Skip to content

Commit e2c779c

Browse files
author
Aidan Lee
committed
try non templated field ref
1 parent ddf922f commit e2c779c

3 files changed

Lines changed: 96 additions & 173 deletions

File tree

include/hx/FieldRef.h

Lines changed: 90 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -21,92 +21,57 @@ namespace hx
2121

2222

2323
#define HX_FIELD_REF_MEM_OP(op,ret) \
24-
inline ret operator op (const FieldRef &inA) \
25-
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
26-
inline ret operator op (const IndexRef &inA); \
27-
template<typename T> inline ret operator op (const T& inA) \
28-
{ return this->operator Dynamic() op inA; }
29-
30-
#define HX_FIELD_REF_IMPL_MEM_OP(op,ret) \
31-
inline ret hx::FieldRef::operator op (const IndexRef &inA) \
32-
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
24+
ret operator op (const FieldRef& inA); \
25+
ret operator op (const IndexRef& inA); \
26+
ret operator op (const hx::Val& inA);
3327

3428
class FieldRef
3529
{
3630
public:
37-
explicit FieldRef(hx::Object *inObj,const String &inName) : mObject(inObj), mName(inName)
38-
{
39-
}
40-
41-
hx::Val operator=(const hx::Val &inRHS)
42-
{
43-
return mObject->__SetField(mName,inRHS, HX_PROP_DYNAMIC );
44-
}
45-
inline operator hx::Val() const { return mObject ? mObject->__Field(mName, HX_PROP_DYNAMIC) : null(); }
46-
inline operator Dynamic() const { return mObject ? Dynamic(mObject->__Field(mName, HX_PROP_DYNAMIC)) : null(); }
47-
inline operator double() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
48-
inline operator float() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
49-
inline operator int() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
50-
inline operator cpp::UInt64() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
51-
inline operator cpp::Int64() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
52-
53-
54-
// post-increment
55-
inline double operator++(int)
56-
{
57-
double d = mObject->__Field(mName, HX_PROP_DYNAMIC);
58-
mObject->__SetField(mName,d+1, HX_PROP_DYNAMIC);
59-
return d;
60-
}
61-
// pre-increment
62-
inline double operator++()
63-
{
64-
double d = ((double)mObject->__Field(mName, HX_PROP_DYNAMIC)) + 1;
65-
mObject->__SetField(mName,d, HX_PROP_DYNAMIC);
66-
return d;
67-
}
68-
// post-decrement
69-
inline double operator--(int)
70-
{
71-
double d = mObject->__Field(mName, HX_PROP_DYNAMIC);
72-
mObject->__SetField(mName,d-1, HX_PROP_DYNAMIC);
73-
return d;
74-
}
75-
// pre-decrement
76-
inline double operator--()
77-
{
78-
double d = (double)(mObject->__Field(mName, HX_PROP_DYNAMIC)) - 1;
79-
mObject->__SetField(mName,d, HX_PROP_DYNAMIC);
80-
return d;
81-
}
82-
bool operator !() { return ! ((int)(mObject->__Field(mName, HX_PROP_DYNAMIC))); }
83-
int operator ~() { return ~ ((int)mObject->__Field(mName, HX_PROP_DYNAMIC)); }
84-
85-
inline bool operator==(const null &) const { return !mObject; }
86-
inline bool operator!=(const null &) const { return mObject; }
87-
88-
double operator -() { return - (double)(mObject->__Field(mName, HX_PROP_DYNAMIC)); }
89-
90-
bool HasPointer() const { return mObject; }
91-
92-
93-
HX_FIELD_REF_MEM_OP(==,bool)
94-
HX_FIELD_REF_MEM_OP(!=,bool)
95-
HX_FIELD_REF_MEM_OP(<,bool)
96-
HX_FIELD_REF_MEM_OP(<=,bool)
97-
HX_FIELD_REF_MEM_OP(>,bool)
98-
HX_FIELD_REF_MEM_OP(>=,bool)
99-
100-
HX_FIELD_REF_MEM_OP(+,Dynamic)
101-
HX_FIELD_REF_MEM_OP(*,double)
102-
HX_FIELD_REF_MEM_OP(/,double)
103-
HX_FIELD_REF_MEM_OP(-,double)
104-
HX_FIELD_REF_MEM_OP(%,double)
105-
106-
107-
108-
String mName;
109-
hx::Object *mObject;
31+
explicit FieldRef(hx::Object* inObj, const String& inName);
32+
33+
hx::Val operator=(const hx::Val& inRHS);
34+
operator hx::Val();
35+
operator Dynamic() const;
36+
operator double() const;
37+
operator float() const;
38+
operator int() const;
39+
operator cpp::UInt64() const;
40+
operator cpp::Int64() const;
41+
42+
// post-increment
43+
double operator++(int);
44+
// pre-increment
45+
double operator++();
46+
// post-decrement
47+
double operator--(int);
48+
// pre-decrement
49+
double operator--();
50+
bool operator !();
51+
int operator ~();
52+
53+
bool operator==(const null&) const;
54+
bool operator!=(const null&) const;
55+
56+
double operator -();
57+
58+
bool HasPointer() const;
59+
60+
HX_FIELD_REF_MEM_OP(==,bool)
61+
HX_FIELD_REF_MEM_OP(!=,bool)
62+
HX_FIELD_REF_MEM_OP(<,bool)
63+
HX_FIELD_REF_MEM_OP(<=,bool)
64+
HX_FIELD_REF_MEM_OP(>,bool)
65+
HX_FIELD_REF_MEM_OP(>=,bool)
66+
67+
HX_FIELD_REF_MEM_OP(+,Dynamic)
68+
HX_FIELD_REF_MEM_OP(*,double)
69+
HX_FIELD_REF_MEM_OP(/,double)
70+
HX_FIELD_REF_MEM_OP(-,double)
71+
HX_FIELD_REF_MEM_OP(%,double)
72+
73+
String mName;
74+
hx::Object *mObject;
11075
};
11176

11277
// We can define this one now...
@@ -141,81 +106,53 @@ HX_FIELD_REF_OP(%,double)
141106
//
142107

143108
#define HX_INDEX_REF_MEM_OP(op,ret) \
144-
inline ret operator op (const IndexRef &inA) \
145-
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
146-
inline ret operator op (const FieldRef &inA) \
147-
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
148-
template<typename T> inline ret operator op (const T& inA) \
149-
{ return this->operator Dynamic() op inA; }
150-
109+
ret operator op (const IndexRef &inA); \
110+
ret operator op (const FieldRef &inA); \
111+
ret operator op (const hx::Val& inA);
151112

152113
class IndexRef
153114
{
154115
public:
155-
explicit IndexRef(hx::Object *inObj,int inIndex) : mObject(inObj), mIndex(inIndex)
156-
{
157-
}
158-
159-
Dynamic operator=(const Dynamic &inRHS)
160-
{
161-
return mObject->__SetItem(mIndex,inRHS);
162-
}
163-
inline operator Dynamic() const { return mObject->__GetItem(mIndex); }
164-
inline operator double() const { return mObject->__GetItem(mIndex); }
165-
inline operator int() const { return mObject->__GetItem(mIndex); }
166-
167-
// post-increment
168-
inline double operator++(int)
169-
{
170-
double d = mObject->__GetItem(mIndex)->__ToDouble();
171-
mObject->__SetItem(mIndex,d+1);
172-
return d;
173-
}
174-
// pre-increment
175-
inline double operator++()
176-
{
177-
double d = mObject->__GetItem(mIndex)->__ToDouble() + 1;
178-
mObject->__SetItem(mIndex,d);
179-
return d;
180-
}
181-
// post-decrement
182-
inline double operator--(int)
183-
{
184-
double d = mObject->__GetItem(mIndex)->__ToDouble();
185-
mObject->__SetItem(mIndex,d-1);
186-
return d;
187-
}
188-
// pre-decrement
189-
inline double operator--()
190-
{
191-
double d = mObject->__GetItem(mIndex)->__ToDouble() - 1;
192-
mObject->__SetItem(mIndex,d);
193-
return d;
194-
}
195-
bool operator !() { return ! mObject->__GetItem(mIndex)->__ToInt(); }
196-
int operator ~() { return ~ mObject->__GetItem(mIndex)->__ToInt(); }
197-
double operator -() { return - mObject->__GetItem(mIndex)->__ToDouble(); }
198-
199-
inline bool operator==(const null &) const { return !mObject; }
200-
inline bool operator!=(const null &) const { return mObject; }
201-
202-
HX_INDEX_REF_MEM_OP(==,bool)
203-
HX_INDEX_REF_MEM_OP(!=,bool)
204-
HX_INDEX_REF_MEM_OP(<,bool)
205-
HX_INDEX_REF_MEM_OP(<=,bool)
206-
HX_INDEX_REF_MEM_OP(>,bool)
207-
HX_INDEX_REF_MEM_OP(>=,bool)
208-
209-
HX_INDEX_REF_MEM_OP(+,Dynamic)
210-
HX_INDEX_REF_MEM_OP(*,double)
211-
HX_INDEX_REF_MEM_OP(/,double)
212-
HX_INDEX_REF_MEM_OP(-,double)
213-
HX_INDEX_REF_MEM_OP(%,double)
214-
215-
bool HasPointer() const { return mObject; }
216-
217-
int mIndex;
218-
hx::Object *mObject;
116+
explicit IndexRef(hx::Object* inObj, int inIndex);
117+
118+
Dynamic operator=(const Dynamic& inRHS);
119+
operator Dynamic() const;
120+
operator double() const;
121+
operator int() const;
122+
123+
// post-increment
124+
double operator++(int);
125+
// pre-increment
126+
double operator++();
127+
// post-decrement
128+
double operator--(int);
129+
// pre-decrement
130+
double operator--();
131+
132+
bool operator !();
133+
int operator ~();
134+
double operator -();
135+
136+
bool operator==(const null&) const;
137+
bool operator!=(const null&) const;
138+
139+
HX_INDEX_REF_MEM_OP(== , bool)
140+
HX_INDEX_REF_MEM_OP(!= , bool)
141+
HX_INDEX_REF_MEM_OP(< , bool)
142+
HX_INDEX_REF_MEM_OP(<= , bool)
143+
HX_INDEX_REF_MEM_OP(> , bool)
144+
HX_INDEX_REF_MEM_OP(>= , bool)
145+
146+
HX_INDEX_REF_MEM_OP(+, Dynamic)
147+
HX_INDEX_REF_MEM_OP(*, double)
148+
HX_INDEX_REF_MEM_OP(/ , double)
149+
HX_INDEX_REF_MEM_OP(-, double)
150+
HX_INDEX_REF_MEM_OP(%, double)
151+
152+
bool HasPointer() const;
153+
154+
int mIndex;
155+
hx::Object *mObject;
219156
};
220157

221158
// We can define this one now...
@@ -243,20 +180,6 @@ HX_INDEX_REF_OP(-,double)
243180
HX_INDEX_REF_OP(%,double)
244181

245182

246-
// Implement once IndexRef has been defined.
247-
HX_FIELD_REF_IMPL_MEM_OP(==,bool)
248-
HX_FIELD_REF_IMPL_MEM_OP(!=,bool)
249-
HX_FIELD_REF_IMPL_MEM_OP(<,bool)
250-
HX_FIELD_REF_IMPL_MEM_OP(<=,bool)
251-
HX_FIELD_REF_IMPL_MEM_OP(>,bool)
252-
HX_FIELD_REF_IMPL_MEM_OP(>=,bool)
253-
254-
HX_FIELD_REF_IMPL_MEM_OP(+,Dynamic)
255-
HX_FIELD_REF_IMPL_MEM_OP(*,double)
256-
HX_FIELD_REF_IMPL_MEM_OP(/,double)
257-
HX_FIELD_REF_IMPL_MEM_OP(-,double)
258-
HX_FIELD_REF_IMPL_MEM_OP(%,double)
259-
260183
// Disambiguate Dynamic operators...
261184

262185
#define HX_INDEX_REF_OP_DYNAMIC(op,ret) \

include/hx/Operators.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,14 @@ inline L& UShrEq(L &inLHS, R inRHS) { inLHS = hx::UShr(inLHS,inRHS); return inLH
134134
template<typename L, typename R>
135135
inline L& ModEq(L &inLHS, R inRHS) { inLHS = DoubleMod(inLHS,inRHS); return inLHS; }
136136

137-
#if defined(__GNUC__) || defined(__SNC__)
138137
template<typename R>
139-
inline hx::FieldRef AddEq(hx::FieldRef inLHS, R inRHS) { inLHS = inLHS + inRHS; return inLHS; }
138+
inline hx::FieldRef AddEq(hx::FieldRef inLHS, R inRHS) { inLHS = inLHS + hx::Val{ inRHS }; return inLHS; }
140139
template<typename R>
141-
inline hx::FieldRef MultEq(hx::FieldRef inLHS, R inRHS) { inLHS = inLHS * inRHS; return inLHS; }
140+
inline hx::FieldRef MultEq(hx::FieldRef inLHS, R inRHS) { inLHS = inLHS * hx::Val{ inRHS }; return inLHS; }
142141
template<typename R>
143142
inline hx::FieldRef DivEq(hx::FieldRef inLHS, R inRHS) { inLHS = (double)inLHS / (double)inRHS; return inLHS; }
144143
template<typename R>
145-
inline hx::FieldRef SubEq(hx::FieldRef inLHS, R inRHS) { inLHS = inLHS - inRHS; return inLHS; }
144+
inline hx::FieldRef SubEq(hx::FieldRef inLHS, R inRHS) { inLHS = inLHS - hx::Val{ inRHS }; return inLHS; }
146145
template<typename R>
147146
inline hx::FieldRef AndEq(hx::FieldRef inLHS, R inRHS) { inLHS = (int)inLHS & (int)inRHS; return inLHS; }
148147
template<typename R>
@@ -160,7 +159,7 @@ inline hx::FieldRef ModEq(hx::FieldRef inLHS, R inRHS) { inLHS = DoubleMod(inLHS
160159

161160

162161
template<typename R>
163-
inline hx::IndexRef AddEq(hx::IndexRef inLHS, R inRHS) { inLHS = inLHS + inRHS; return inLHS; }
162+
inline hx::IndexRef AddEq(hx::IndexRef inLHS, R inRHS) { inLHS = inLHS + hx::Val{ inRHS }; return inLHS; }
164163
template<typename R>
165164
inline hx::IndexRef MultEq(hx::IndexRef inLHS, R inRHS) { inLHS = (double)inLHS * (double)inRHS; return inLHS; }
166165
template<typename R>
@@ -184,7 +183,6 @@ inline hx::IndexRef ModEq(hx::IndexRef inLHS, R inRHS) { inLHS = DoubleMod(inLHS
184183

185184

186185

187-
#endif // __GNUC__ || __SNC__
188186

189187
template<typename R,typename T>
190188
inline hx::__TArrayImplRef<T> AddEq(hx::__TArrayImplRef<T> ref, R inRHS)

toolchain/haxe-target.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@
185185
<file name = "src/hx/StdLibs.cpp" tags="haxe,static" />
186186
<file name = "src/hx/Debug.cpp"/>
187187
<file name = "src/hx/Debugger.cpp" if="HXCPP_DEBUGGER" />
188+
<file name = "src/hx/FieldRef.cpp"/>
189+
<file name = "src/hx/IndexRef.cpp"/>
188190

189191
<section if="HXCPP_TELEMETRY">
190192
<file name = "src/hx/TelemetryTracy.cpp" if="HXCPP_TRACY"/>

0 commit comments

Comments
 (0)