|
| 1 | +#define NULL 0 |
| 2 | +static const void * ptr1 = NULL; // this/lhs address |
| 3 | +static const void * ptr2 = NULL; // rhs address |
| 4 | +static char msg1[100]; // check message |
| 5 | +static int val1 = 0; // current/lhs value |
| 6 | +static int val2 = 0; // rhs value |
| 7 | +static int val3 = 0; // result value |
| 8 | +static int initial = 1; // 1 = enable ctor/copy-ctor/dtor/let |
| 9 | + |
| 10 | +void setMsg( const char* msg ) { |
| 11 | + char *s = msg1; |
| 12 | + while( *msg ) |
| 13 | + *s++ = *msg++; |
| 14 | + *s = *msg; |
| 15 | +} |
| 16 | + |
| 17 | +void setInitial( int flag ) { |
| 18 | + initial = flag; |
| 19 | +} |
| 20 | + |
| 21 | +void resetChecks() { |
| 22 | + ptr1 = NULL; |
| 23 | + ptr2 = NULL; |
| 24 | + setMsg( "" ); |
| 25 | + val1 = 0; |
| 26 | + val2 = 0; |
| 27 | + val3 = 0; |
| 28 | +} |
| 29 | + |
| 30 | +const void* getPtr1() { |
| 31 | + return ptr1; |
| 32 | +} |
| 33 | + |
| 34 | +const void* getPtr2() { |
| 35 | + return ptr2; |
| 36 | +} |
| 37 | + |
| 38 | +char* getMsg1() { |
| 39 | + return msg1; |
| 40 | +} |
| 41 | + |
| 42 | +int getVal1() { |
| 43 | + return val1; |
| 44 | +} |
| 45 | + |
| 46 | +int getVal2() { |
| 47 | + return val2; |
| 48 | +} |
| 49 | + |
| 50 | +int getVal3() { |
| 51 | + return val3; |
| 52 | +} |
| 53 | + |
| 54 | +class UDT |
| 55 | +{ |
| 56 | + public: |
| 57 | + |
| 58 | + int value; |
| 59 | + void* self; |
| 60 | + |
| 61 | + UDT(); |
| 62 | + UDT( UDT const& rhs ); |
| 63 | + UDT( int const& rhs ); |
| 64 | + ~UDT(); |
| 65 | + |
| 66 | + // assignment |
| 67 | + UDT& operator=( UDT const& rhs ); |
| 68 | + |
| 69 | + // !!! TODO !!! non-static member bops |
| 70 | + UDT& operator+( int const& rhs ); |
| 71 | + UDT& operator-( int const& rhs ); |
| 72 | +}; |
| 73 | + |
| 74 | +UDT operator+( UDT const& lhs, UDT const& rhs ); |
| 75 | +UDT operator-( UDT const& lhs, UDT const& rhs ); |
| 76 | + |
| 77 | +UDT operator+( int const& lhs, UDT const& rhs ); |
| 78 | +UDT operator-( int const& lhs, UDT const& rhs ); |
| 79 | + |
| 80 | +// constructor UDT() |
| 81 | +UDT::UDT() |
| 82 | +{ |
| 83 | + self = this; |
| 84 | + if( initial ) { |
| 85 | + ptr1 = this; |
| 86 | + ptr2 = NULL; |
| 87 | + setMsg( "UDT::UDT()" ); |
| 88 | + val1 = -1; |
| 89 | + val2 = -1; |
| 90 | + val3 = 0; |
| 91 | + } |
| 92 | + value = 0; |
| 93 | +} |
| 94 | + |
| 95 | +// constructor UDT( byref rhs as const UDT ) |
| 96 | +UDT::UDT( UDT const& rhs ) |
| 97 | +{ |
| 98 | + self = this; |
| 99 | + if( initial ) { |
| 100 | + ptr1 = this; |
| 101 | + ptr2 = &rhs; |
| 102 | + setMsg( "UDT::UDT( UDT const& rhs )" ); |
| 103 | + val1 = -1; |
| 104 | + val2 = rhs.value; |
| 105 | + val3 = rhs.value; |
| 106 | + } |
| 107 | + value = rhs.value; |
| 108 | +} |
| 109 | + |
| 110 | +// constructor UDT( byref rhs as const long ) |
| 111 | +UDT::UDT( int const& rhs ) |
| 112 | +{ |
| 113 | + self = this; |
| 114 | + if( initial ) { |
| 115 | + ptr1 = this; |
| 116 | + ptr2 = &rhs; |
| 117 | + setMsg( "UDT::UDT( int const& rhs )" ); |
| 118 | + val1 = -1; |
| 119 | + val2 = rhs; |
| 120 | + val3 = rhs; |
| 121 | + } |
| 122 | + value = rhs; |
| 123 | +} |
| 124 | + |
| 125 | +// destructor UDT() |
| 126 | +UDT::~UDT() |
| 127 | +{ |
| 128 | + if( initial ) { |
| 129 | + ptr1 = this; |
| 130 | + ptr2 = NULL; |
| 131 | + setMsg( "UDT::~UDT()" ); |
| 132 | + val1 = value; |
| 133 | + val2 = -1; |
| 134 | + val3 = -1; |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +// operator UDT.let( byref rhs as const UDT ) |
| 139 | +UDT& UDT::operator=( UDT const& rhs ) |
| 140 | +{ |
| 141 | + if( initial ) { |
| 142 | + ptr1 = this; |
| 143 | + ptr2 = &rhs; |
| 144 | + setMsg( "UDT& UDT::operator=( UDT const& rhs )" ); |
| 145 | + val1 = value; |
| 146 | + val2 = rhs.value; |
| 147 | + val3 = rhs.value; |
| 148 | + } |
| 149 | + value = rhs.value; |
| 150 | + return *this; |
| 151 | +} |
| 152 | + |
| 153 | +// !!! TODO !!!: operator UDT.+( byref rhs as const long ) |
| 154 | +UDT& UDT::operator+( int const& rhs ) |
| 155 | +{ |
| 156 | + ptr1 = this; |
| 157 | + ptr2 = &rhs; |
| 158 | + setMsg( "UDT& UDT::operator+( int const& rhs )" ); |
| 159 | + val1 = value; |
| 160 | + val2 = rhs; |
| 161 | + val3 = value + rhs; |
| 162 | + |
| 163 | + value += rhs; |
| 164 | + return *this; |
| 165 | +} |
| 166 | + |
| 167 | +// !!! TODO !!!: operator UDT.+( byref rhs as const long ) |
| 168 | +UDT& UDT::operator-( int const& rhs ) |
| 169 | +{ |
| 170 | + ptr1 = this; |
| 171 | + ptr2 = &rhs; |
| 172 | + setMsg( "UDT& UDT::operator-( int const& rhs )" ); |
| 173 | + val1 = value; |
| 174 | + val2 = rhs; |
| 175 | + val3 = value - rhs; |
| 176 | + |
| 177 | + value -= rhs; |
| 178 | + return *this; |
| 179 | +} |
| 180 | + |
| 181 | +// operator +( byref lhs as const UDT, byref rhs as const UDT ) as UDT |
| 182 | +UDT operator+( UDT const& lhs, UDT const& rhs ) |
| 183 | +{ |
| 184 | + ptr1 = &lhs; |
| 185 | + ptr2 = &rhs; |
| 186 | + setMsg( "UDT operator+( UDT const& lhs, UDT const& rhs )" ); |
| 187 | + val1 = lhs.value; |
| 188 | + val2 = rhs.value; |
| 189 | + val3 = lhs.value + rhs.value; |
| 190 | + |
| 191 | + return UDT(lhs.value + rhs.value); |
| 192 | +} |
| 193 | + |
| 194 | +// operator -( byref lhs as const UDT, byref rhs as const UDT ) as UDT |
| 195 | +UDT operator-( UDT const& lhs, UDT const& rhs ) |
| 196 | +{ |
| 197 | + ptr1 = &lhs; |
| 198 | + ptr2 = &rhs; |
| 199 | + setMsg( "UDT operator-( UDT const& lhs, UDT const& rhs )" ); |
| 200 | + val1 = lhs.value; |
| 201 | + val2 = rhs.value; |
| 202 | + val3 = lhs.value - rhs.value; |
| 203 | + |
| 204 | + return UDT(lhs.value - rhs.value); |
| 205 | +} |
| 206 | + |
| 207 | +// operator +( byref lhs as const long, byref rhs as const UDT ) as UDT |
| 208 | +UDT operator+( int const& lhs, UDT const& rhs ) |
| 209 | +{ |
| 210 | + ptr1 = &lhs; |
| 211 | + ptr2 = &rhs; |
| 212 | + setMsg( "UDT operator+( int const& lhs, UDT const& rhs )" ); |
| 213 | + val1 = lhs; |
| 214 | + val2 = rhs.value; |
| 215 | + val3 = lhs + rhs.value; |
| 216 | + |
| 217 | + return UDT(lhs + rhs.value); |
| 218 | +} |
| 219 | + |
| 220 | +// operator -( byref lhs as const long, byref rhs as const UDT ) as UDT |
| 221 | +UDT operator-( int const& lhs, UDT const& rhs ) |
| 222 | +{ |
| 223 | + ptr1 = &lhs; |
| 224 | + ptr2 = &rhs; |
| 225 | + setMsg( "UDT operator-( int const& lhs, UDT const& rhs )" ); |
| 226 | + val1 = lhs; |
| 227 | + val2 = rhs.value; |
| 228 | + val3 = lhs - rhs.value; |
| 229 | + |
| 230 | + return UDT(lhs - rhs.value); |
| 231 | +} |
| 232 | + |
0 commit comments