Skip to content

Commit d7963fa

Browse files
author
Aidan Lee
committed
Commit missing files
1 parent e2c779c commit d7963fa

2 files changed

Lines changed: 348 additions & 0 deletions

File tree

src/hx/FieldRef.cpp

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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+
}

src/hx/IndexRef.cpp

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#include <hxcpp.h>
2+
3+
#define HX_INDEX_REF_IMPL_MEM_OP(op,ret) \
4+
ret hx::IndexRef::operator op (const FieldRef& inA) { return this->operator Dynamic() op inA.operator Dynamic(); } \
5+
ret hx::IndexRef::operator op (const IndexRef& inA) { return this->operator Dynamic() op inA.operator Dynamic(); } \
6+
ret hx::IndexRef::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::IndexRef::IndexRef(hx::Object* inObj, int inIndex) : mObject(inObj), mIndex(inIndex) {}
18+
19+
Dynamic hx::IndexRef::operator=(const Dynamic& inRHS)
20+
{
21+
return mObject->__SetItem(mIndex, inRHS);
22+
}
23+
24+
hx::IndexRef::operator Dynamic() const
25+
{
26+
return mObject->__GetItem(mIndex);
27+
}
28+
29+
hx::IndexRef::operator double() const
30+
{
31+
return mObject->__GetItem(mIndex);
32+
}
33+
34+
hx::IndexRef::operator int() const
35+
{
36+
return mObject->__GetItem(mIndex);
37+
}
38+
39+
double hx::IndexRef::operator ++(int)
40+
{
41+
double d = mObject->__GetItem(mIndex)->__ToDouble();
42+
mObject->__SetItem(mIndex, d + 1);
43+
return d;
44+
}
45+
46+
double hx::IndexRef::operator ++()
47+
{
48+
double d = mObject->__GetItem(mIndex)->__ToDouble() + 1;
49+
mObject->__SetItem(mIndex, d);
50+
return d;
51+
}
52+
53+
double hx::IndexRef::operator --(int)
54+
{
55+
double d = mObject->__GetItem(mIndex)->__ToDouble();
56+
mObject->__SetItem(mIndex, d - 1);
57+
return d;
58+
}
59+
60+
double hx::IndexRef::operator --()
61+
{
62+
double d = mObject->__GetItem(mIndex)->__ToDouble() - 1;
63+
mObject->__SetItem(mIndex, d);
64+
return d;
65+
}
66+
67+
bool hx::IndexRef::operator !()
68+
{
69+
return !mObject->__GetItem(mIndex)->__ToInt();
70+
}
71+
72+
int hx::IndexRef::operator ~()
73+
{
74+
return ~mObject->__GetItem(mIndex)->__ToInt();
75+
}
76+
77+
double hx::IndexRef::operator -()
78+
{
79+
return -mObject->__GetItem(mIndex)->__ToDouble();
80+
}
81+
82+
bool hx::IndexRef::operator ==(const null&) const
83+
{
84+
return !mObject;
85+
}
86+
87+
bool hx::IndexRef::operator !=(const null&) const
88+
{
89+
return mObject;
90+
}
91+
92+
bool hx::IndexRef::HasPointer() const
93+
{
94+
return mObject;
95+
}
96+
97+
HX_INDEX_REF_IMPL_MEM_OP(== , bool)
98+
HX_INDEX_REF_IMPL_MEM_OP(!= , bool)
99+
HX_INDEX_REF_IMPL_MEM_OP(< , bool)
100+
HX_INDEX_REF_IMPL_MEM_OP(<= , bool)
101+
HX_INDEX_REF_IMPL_MEM_OP(> , bool)
102+
HX_INDEX_REF_IMPL_MEM_OP(>= , bool)
103+
104+
HX_INDEX_REF_IMPL_MEM_OP(+, Dynamic)
105+
106+
// Below has the above macros expanded since some operators on some times aren't supported and need manual dynamic wrapping.
107+
// There may be some sort of tagged dispatch which could be done in the macro instead to avoid this.
108+
109+
double hx::IndexRef::operator * (const FieldRef& inA) { return this->operator Dynamic() * inA.operator Dynamic(); }
110+
double hx::IndexRef::operator * (const IndexRef& inA) { return this->operator Dynamic() * inA.operator Dynamic(); }
111+
double hx::IndexRef::operator * (const hx::Val& inA)
112+
{
113+
switch (inA.type)
114+
{
115+
case hx::Val::typeObject: return this->operator double() * inA.asDouble();
116+
case hx::Val::typeString: return this->operator double() * inA.asDouble();
117+
case hx::Val::typeDouble: return this->operator double() * inA.asDouble();
118+
case hx::Val::typeInt: return this->operator double() * inA.asInt();
119+
case hx::Val::typeInt64: return this->operator double() * inA.asInt64();
120+
case hx::Val::typeBool: return this->operator double() * inA.asInt();
121+
}
122+
}
123+
124+
double hx::IndexRef::operator / (const FieldRef& inA) { return this->operator Dynamic() / inA.operator Dynamic(); }
125+
double hx::IndexRef::operator / (const IndexRef& inA) { return this->operator Dynamic() / inA.operator Dynamic(); }
126+
double hx::IndexRef::operator / (const hx::Val& inA)
127+
{
128+
switch (inA.type) {
129+
case hx::Val::typeObject: return this->operator double() / inA.asDouble();
130+
case hx::Val::typeString: return this->operator double() / inA.asDouble();
131+
case hx::Val::typeDouble: return this->operator double() / inA.asDouble();
132+
case hx::Val::typeInt: return this->operator double() / inA.asInt();
133+
case hx::Val::typeInt64: return this->operator double() / inA.asInt64();
134+
case hx::Val::typeBool: return this->operator double() / inA.asInt();
135+
}
136+
}
137+
138+
double hx::IndexRef::operator - (const FieldRef& inA) { return this->operator Dynamic() - inA.operator Dynamic(); }
139+
double hx::IndexRef::operator - (const IndexRef& inA) { return this->operator Dynamic() - inA.operator Dynamic(); }
140+
double hx::IndexRef::operator - (const hx::Val& inA)
141+
{
142+
switch (inA.type) {
143+
case hx::Val::typeObject: return this->operator double() - inA.asDouble();
144+
case hx::Val::typeString: return this->operator double() - inA.asDouble();
145+
case hx::Val::typeDouble: return this->operator double() - inA.asDouble();
146+
case hx::Val::typeInt: return this->operator double() - inA.asInt();
147+
case hx::Val::typeInt64: return this->operator double() - inA.asInt64();
148+
case hx::Val::typeBool: return this->operator double() - inA.asInt();
149+
}
150+
}
151+
152+
double hx::IndexRef::operator % (const FieldRef& inA) { return this->operator Dynamic() % inA.operator Dynamic(); }
153+
double hx::IndexRef::operator % (const IndexRef& inA) { return this->operator Dynamic() % inA.operator Dynamic(); }
154+
double hx::IndexRef::operator % (const hx::Val& inA)
155+
{
156+
switch (inA.type) {
157+
case hx::Val::typeObject: return this->operator int() % inA.asInt();
158+
case hx::Val::typeString: return this->operator int() % inA.asInt();
159+
case hx::Val::typeDouble: return this->operator int() % inA.asInt();
160+
case hx::Val::typeInt: return this->operator int() % inA.asInt();
161+
case hx::Val::typeInt64: return this->operator int() % inA.asInt64();
162+
case hx::Val::typeBool: return this->operator int() % inA.asInt();
163+
}
164+
}

0 commit comments

Comments
 (0)