-
Notifications
You must be signed in to change notification settings - Fork 12
/
Enum.cpp
172 lines (142 loc) · 4.33 KB
/
Enum.cpp
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
#include <hxcpp.h>
// -------- Enums ---------------------------------
namespace hx
{
Dynamic EnumBase_obj::__Create(DynamicArray inArgs) { return new hx::EnumBase_obj; }
Dynamic EnumBase_obj::__CreateEmpty() { return new hx::EnumBase_obj; }
int EnumBase_obj::__FindIndex(String inName)
{
if (inName==HX_CSTRING("__")) return 1;
return -1;
}
int EnumBase_obj::__FindArgCount(String inName)
{
if (inName==HX_CSTRING("__")) return 0;
return -1;
}
hx::Val EnumBase_obj::__Field(const String &inName, hx::PropertyAccess inCallProp)
{
if (HX_FIELD_EQ(inName,"tag") ) { return ::hx::Val( _hx_tag ); }
if (HX_FIELD_EQ(inName,"index") ) { return ::hx::Val( index ); }
return null();
}
hx::Class hxEnumBase_obj__mClass;
hx::Class &EnumBase_obj::__SGetClass() { return hxEnumBase_obj__mClass; }
//void hxEnumBase_obj::__GetFields(Array<String> &outFields) { }
void EnumBase_obj::__boot()
{
Static(hxEnumBase_obj__mClass) = hx::_hx_RegisterClass(HX_CSTRING("__EnumBase") ,TCanCast<EnumBase_obj>,
sNone,sNone,
&__CreateEmpty, &__Create, 0 );
}
#if (HXCPP_API_LEVEL >= 330)
DynamicArray EnumBase_obj::_hx_getParameters()
{
Array<Dynamic> result = Array_obj<Dynamic>::__new(mFixedFields);
cpp::Variant *fixed = _hx_getFixed();
for(int i=0;i<mFixedFields;i++)
result[i] = fixed[i];
return result;
}
#endif
int EnumBase_obj::__Compare(const hx::Object *inRHS) const
{
if (inRHS->__GetType()!=vtEnum) return -1;
const EnumBase_obj *rhs = static_cast<const EnumBase_obj *>(inRHS);
#if (HXCPP_API_LEVEL >= 330)
if (_hx_tag!=rhs->_hx_tag || GetEnumName()!=rhs->GetEnumName()) return -1;
if (mFixedFields!=rhs->mFixedFields) return -1;
if (!mFixedFields) return 0;
const cpp::Variant *f0 = _hx_getFixed();
const cpp::Variant *f1 = rhs->_hx_getFixed();
for(int i=0;i<mFixedFields;i++)
if ( f0[i] != f1[i])
return -1;
#else
if (tag!=rhs->tag || GetEnumName()!=rhs->GetEnumName()) return -1;
if (mArgs==null() && rhs->mArgs==null())
return 0;
if (mArgs==null() || rhs->mArgs==null())
return -1;
int n = mArgs->__length();
if (rhs->mArgs->__length()!=n)
return -1;
for(int i=0;i<n;i++)
if ( mArgs[i] != rhs->mArgs[i] )
return -1;
#endif
return 0;
}
#if (HXCPP_API_LEVEL >= 330)
bool __hxcpp_enum_eq( ::hx::EnumBase a, ::hx::EnumBase b)
{
if (!a.mPtr || !b.mPtr)
return !a.mPtr && !b.mPtr;
// Known to be same type
if (a->index != b->index)
return 0;
int n = a->_hx_getParamCount();
if (n==0)
return true;
cpp::Variant *fa = a->_hx_getFixed();
cpp::Variant *fb = b->_hx_getFixed();
for(int i=0;i<n;i++)
if ( fa[i]!=fb[i] )
return false;
return true;
}
#endif
void EnumBase_obj::__Mark(hx::MarkContext *__inCtx)
{
#if (HXCPP_API_LEVEL >= 330)
HX_MARK_MEMBER(_hx_tag);
if (mFixedFields>0)
{
cpp::Variant *v = _hx_getFixed();
for(int i=0;i<mFixedFields;i++)
HX_MARK_MEMBER(v[i]);
}
#else
HX_MARK_MEMBER(tag);
HX_MARK_MEMBER(mArgs);
#endif
}
#ifdef HXCPP_VISIT_ALLOCS
void EnumBase_obj::__Visit(hx::VisitContext *__inCtx)
{
#if (HXCPP_API_LEVEL >= 330)
HX_VISIT_MEMBER(_hx_tag);
if (mFixedFields>0)
{
cpp::Variant *v = _hx_getFixed();
for(int i=0;i<mFixedFields;i++)
HX_VISIT_MEMBER(v[i]);
}
#else
HX_VISIT_MEMBER(tag);
HX_VISIT_MEMBER(mArgs);
#endif
}
#endif
Dynamic EnumBase_obj::__GetItem(int inIndex) const
{
return ((EnumBase_obj *)this)->_hx_getParamI(inIndex);
}
String EnumBase_obj::toString() {
#if (HXCPP_API_LEVEL >= 330)
if (mFixedFields==0)
return _hx_tag;
if (mFixedFields==1)
return _hx_tag + HX_CSTRING("(") + _hx_getFixed()->asString() + HX_CSTRING(")");
Array<String> args = Array_obj<String>::__new(mFixedFields);
cpp::Variant *v = _hx_getFixed();
for(int i=0;i<mFixedFields;i++)
args[i] = v[i].asString();
return _hx_tag + HX_CSTRING("(") + args->join(HX_CSTRING(",")) + HX_CSTRING(")");
#else
if (mArgs==null() || mArgs->length==0)
return tag;
return tag + HX_CSTRING("(") + mArgs->join(HX_CSTRING(",")) + HX_CSTRING(")");
#endif
}
}