|
| 1 | +#include <hxcpp.h> |
| 2 | + |
| 3 | +#define HX_FIELD_REF_IMPL_MEM_OP(op,ret) \ |
| 4 | + ret hx::FieldRef::operator op (const FieldRef& inA) { return this->operator Dynamic() op inA.operator Dynamic(); } \ |
| 5 | + ret hx::FieldRef::operator op (const IndexRef& inA) { return this->operator Dynamic() op inA.operator Dynamic(); } \ |
| 6 | + ret hx::FieldRef::operator op (const hx::Val& inA) { \ |
| 7 | + switch (inA.type) { \ |
| 8 | + case hx::Val::typeObject: return this->operator Dynamic() op Dynamic { inA.asDynamic() }; \ |
| 9 | + case hx::Val::typeString: return this->operator Dynamic() op inA.asString(); \ |
| 10 | + case hx::Val::typeDouble: return this->operator Dynamic() op inA.asDouble(); \ |
| 11 | + case hx::Val::typeInt : return this->operator Dynamic() op inA.asInt(); \ |
| 12 | + case hx::Val::typeInt64 : return this->operator Dynamic() op inA.asInt64(); \ |
| 13 | + case hx::Val::typeBool : return this->operator Dynamic() op inA.asInt(); \ |
| 14 | + } \ |
| 15 | + } |
| 16 | + |
| 17 | +hx::FieldRef::FieldRef(hx::Object* inObj, const String& inName) : mObject(inObj), mName(inName) {} |
| 18 | + |
| 19 | +hx::Val hx::FieldRef::operator=(const hx::Val& inRHS) |
| 20 | +{ |
| 21 | + return mObject->__SetField(mName, inRHS, HX_PROP_DYNAMIC); |
| 22 | +} |
| 23 | + |
| 24 | +hx::FieldRef::operator hx::Val() |
| 25 | +{ |
| 26 | + return mObject ? mObject->__Field(mName, HX_PROP_DYNAMIC) : null(); |
| 27 | +} |
| 28 | + |
| 29 | +hx::FieldRef::operator Dynamic() const |
| 30 | +{ |
| 31 | + return mObject ? Dynamic(mObject->__Field(mName, HX_PROP_DYNAMIC)) : null(); |
| 32 | +} |
| 33 | + |
| 34 | +hx::FieldRef::operator double() const |
| 35 | +{ |
| 36 | + return mObject->__Field(mName, HX_PROP_DYNAMIC); |
| 37 | +} |
| 38 | + |
| 39 | +hx::FieldRef::operator float() const |
| 40 | +{ |
| 41 | + return mObject->__Field(mName, HX_PROP_DYNAMIC); |
| 42 | +} |
| 43 | + |
| 44 | +hx::FieldRef::operator int() const |
| 45 | +{ |
| 46 | + return mObject->__Field(mName, HX_PROP_DYNAMIC); |
| 47 | +} |
| 48 | + |
| 49 | +hx::FieldRef::operator cpp::UInt64() const |
| 50 | +{ |
| 51 | + return mObject->__Field(mName, HX_PROP_DYNAMIC); |
| 52 | +} |
| 53 | + |
| 54 | +hx::FieldRef::operator cpp::Int64() const |
| 55 | +{ |
| 56 | + return mObject->__Field(mName, HX_PROP_DYNAMIC); |
| 57 | +} |
| 58 | + |
| 59 | +double hx::FieldRef::operator++(int) |
| 60 | +{ |
| 61 | + double d = mObject->__Field(mName, HX_PROP_DYNAMIC); |
| 62 | + mObject->__SetField(mName, d + 1, HX_PROP_DYNAMIC); |
| 63 | + return d; |
| 64 | +} |
| 65 | + |
| 66 | +double hx::FieldRef::operator++() |
| 67 | +{ |
| 68 | + double d = ((double)mObject->__Field(mName, HX_PROP_DYNAMIC)) + 1; |
| 69 | + mObject->__SetField(mName, d, HX_PROP_DYNAMIC); |
| 70 | + return d; |
| 71 | +} |
| 72 | + |
| 73 | +double hx::FieldRef::operator--(int) |
| 74 | +{ |
| 75 | + double d = mObject->__Field(mName, HX_PROP_DYNAMIC); |
| 76 | + mObject->__SetField(mName, d - 1, HX_PROP_DYNAMIC); |
| 77 | + return d; |
| 78 | +} |
| 79 | + |
| 80 | +double hx::FieldRef::operator--() |
| 81 | +{ |
| 82 | + double d = (double)(mObject->__Field(mName, HX_PROP_DYNAMIC)) - 1; |
| 83 | + mObject->__SetField(mName, d, HX_PROP_DYNAMIC); |
| 84 | + return d; |
| 85 | +} |
| 86 | + |
| 87 | +bool hx::FieldRef::operator!() |
| 88 | +{ |
| 89 | + return !((int)(mObject->__Field(mName, HX_PROP_DYNAMIC))); |
| 90 | +} |
| 91 | + |
| 92 | +int hx::FieldRef::operator~() |
| 93 | +{ |
| 94 | + return ~((int)mObject->__Field(mName, HX_PROP_DYNAMIC)); |
| 95 | +} |
| 96 | + |
| 97 | +bool hx::FieldRef::operator==(const null&) const |
| 98 | +{ |
| 99 | + return !mObject; |
| 100 | +} |
| 101 | + |
| 102 | +bool hx::FieldRef::operator!=(const null&) const |
| 103 | +{ |
| 104 | + return mObject; |
| 105 | +} |
| 106 | + |
| 107 | +double hx::FieldRef::operator-() |
| 108 | +{ |
| 109 | + return -(double)(mObject->__Field(mName, HX_PROP_DYNAMIC)); |
| 110 | +} |
| 111 | + |
| 112 | +bool hx::FieldRef::HasPointer() const |
| 113 | +{ |
| 114 | + return mObject; |
| 115 | +} |
| 116 | + |
| 117 | +HX_FIELD_REF_IMPL_MEM_OP(== , bool) |
| 118 | +HX_FIELD_REF_IMPL_MEM_OP(!= , bool) |
| 119 | +HX_FIELD_REF_IMPL_MEM_OP(< , bool) |
| 120 | +HX_FIELD_REF_IMPL_MEM_OP(<= , bool) |
| 121 | +HX_FIELD_REF_IMPL_MEM_OP(> , bool) |
| 122 | +HX_FIELD_REF_IMPL_MEM_OP(>= , bool) |
| 123 | + |
| 124 | +HX_FIELD_REF_IMPL_MEM_OP(+, Dynamic) |
| 125 | + |
| 126 | +// Below has the above macros expanded since some operators on some times aren't supported and need manual dynamic wrapping. |
| 127 | +// There may be some sort of tagged dispatch which could be done in the macro instead to avoid this. |
| 128 | + |
| 129 | +double hx::FieldRef::operator * (const FieldRef& inA) { return this->operator Dynamic() * inA.operator Dynamic(); } |
| 130 | +double hx::FieldRef::operator * (const IndexRef& inA) { return this->operator Dynamic() * inA.operator Dynamic(); } |
| 131 | +double hx::FieldRef::operator * (const hx::Val& inA) |
| 132 | +{ |
| 133 | + switch (inA.type) |
| 134 | + { |
| 135 | + case hx::Val::typeObject: return this->operator double() * inA.asDouble(); |
| 136 | + case hx::Val::typeString: return this->operator double() * inA.asDouble(); |
| 137 | + case hx::Val::typeDouble: return this->operator double() * inA.asDouble(); |
| 138 | + case hx::Val::typeInt: return this->operator double() * inA.asInt(); |
| 139 | + case hx::Val::typeInt64: return this->operator double() * inA.asInt64(); |
| 140 | + case hx::Val::typeBool: return this->operator double() * inA.asInt(); |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +double hx::FieldRef::operator / (const FieldRef& inA) { return this->operator Dynamic() / inA.operator Dynamic(); } |
| 145 | +double hx::FieldRef::operator / (const IndexRef& inA) { return this->operator Dynamic() / inA.operator Dynamic(); } |
| 146 | +double hx::FieldRef::operator / (const hx::Val& inA) |
| 147 | +{ |
| 148 | + switch (inA.type) { |
| 149 | + case hx::Val::typeObject: return this->operator double() / inA.asDouble(); |
| 150 | + case hx::Val::typeString: return this->operator double() / inA.asDouble(); |
| 151 | + case hx::Val::typeDouble: return this->operator double() / inA.asDouble(); |
| 152 | + case hx::Val::typeInt: return this->operator double() / inA.asInt(); |
| 153 | + case hx::Val::typeInt64: return this->operator double() / inA.asInt64(); |
| 154 | + case hx::Val::typeBool: return this->operator double() / inA.asInt(); |
| 155 | + } |
| 156 | +} |
| 157 | + |
| 158 | +double hx::FieldRef::operator - (const FieldRef& inA) { return this->operator Dynamic() - inA.operator Dynamic(); } |
| 159 | +double hx::FieldRef::operator - (const IndexRef& inA) { return this->operator Dynamic() - inA.operator Dynamic(); } |
| 160 | +double hx::FieldRef::operator - (const hx::Val& inA) |
| 161 | +{ |
| 162 | + switch (inA.type) { |
| 163 | + case hx::Val::typeObject: return this->operator double() - inA.asDouble(); |
| 164 | + case hx::Val::typeString: return this->operator double() - inA.asDouble(); |
| 165 | + case hx::Val::typeDouble: return this->operator double() - inA.asDouble(); |
| 166 | + case hx::Val::typeInt: return this->operator double() - inA.asInt(); |
| 167 | + case hx::Val::typeInt64: return this->operator double() - inA.asInt64(); |
| 168 | + case hx::Val::typeBool: return this->operator double() - inA.asInt(); |
| 169 | + } |
| 170 | +} |
| 171 | + |
| 172 | +double hx::FieldRef::operator % (const FieldRef& inA) { return this->operator Dynamic() % inA.operator Dynamic(); } |
| 173 | +double hx::FieldRef::operator % (const IndexRef& inA) { return this->operator Dynamic() % inA.operator Dynamic(); } |
| 174 | +double hx::FieldRef::operator % (const hx::Val& inA) |
| 175 | +{ |
| 176 | + switch (inA.type) { |
| 177 | + case hx::Val::typeObject: return this->operator int() % inA.asInt(); |
| 178 | + case hx::Val::typeString: return this->operator int() % inA.asInt(); |
| 179 | + case hx::Val::typeDouble: return this->operator int() % inA.asInt(); |
| 180 | + case hx::Val::typeInt: return this->operator int() % inA.asInt(); |
| 181 | + case hx::Val::typeInt64: return this->operator int() % inA.asInt64(); |
| 182 | + case hx::Val::typeBool: return this->operator int() % inA.asInt(); |
| 183 | + } |
| 184 | +} |
0 commit comments