forked from CloverHackyColor/CloverBootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
187 lines (157 loc) · 4.24 KB
/
Copy pathmain.cpp
File metadata and controls
187 lines (157 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// main.cpp
// cpp_tests
//
// Created by jief on 23.02.20.
// Copyright © 2020 Jief_Machak. All rights reserved.
//
#include <iostream>
#include <locale.h>
#include "../../../PosixCompilation/xcode_utf_fixed.h"
#include "../../../rEFIt_UEFI/cpp_unit_test/all_tests.h"
//#include "../../../rEFIt_UEFI/cpp_foundation/XToolsCommon.h"
#include "../../../rEFIt_UEFI/libeg/XImage.h"
//#include "../../../rEFIt_UEFI/Platform/platformdata.h"
//class Boolean
//{
// bool flag;
//public:
// explicit Boolean() : flag(false) {}
// explicit Boolean(const bool other) { flag = other; }
// explicit Boolean(const Boolean& other) { flag = other.flag; }
//// template <typename T>
//// Boolean(T other) = delete;// { return *this; }
//
// Boolean& operator= (const Boolean& other) { return *this; }
// Boolean& operator= (const bool other) { return *this; }
// template <typename T>
// Boolean& operator= (const T other) = delete;// { return *this; }
//
// bool getValue() const {return flag;}
// void setValue(bool a) {flag = a;}
//};
// The following is by no means a FULL solution!
#include <functional>
#include <iostream>
#include <cassert>
template<typename T>
class Property {
public:
Property(){}
operator const T& () const {
// Call override getter if we have it
if (getter) return getter();
return get();
}
const T& operator = (const T& other) {
// Call override setter if we have it
if (setter) return setter(other);
return set(other);
}
bool operator == (const T& other) const {
// Static cast makes sure our getter operator is called, so we could use overrides if those are in place
return static_cast<const T&>(*this) == other;
}
// Use this to always get without overrides, useful for use with overriding implementations
const T& get() const {
return t;
}
// Use this to always set without overrides, useful for use with overriding implementations
const T& set(const T& other) {
return t = other;
}
// Assign getter and setter to these properties
std::function<const T&()> getter;
std::function<const T&(const T&)> setter;
private:
T t;
};
// Basic usage, no override
struct Test {
Property<int> prop;
};
// Override getter and setter
struct TestWithOverride {
TestWithOverride(){
prop.setter = [&](const int& other){
std::cout << "Custom setter called" << std::endl;
return prop.set(other);
};
prop.setter = std::bind(&TestWithOverride::setProp,this,std::placeholders::_1);
prop.getter = std::bind(&TestWithOverride::getProp,this);
}
Property<int> prop;
private:
const int& getProp() const {
std::cout << "Custom getter called" << std::endl;
return prop.get();
}
const int& setProp(const int& other){
std::cout << "Custom setter called" << std::endl;
return prop.set(other);
}
};
class MyFloat {
public:
float f;
MyFloat() { f = 0.0f; }
MyFloat(float _f) : f(_f) {}
float get() { return 1; }
};
template<typename T>
class MutableRef : public T {
public:
const T* t;
const T& operator = (const T* other) {
t = other;
return *t;
}
operator T& () {
return *t;
}
};
extern "C" int main(int argc, const char * argv[])
{
(void)argc;
(void)argv;
setlocale(LC_ALL, "en_US"); // to allow printf unicode char
XString8 s("foo");
// s.strcat("a");
char* p = s.forgetDataWithoutFreeing();
free(p);
XString8 s2;
// s2.S8Printf("bar");
char* q = s2.forgetDataWithoutFreeing();
free(q);
MyFloat test = 5.0f;
MutableRef<MyFloat> Background;
Background = &test;
test = 6;
float test2 = Background.get(); (void)test2;
Test t;
TestWithOverride t1;
t.prop = 1;
assert(t.prop == 1);
t1.prop = 1;
assert(t1.prop == 1);
/*
Expected output:
1. No aborts on assertions
2. Text:
Custom setter called
Custom getter called
*/
// xcode_utf_fixed_tests();
const int i = 2;
(void)i;
XBool b;
b = true;
b = false;
// b = XBool(i);
// b = (char*)NULL;
// b = (float)1.0;
// b = i;
//printf("%d", numeric_limits<int>::min());
//printf("%d", numeric_limits<int>::min());
return all_tests() ? 0 : -1 ;
}