| 125 | |
| 126 | template<typename T, typename HANDLER = DefaultStructHandler > |
| 127 | class Struct |
| 128 | { |
| 129 | public: |
| 130 | T value; |
| 131 | // This allows 'StaticCast' to be used from arrays |
| 132 | typedef Dynamic Ptr; |
| 133 | |
| 134 | inline Struct( ) : value() { } |
| 135 | inline Struct( const T &inRHS ) : value(inRHS) { } |
| 136 | inline Struct( const null &) { value = T(); } |
| 137 | inline Struct( const Reference<T> &); |
| 138 | inline Struct( const Dynamic &inRHS) { fromDynamic(inRHS.mPtr); } |
| 139 | |
| 140 | template<class... TArgs> |
| 141 | Struct(TArgs... args) : value(std::forward<TArgs>(args)...) {} |
| 142 | |
| 143 | inline Struct<T,HANDLER> &operator=( const T &inRHS ) { value = inRHS; return *this; } |
| 144 | inline Struct<T,HANDLER> &operator=( const null & ) { value = T(); return *this; } |
| 145 | inline Struct<T,HANDLER> &operator=( const Dynamic &inRHS ) { return *this = Struct<T,HANDLER>(inRHS); } |
| 146 | |
| 147 | operator Dynamic() const |
| 148 | { |
| 149 | hx::Object *result = 0; |
| 150 | HANDLER::handler(dhoToDynamic, (void *)&value, sizeof(T), &result ); |
| 151 | if (result) |
| 152 | return result; |
| 153 | return CreateDynamicStruct( &value, sizeof(T), HANDLER::handler); |
| 154 | } |
| 155 | operator String() const { return HANDLER::toString(&value); } |
| 156 | |
| 157 | inline Struct( const hx::Val &inRHS) { fromDynamic(inRHS.asObject()); } |
| 158 | operator hx::Val() const { return operator Dynamic(); } |
| 159 | |
| 160 | bool operator==(const Struct<T,HANDLER> &inRHS) const { return value==inRHS.value; } |
| 161 | bool operator==(const null &inRHS) const { return false; } |
| 162 | bool operator!=(const null &inRHS) const { return true; } |
| 163 | |
| 164 | // Haxe uses -> notation |
| 165 | inline T *operator->() { return &value; } |
| 166 | |
| 167 | T &get() { return value; } |
| 168 | |
| 169 | static inline bool is( const Dynamic &inRHS) |
| 170 | { |
| 171 | hx::Object *ptr = inRHS.mPtr; |
| 172 | if (!ptr) |
| 173 | return false; |
| 174 | StructHandlerDynamicParams convert(ptr, ptr->__CStr()); |
| 175 | HANDLER::handler(dhoIs, 0, sizeof(T), &convert ); |
| 176 | return convert.outProcessed; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | inline void fromDynamic( hx::Object *ptr) |
| 181 | { |
| 182 | if (!ptr) |
| 183 | { |
| 184 | value = T(); |
nothing calls this directly
no test coverage detected