Update Files
This commit is contained in:
92
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/CppInt32__.h
Normal file
92
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/CppInt32__.h
Normal file
@ -0,0 +1,92 @@
|
||||
#ifndef INCLUDED_haxe_CppInt32__
|
||||
#define INCLUDED_haxe_CppInt32__
|
||||
|
||||
#include <hxcpp.h>
|
||||
|
||||
namespace cpp
|
||||
{
|
||||
|
||||
#define HX_I32_DEF_FUNC1(Name) \
|
||||
static inline Dynamic __##Name(const Dynamic &a) { return Name(a); } \
|
||||
static inline Dynamic Name##_dyn() { return hx::CreateStaticFunction1(#Name,&CppInt32__::__##Name); }
|
||||
|
||||
#define HX_I32_DEF_FUNC2(Name) \
|
||||
static inline Dynamic __##Name(const Dynamic &a, const Dynamic &b) { return Name(a,b); } \
|
||||
static inline Dynamic Name##_dyn() { return hx::CreateStaticFunction2(#Name,&CppInt32__::__##Name); }
|
||||
|
||||
class CppInt32__
|
||||
{
|
||||
public:
|
||||
CppInt32__(int inX=0) : mValue(inX) { }
|
||||
CppInt32__(const null &inNull) : mValue(0) { }
|
||||
CppInt32__(const Dynamic &inD);
|
||||
operator int() const { return mValue; }
|
||||
template<typename T>
|
||||
inline CppInt32__ &operator=(T inValue) { mValue = inValue; return *this; }
|
||||
|
||||
static inline CppInt32__ make(int a,int b) { return CppInt32__( (a<<16) | b ); }
|
||||
static inline CppInt32__ ofInt(int a) { return CppInt32__( a ); }
|
||||
static inline int toInt(CppInt32__ a) { __hxcpp_check_overflow(a); return a.mValue; }
|
||||
static inline int toNativeInt(CppInt32__ a) { return a.mValue; }
|
||||
static inline CppInt32__ add(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue + b.mValue ); }
|
||||
static inline CppInt32__ sub(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue - b.mValue ); }
|
||||
static inline CppInt32__ mul(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue * b.mValue ); }
|
||||
static inline CppInt32__ div(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue / b.mValue ); }
|
||||
static inline CppInt32__ mod(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue % b.mValue ); }
|
||||
static inline CppInt32__ shl(CppInt32__ a,int b) { return CppInt32__( a.mValue << (b&31) ); }
|
||||
static inline CppInt32__ shr(CppInt32__ a,int b) { return CppInt32__( a.mValue >> (b&31) ); }
|
||||
static inline CppInt32__ ushr(CppInt32__ a,int b) { return CppInt32__( ((unsigned int)a.mValue) >> (b&31) ); }
|
||||
static inline CppInt32__ _and(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue & b.mValue ); }
|
||||
static inline CppInt32__ _or(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue | b.mValue ); }
|
||||
static inline CppInt32__ _xor(CppInt32__ a,CppInt32__ b) { return CppInt32__( a.mValue ^ b.mValue ); }
|
||||
static inline CppInt32__ neg(CppInt32__ a) { return CppInt32__( -a.mValue ); }
|
||||
static inline CppInt32__ complement(CppInt32__ a) { return CppInt32__( ~a.mValue ); }
|
||||
static inline int compare(CppInt32__ a,CppInt32__ b) { return ( a.mValue - b.mValue ); }
|
||||
static inline bool isNeg(CppInt32__ a) { return a.mValue < 0; }
|
||||
static inline bool isZero(CppInt32__ a) { return a.mValue == 0; }
|
||||
static inline int ucompare(CppInt32__ a,CppInt32__ b) { unsigned int am = a.mValue, bm = b.mValue; return (am == bm) ? 0 : ((am > bm) ? 1 : -1); }
|
||||
|
||||
|
||||
inline bool operator==(const CppInt32__ &inRHS) const { return mValue == inRHS.mValue; }
|
||||
|
||||
inline int operator-(CppInt32__ b) { return mValue - b.mValue; }
|
||||
inline int operator+(CppInt32__ b) { return mValue + b.mValue; }
|
||||
inline int operator*(CppInt32__ b) { return mValue * b.mValue; }
|
||||
inline int operator/(CppInt32__ b) { return mValue / b.mValue; }
|
||||
inline int operator%(CppInt32__ b) { return mValue % b.mValue; }
|
||||
|
||||
HX_I32_DEF_FUNC2(make)
|
||||
HX_I32_DEF_FUNC1(ofInt)
|
||||
HX_I32_DEF_FUNC1(toInt)
|
||||
HX_I32_DEF_FUNC1(toNativeInt)
|
||||
HX_I32_DEF_FUNC2(add)
|
||||
HX_I32_DEF_FUNC2(sub)
|
||||
HX_I32_DEF_FUNC2(mul)
|
||||
HX_I32_DEF_FUNC2(div)
|
||||
HX_I32_DEF_FUNC2(mod)
|
||||
HX_I32_DEF_FUNC2(shl)
|
||||
HX_I32_DEF_FUNC2(shr)
|
||||
HX_I32_DEF_FUNC2(ushr)
|
||||
HX_I32_DEF_FUNC2(_and)
|
||||
HX_I32_DEF_FUNC2(_or)
|
||||
HX_I32_DEF_FUNC2(_xor)
|
||||
HX_I32_DEF_FUNC1(neg)
|
||||
HX_I32_DEF_FUNC1(complement)
|
||||
HX_I32_DEF_FUNC2(compare)
|
||||
HX_I32_DEF_FUNC2(ucompare)
|
||||
HX_I32_DEF_FUNC1(isNeg)
|
||||
HX_I32_DEF_FUNC1(isZero)
|
||||
|
||||
int mValue;
|
||||
};
|
||||
|
||||
typedef CppInt32__ CppInt32___obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
108
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/FastIterator.h
Normal file
108
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/FastIterator.h
Normal file
@ -0,0 +1,108 @@
|
||||
#ifndef INCLUDED_cpp_FastIterator
|
||||
#define INCLUDED_cpp_FastIterator
|
||||
|
||||
namespace cpp
|
||||
{
|
||||
|
||||
class HXCPP_EXTERN_CLASS_ATTRIBUTES IteratorBase : public hx::Object
|
||||
{
|
||||
public:
|
||||
hx::Val __Field(const String &inString ,hx::PropertyAccess inCallProp);
|
||||
virtual bool hasNext() = 0;
|
||||
virtual Dynamic _dynamicNext() = 0;
|
||||
|
||||
Dynamic hasNext_dyn( );
|
||||
Dynamic next_dyn( );
|
||||
Dynamic _dynamicNext_dyn( );
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
class HXCPP_EXTERN_CLASS_ATTRIBUTES FastIterator_obj : public IteratorBase
|
||||
{
|
||||
public:
|
||||
virtual bool hasNext() = 0;
|
||||
virtual T next() = 0;
|
||||
|
||||
virtual Dynamic _dynamicNext() { return next(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
class HXCPP_EXTERN_CLASS_ATTRIBUTES DynamicIterator : public FastIterator_obj<T>
|
||||
{
|
||||
public:
|
||||
Dynamic mNext;
|
||||
Dynamic mHasNext;
|
||||
|
||||
DynamicIterator(Dynamic inValue)
|
||||
{
|
||||
mNext = inValue->__Field(HX_CSTRING("next"), HX_PROP_ALWAYS);
|
||||
mHasNext = inValue->__Field(HX_CSTRING("hasNext"), HX_PROP_ALWAYS);
|
||||
}
|
||||
|
||||
bool hasNext() { return mHasNext(); }
|
||||
T next() { return mNext(); }
|
||||
|
||||
void __Mark(hx::MarkContext *__inCtx)
|
||||
{
|
||||
HX_MARK_MEMBER_NAME(mNext,"mNext");
|
||||
HX_MARK_MEMBER_NAME(mHasNext,"mHasNext");
|
||||
}
|
||||
|
||||
#ifdef HXCPP_VISIT_ALLOCS
|
||||
void __Visit(hx::VisitContext *__inCtx)
|
||||
{
|
||||
HX_VISIT_MEMBER_NAME(mNext,"mNext");
|
||||
HX_VISIT_MEMBER_NAME(mHasNext,"mHasNext");
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
FastIterator_obj<T> *CreateFastIterator(Dynamic inValue)
|
||||
{
|
||||
FastIterator_obj<T> *result = dynamic_cast< FastIterator_obj<T> *>(inValue.GetPtr());
|
||||
if (result) return result;
|
||||
return new DynamicIterator<T>(inValue);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class HXCPP_EXTERN_CLASS_ATTRIBUTES StringIterator : public cpp::FastIterator_obj<T>
|
||||
{
|
||||
public:
|
||||
String value;
|
||||
int pos;
|
||||
|
||||
StringIterator(const String &inValue) : value(inValue), pos(0) { }
|
||||
|
||||
bool hasNext() { return pos<value.length; }
|
||||
void __Mark(hx::MarkContext *__inCtx)
|
||||
{
|
||||
cpp::FastIterator_obj<T>::__Mark(__inCtx);
|
||||
HX_MARK_MEMBER_NAME(value,"value");
|
||||
}
|
||||
|
||||
#ifdef HXCPP_VISIT_ALLOCS
|
||||
void __Visit(hx::VisitContext *__inCtx)
|
||||
{
|
||||
cpp::FastIterator_obj<T>::__Visit(__inCtx);
|
||||
HX_VISIT_MEMBER_NAME(value,"value");
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
148
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/Int64.h
Normal file
148
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/Int64.h
Normal file
@ -0,0 +1,148 @@
|
||||
#ifndef CPP_INT64_INCLUDED
|
||||
#define CPP_INT64_INCLUDED
|
||||
|
||||
namespace cpp
|
||||
{
|
||||
|
||||
class Int64Handler
|
||||
{
|
||||
public:
|
||||
static inline const char *getName() { return "cpp.Int64"; }
|
||||
static inline String toString( const void *inValue ) { return String( *(Int64 *)inValue ); }
|
||||
static inline void handler(DynamicHandlerOp op, void *ioValue,int inSize, void *outResult)
|
||||
{
|
||||
if (op==dhoToString)
|
||||
*(String *)outResult = toString(ioValue);
|
||||
else if (op==dhoGetClassName)
|
||||
*(const char **)outResult = getName();
|
||||
else if (op==dhoFromDynamic)
|
||||
{
|
||||
StructHandlerDynamicParams *params = (StructHandlerDynamicParams *)outResult;
|
||||
cpp::Int64 &value = *(cpp::Int64 *)ioValue;
|
||||
params->outProcessed = true;
|
||||
if (!params->inData)
|
||||
value = 0;
|
||||
else
|
||||
value = params->inData->__ToInt64();
|
||||
}
|
||||
else if (op==dhoToDynamic)
|
||||
{
|
||||
Dynamic value = *(cpp::Int64 *)ioValue;
|
||||
*(hx::Object **)outResult = value.mPtr;
|
||||
}
|
||||
else if (op==dhoIs)
|
||||
{
|
||||
StructHandlerDynamicParams *params = (StructHandlerDynamicParams *)outResult;
|
||||
hx::Object *obj = params->inData;
|
||||
int type = obj->__GetType();
|
||||
params->outProcessed = type==vtInt || type==vtInt64;
|
||||
}
|
||||
else
|
||||
return DefaultStructHandler::handler(op,ioValue,inSize, outResult);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Struct<Int64,Int64Handler> Int64Struct;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if (HXCPP_API_LEVEL >= 420)
|
||||
|
||||
inline cpp::Int64 _hx_int64_make(int a, int b) { return (((cpp::Int64)(unsigned int)a)<<32) | (unsigned int)b; }
|
||||
inline bool _hx_int64_is_neg(cpp::Int64 a) { return a<0; }
|
||||
inline bool _hx_int64_is_zero(cpp::Int64 a) { return a==0; }
|
||||
inline bool _hx_int64_eq(cpp::Int64 a, cpp::Int64 b) { return a==b; }
|
||||
inline bool _hx_int64_neq(cpp::Int64 a, cpp::Int64 b) { return a!=b; }
|
||||
inline int _hx_int64_compare(cpp::Int64 a, cpp::Int64 b)
|
||||
{
|
||||
return a==b ? 0 : a<b ? -1 : 1;
|
||||
}
|
||||
inline int _hx_int64_ucompare(cpp::Int64 a, cpp::Int64 b)
|
||||
{
|
||||
return a==b ? 0 : ( ::cpp::UInt64)a<( ::cpp::UInt64)b ? -1 : 1;
|
||||
}
|
||||
inline String _hx_int64_to_string(cpp::Int64 a) { return a; }
|
||||
|
||||
inline cpp::Int64 _hx_int64_neg(cpp::Int64 a) { return -a; }
|
||||
inline cpp::Int64 _hx_int64_complement(cpp::Int64 a) { return ~a; }
|
||||
|
||||
inline cpp::Int64 _hx_int64_pre_increment(cpp::Int64 &ioVal) {
|
||||
return ++ioVal;
|
||||
}
|
||||
inline cpp::Int64 _hx_int64_post_increment(cpp::Int64 &ioVal) {
|
||||
return ioVal++;
|
||||
}
|
||||
inline cpp::Int64 _hx_int64_pre_decrement(cpp::Int64 &ioVal) {
|
||||
return --ioVal;
|
||||
}
|
||||
inline cpp::Int64 _hx_int64_post_decrement(cpp::Int64 &ioVal) {
|
||||
return ioVal--;
|
||||
}
|
||||
|
||||
inline cpp::Int64 _hx_int64_sub(cpp::Int64 a, cpp::Int64 b) { return a-b; }
|
||||
inline cpp::Int64 _hx_int64_add(cpp::Int64 a, cpp::Int64 b) { return a+b; }
|
||||
inline cpp::Int64 _hx_int64_mul(cpp::Int64 a, cpp::Int64 b) { return a*b; }
|
||||
inline cpp::Int64 _hx_int64_div(cpp::Int64 a, cpp::Int64 b) { return a/b; }
|
||||
inline cpp::Int64 _hx_int64_mod(cpp::Int64 a, cpp::Int64 b) { return a%b; }
|
||||
inline cpp::Int64 _hx_int64_and(cpp::Int64 a, cpp::Int64 b) { return a&b; }
|
||||
inline cpp::Int64 _hx_int64_or(cpp::Int64 a, cpp::Int64 b) { return a|b; }
|
||||
inline cpp::Int64 _hx_int64_xor(cpp::Int64 a, cpp::Int64 b) { return a^b; }
|
||||
inline cpp::Int64 _hx_int64_shl(cpp::Int64 a, int b) { return a<<(b&63); }
|
||||
inline cpp::Int64 _hx_int64_shr(cpp::Int64 a, int b) { return a>>(b&63); }
|
||||
inline cpp::Int64 _hx_int64_ushr(cpp::Int64 a, int b) { return ((cpp::UInt64)a)>>(b&63); }
|
||||
inline int _hx_int64_high(cpp::Int64 a) { return (int)( a >> 32 ); }
|
||||
inline int _hx_int64_low(cpp::Int64 a) { return (int)( a & 0xffffffff ); }
|
||||
|
||||
#else
|
||||
|
||||
inline cpp::Int64Struct _hx_int64_make(int a, int b) { return (((cpp::Int64)(unsigned int)a)<<32) | (unsigned int)b; }
|
||||
inline bool _hx_int64_is_neg(cpp::Int64 a) { return a<0; }
|
||||
inline bool _hx_int64_is_zero(cpp::Int64 a) { return a==0; }
|
||||
inline bool _hx_int64_eq(cpp::Int64 a, cpp::Int64 b) { return a==b; }
|
||||
inline bool _hx_int64_neq(cpp::Int64 a, cpp::Int64 b) { return a!=b; }
|
||||
inline int _hx_int64_compare(cpp::Int64 a, cpp::Int64 b)
|
||||
{
|
||||
return a==b ? 0 : a<b ? -1 : 1;
|
||||
}
|
||||
inline int _hx_int64_ucompare(cpp::Int64 a, cpp::Int64 b)
|
||||
{
|
||||
return a==b ? 0 : ( ::cpp::UInt64)a<( ::cpp::UInt64)b ? -1 : 1;
|
||||
}
|
||||
inline String _hx_int64_to_string(cpp::Int64Struct a) { return a; }
|
||||
|
||||
inline cpp::Int64Struct _hx_int64_neg(cpp::Int64 a) { return -a; }
|
||||
inline cpp::Int64Struct _hx_int64_complement(cpp::Int64 a) { return ~a; }
|
||||
|
||||
inline cpp::Int64Struct _hx_int64_pre_increment(cpp::Int64Struct &ioVal) {
|
||||
return ++ioVal.get();
|
||||
}
|
||||
inline cpp::Int64Struct _hx_int64_post_increment(cpp::Int64Struct &ioVal) {
|
||||
return ioVal.get()++;
|
||||
}
|
||||
inline cpp::Int64Struct _hx_int64_pre_decrement(cpp::Int64Struct &ioVal) {
|
||||
return --ioVal.get();
|
||||
}
|
||||
inline cpp::Int64Struct _hx_int64_post_decrement(cpp::Int64Struct &ioVal) {
|
||||
return ioVal.get()--;
|
||||
}
|
||||
|
||||
inline cpp::Int64Struct _hx_int64_sub(cpp::Int64 a, cpp::Int64 b) { return a-b; }
|
||||
inline cpp::Int64Struct _hx_int64_add(cpp::Int64 a, cpp::Int64 b) { return a+b; }
|
||||
inline cpp::Int64Struct _hx_int64_mul(cpp::Int64 a, cpp::Int64 b) { return a*b; }
|
||||
inline cpp::Int64Struct _hx_int64_div(cpp::Int64 a, cpp::Int64 b) { return a/b; }
|
||||
inline cpp::Int64Struct _hx_int64_mod(cpp::Int64 a, cpp::Int64 b) { return a%b; }
|
||||
inline cpp::Int64Struct _hx_int64_and(cpp::Int64 a, cpp::Int64 b) { return a&b; }
|
||||
inline cpp::Int64Struct _hx_int64_or(cpp::Int64 a, cpp::Int64 b) { return a|b; }
|
||||
inline cpp::Int64Struct _hx_int64_xor(cpp::Int64 a, cpp::Int64 b) { return a^b; }
|
||||
inline cpp::Int64Struct _hx_int64_shl(cpp::Int64 a, int b) { return a<<(b&63); }
|
||||
inline cpp::Int64Struct _hx_int64_shr(cpp::Int64 a, int b) { return a>>(b&63); }
|
||||
inline cpp::Int64Struct _hx_int64_ushr(cpp::Int64 a, int b) { return ((cpp::UInt64)a)>>(b&63); }
|
||||
inline int _hx_int64_high(cpp::Int64Struct a) { return (int)( a.get() >>32 ); }
|
||||
inline int _hx_int64_low(cpp::Int64Struct a) { return (int)( a.get() & 0xffffffff ); }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
562
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/Pointer.h
Normal file
562
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/Pointer.h
Normal file
@ -0,0 +1,562 @@
|
||||
#ifndef CPP_POINTER_H
|
||||
#define CPP_POINTER_H
|
||||
|
||||
namespace cpp
|
||||
{
|
||||
|
||||
struct AutoCast
|
||||
{
|
||||
void *value;
|
||||
|
||||
explicit inline AutoCast(void *inValue) : value(inValue) { }
|
||||
};
|
||||
|
||||
|
||||
struct RawAutoCast
|
||||
{
|
||||
void *value;
|
||||
|
||||
explicit inline RawAutoCast(void *inValue) : value(inValue) { }
|
||||
|
||||
template<typename T>
|
||||
operator T*() const { return (T*)value; }
|
||||
};
|
||||
|
||||
|
||||
Dynamic CreateDynamicPointer(void *inValue);
|
||||
|
||||
enum DynamicHandlerOp
|
||||
{
|
||||
dhoGetClassName,
|
||||
dhoToString,
|
||||
dhoFromDynamic,
|
||||
dhoToDynamic,
|
||||
dhoIs,
|
||||
};
|
||||
typedef void (*DynamicHandlerFunc)(DynamicHandlerOp op, void *ioValue, int inSize, void *outResult);
|
||||
Dynamic CreateDynamicStruct(const void *inValue, int inSize, DynamicHandlerFunc inFunc);
|
||||
|
||||
template<typename T> class Reference;
|
||||
|
||||
|
||||
|
||||
struct StructHandlerDynamicParams
|
||||
{
|
||||
StructHandlerDynamicParams(hx::Object *data,const char *inName) :
|
||||
outProcessed(false), inName(inName), inData(data) { }
|
||||
bool outProcessed;
|
||||
hx::Object *inData;
|
||||
const char *inName;
|
||||
};
|
||||
|
||||
|
||||
class DefaultStructHandler
|
||||
{
|
||||
public:
|
||||
static inline const char *getName() { return "unknown"; }
|
||||
static inline String toString( const void *inValue ) { return HX_CSTRING("Struct"); }
|
||||
static inline void handler(DynamicHandlerOp op, void *ioValue, int inSize, void *outResult)
|
||||
{
|
||||
if (op==dhoToString)
|
||||
*(String *)outResult = toString(ioValue);
|
||||
else if (op==dhoGetClassName)
|
||||
*(const char **)outResult = getName();
|
||||
else if (op==dhoToDynamic)
|
||||
{
|
||||
// Handle outsize..
|
||||
*(hx::Object **)outResult = 0;
|
||||
}
|
||||
else if (op==dhoFromDynamic)
|
||||
{
|
||||
StructHandlerDynamicParams *params = (StructHandlerDynamicParams *)outResult;
|
||||
hx::Object *ptr= params->inData;
|
||||
void *data = (void *)ptr->__GetHandle();
|
||||
int len = ptr->__length();
|
||||
if (data && len>=inSize && ptr->__CStr()==params->inName)
|
||||
{
|
||||
memcpy(ioValue,data,inSize);
|
||||
params->outProcessed = true;
|
||||
}
|
||||
}
|
||||
else if (op==dhoIs)
|
||||
{
|
||||
StructHandlerDynamicParams *params = (StructHandlerDynamicParams *)outResult;
|
||||
hx::Object *ptr= params->inData;
|
||||
void *data = (void *)ptr->__GetHandle();
|
||||
int len = ptr->__length();
|
||||
params->outProcessed = data && len>=inSize && ptr->__CStr()==params->inName;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class EnumHandler
|
||||
{
|
||||
public:
|
||||
static inline const char *getName() { return "enum"; }
|
||||
static inline String toString( const void *inValue ) {
|
||||
int val = inValue ? *(int *)inValue : 0;
|
||||
return HX_CSTRING("enum(") + String(val) + HX_CSTRING(")");
|
||||
}
|
||||
|
||||
static inline void handler(DynamicHandlerOp op, void *ioValue, int inSize, void *outResult)
|
||||
{
|
||||
if (op==dhoToString)
|
||||
*(String *)outResult = toString(ioValue);
|
||||
else if (op==dhoGetClassName)
|
||||
*(const char **)outResult = getName();
|
||||
else if (op==dhoFromDynamic)
|
||||
{
|
||||
StructHandlerDynamicParams *params = (StructHandlerDynamicParams *)outResult;
|
||||
if (params->inData->__GetType()==vtInt)
|
||||
{
|
||||
*(int *)ioValue = params->inData->__ToInt();
|
||||
params->outProcessed = true;
|
||||
}
|
||||
else
|
||||
DefaultStructHandler::handler(op,ioValue, inSize, outResult);
|
||||
}
|
||||
else
|
||||
DefaultStructHandler::handler(op,ioValue, inSize, outResult);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename T, typename HANDLER = DefaultStructHandler >
|
||||
class Struct
|
||||
{
|
||||
public:
|
||||
T value;
|
||||
// This allows 'StaticCast' to be used from arrays
|
||||
typedef Dynamic Ptr;
|
||||
|
||||
inline Struct( ) { }
|
||||
inline Struct( const T &inRHS ) : value(inRHS) { }
|
||||
inline Struct( const null &) { value = T(); }
|
||||
inline Struct( const Reference<T> &);
|
||||
inline Struct( const Dynamic &inRHS) { fromDynamic(inRHS.mPtr); }
|
||||
|
||||
inline Struct<T,HANDLER> &operator=( const T &inRHS ) { value = inRHS; return *this; }
|
||||
inline Struct<T,HANDLER> &operator=( const null & ) { value = T(); return *this; }
|
||||
inline Struct<T,HANDLER> &operator=( const Dynamic &inRHS ) { return *this = Struct<T,HANDLER>(inRHS); }
|
||||
|
||||
operator Dynamic() const
|
||||
{
|
||||
hx::Object *result = 0;
|
||||
HANDLER::handler(dhoToDynamic, (void *)&value, sizeof(T), &result );
|
||||
if (result)
|
||||
return result;
|
||||
return CreateDynamicStruct( &value, sizeof(T), HANDLER::handler);
|
||||
}
|
||||
operator String() const { return HANDLER::toString(&value); }
|
||||
|
||||
#if (HXCPP_API_LEVEL >= 330)
|
||||
inline Struct( const hx::Val &inRHS) { fromDynamic(inRHS.asObject()); }
|
||||
operator hx::Val() const { return operator Dynamic(); }
|
||||
#endif
|
||||
|
||||
bool operator==(const Struct<T,HANDLER> &inRHS) const { return value==inRHS.value; }
|
||||
bool operator==(const null &inRHS) const { return false; }
|
||||
bool operator!=(const null &inRHS) const { return true; }
|
||||
|
||||
// Haxe uses -> notation
|
||||
inline T *operator->() { return &value; }
|
||||
|
||||
T &get() { return value; }
|
||||
|
||||
static inline bool is( const Dynamic &inRHS)
|
||||
{
|
||||
hx::Object *ptr = inRHS.mPtr;
|
||||
if (!ptr)
|
||||
return false;
|
||||
StructHandlerDynamicParams convert(ptr, ptr->__CStr());
|
||||
HANDLER::handler(dhoIs, 0, sizeof(T), &convert );
|
||||
return convert.outProcessed;
|
||||
}
|
||||
|
||||
|
||||
inline void fromDynamic( hx::Object *ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
{
|
||||
value = T();
|
||||
return;
|
||||
}
|
||||
StructHandlerDynamicParams convert(ptr, ptr->__CStr());
|
||||
HANDLER::handler(dhoFromDynamic, &value, sizeof(T), &convert );
|
||||
if (!convert.outProcessed)
|
||||
{
|
||||
hx::NullReference("DynamicData", true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inline operator T& () { return value; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
class Pointer
|
||||
{
|
||||
public:
|
||||
typedef T elementType;
|
||||
|
||||
T *ptr;
|
||||
|
||||
inline Pointer( ) : ptr(0) { }
|
||||
inline Pointer( const Pointer &inRHS ) : ptr(inRHS.ptr) { }
|
||||
inline Pointer( const Dynamic &inRHS) { ptr = inRHS==null()?0: (T*)inRHS->__GetHandle(); }
|
||||
inline Pointer( const null &inRHS ) : ptr(0) { }
|
||||
inline Pointer( const cpp::Variant &inVariant ) {
|
||||
hx::Object *obj = inVariant.asObject();
|
||||
ptr = obj ? (T*)inVariant.valObject->__GetHandle() : 0;
|
||||
}
|
||||
|
||||
template<typename O>
|
||||
inline Pointer( const O *inValue ) : ptr( (T*) inValue) { }
|
||||
//inline Pointer( T *inValue ) : ptr(inValue) { }
|
||||
inline Pointer( AutoCast inValue ) : ptr( (T*)inValue.value) { }
|
||||
|
||||
template<typename H>
|
||||
inline Pointer( const Struct<T,H> &structVal ) : ptr( &structVal.value ) { }
|
||||
|
||||
template<typename O>
|
||||
inline void setRaw(const O *inValue ) { ptr = (T*) inValue; }
|
||||
|
||||
|
||||
inline Pointer operator=( const Pointer &inRHS ) { return ptr = inRHS.ptr; }
|
||||
inline Dynamic operator=( Dynamic &inValue )
|
||||
{
|
||||
ptr = inValue==null() ? 0 : (T*) inValue->__GetHandle();
|
||||
return inValue;
|
||||
}
|
||||
inline Dynamic operator=( null &inValue ) { ptr=0; return inValue; }
|
||||
|
||||
template<typename O>
|
||||
inline Pointer operator=( const Pointer<O> &inValue ) { ptr = (T*) inValue.ptr; return *this; }
|
||||
|
||||
template<typename O>
|
||||
inline Pointer operator=( const O *inValue ) { ptr = (T*) inValue; return *this; }
|
||||
|
||||
template<typename H>
|
||||
inline Pointer operator=( const Struct<T,H> &structVal ) { ptr = &structVal.value; return *this; }
|
||||
|
||||
|
||||
|
||||
inline AutoCast reinterpret() { return AutoCast(ptr); }
|
||||
inline RawAutoCast rawCast() { return RawAutoCast(ptr); }
|
||||
|
||||
inline bool operator==( const null &inValue ) const { return ptr==0; }
|
||||
inline bool operator!=( const null &inValue ) const { return ptr!=0; }
|
||||
|
||||
// Allow '->' syntax
|
||||
inline Pointer *operator->() { return this; }
|
||||
inline Pointer inc() { return ++ptr; }
|
||||
inline Pointer dec() { return --ptr; }
|
||||
inline Pointer add(int inInt) { return ptr+inInt; }
|
||||
inline Pointer sub(int inInt) { return ptr-inInt; }
|
||||
inline Pointer incBy(int inDiff) { ptr+=inDiff; return ptr; }
|
||||
inline Pointer decBy(int inDiff) { ptr-=inDiff; return ptr; }
|
||||
inline T &postIncRef() { return *ptr++; }
|
||||
inline T &postIncVal() { return *ptr++; }
|
||||
|
||||
inline T &at(int inIndex) { return ptr[inIndex]; }
|
||||
inline void setAt(int inIndex, const T &test) { ptr[inIndex] = test; }
|
||||
|
||||
inline T &__get(int inIndex) { return ptr[inIndex]; }
|
||||
inline T &__set(int inIndex, const T &inValue) { T *p = ptr+inIndex; *p = inValue; return *p; }
|
||||
|
||||
inline T &get_value() { return *ptr; }
|
||||
inline T &get_ref() { return *ptr; }
|
||||
inline T &set_ref(const T &inValue) { return *ptr = inValue; }
|
||||
|
||||
operator Dynamic () const { return CreateDynamicPointer((void *)ptr); }
|
||||
#if (HXCPP_API_LEVEL >= 330)
|
||||
operator cpp::Variant () const { return CreateDynamicPointer((void *)ptr); }
|
||||
#endif
|
||||
|
||||
operator T * () { return ptr; }
|
||||
T * get_raw() { return ptr; }
|
||||
const T * get_constRaw() { return ptr; }
|
||||
|
||||
inline void destroy() { delete ptr; }
|
||||
inline void destroyArray() { delete [] ptr; }
|
||||
|
||||
inline bool lt(Pointer inOther) { return ptr < inOther.ptr; }
|
||||
inline bool gt(Pointer inOther) { return ptr > inOther.ptr; }
|
||||
inline bool leq(Pointer inOther) { return ptr <= inOther.ptr; }
|
||||
inline bool geq(Pointer inOther) { return ptr >= inOther.ptr; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
class Pointer<void>
|
||||
{
|
||||
public:
|
||||
enum { elementSize = 0 };
|
||||
|
||||
void *ptr;
|
||||
|
||||
inline Pointer( ) : ptr(0) { }
|
||||
inline Pointer( const Pointer &inRHS ) : ptr(inRHS.ptr) { }
|
||||
inline Pointer( const Dynamic &inRHS) { ptr = inRHS==null()?0: (void*)inRHS->__GetHandle(); }
|
||||
inline Pointer( const null &inRHS ) : ptr(0) { }
|
||||
|
||||
template<typename O>
|
||||
inline Pointer( const O *inValue ) : ptr( (void*) inValue) { }
|
||||
//inline Pointer( T *inValue ) : ptr(inValue) { }
|
||||
inline Pointer( AutoCast inValue ) : ptr( (void*)inValue.value) { }
|
||||
|
||||
inline Pointer operator=( const Pointer &inRHS ) { return ptr = inRHS.ptr; }
|
||||
inline Dynamic operator=( Dynamic &inValue )
|
||||
{
|
||||
ptr = inValue==null() ? 0 : (void*) inValue->__GetHandle();
|
||||
return inValue;
|
||||
}
|
||||
inline Dynamic operator=( null &inValue ) { ptr=0; return inValue; }
|
||||
inline AutoCast reinterpret() { return AutoCast(ptr); }
|
||||
inline RawAutoCast rawCast() { return RawAutoCast(ptr); }
|
||||
|
||||
inline bool operator==( const null &inValue ) const { return ptr==0; }
|
||||
inline bool operator!=( const null &inValue ) const { return ptr!=0; }
|
||||
|
||||
// Allow '->' syntax
|
||||
inline Pointer *operator->() { return this; }
|
||||
inline Pointer inc() { return ptr; }
|
||||
inline Pointer dec() { return ptr; }
|
||||
inline Pointer add(int inInt) { return ptr; }
|
||||
inline Pointer sub(int inInt) { return ptr; }
|
||||
inline Pointer incBy(int inDiff) { return ptr; }
|
||||
inline Pointer decBy(int inDiff) { return ptr; }
|
||||
inline void postIncRef() { }
|
||||
inline void postIncVal() { }
|
||||
|
||||
inline void at(int inIndex) { }
|
||||
|
||||
inline void __get(int inIndex) { }
|
||||
|
||||
template<typename O>
|
||||
inline void __set(int inIndex, O inValue) { }
|
||||
|
||||
inline void get_value() { }
|
||||
inline void get_ref() { }
|
||||
template<typename O> inline void set_ref(O val) { }
|
||||
|
||||
operator Dynamic () const { return CreateDynamicPointer(ptr); }
|
||||
//operator hx::Val () const { return CreateDynamicPointer((void *)ptr); }
|
||||
operator void * () { return ptr; }
|
||||
void * get_raw() { return ptr; }
|
||||
const void * get_constRaw() { return ptr; }
|
||||
|
||||
inline void destroy() { }
|
||||
inline void destroyArray() { }
|
||||
|
||||
inline bool lt(Pointer inOther) { return ptr < inOther.ptr; }
|
||||
inline bool gt(Pointer inOther) { return ptr > inOther.ptr; }
|
||||
inline bool leq(Pointer inOther) { return ptr <= inOther.ptr; }
|
||||
inline bool geq(Pointer inOther) { return ptr >= inOther.ptr; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline bool operator == (const null &, Pointer<T> inPtr) { return inPtr.ptr==0; }
|
||||
template<typename T>
|
||||
inline bool operator != (const null &, Pointer<T> inPtr) { return inPtr.ptr!=0; }
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
class Reference : public Pointer<T>
|
||||
{
|
||||
public:
|
||||
using Pointer<T>::ptr;
|
||||
|
||||
|
||||
inline Reference( const T &inRHS ) : Pointer<T>(&inRHS) { }
|
||||
inline Reference( T &inRHS ) : Pointer<T>(&inRHS) { }
|
||||
|
||||
inline Reference( ) : Pointer<T>((T*)0) { }
|
||||
inline Reference( const Reference &inRHS ) : Pointer<T>(inRHS.ptr) { }
|
||||
inline Reference( const Dynamic &inRHS) { ptr = inRHS==null()?0: (T*)inRHS->__GetHandle(); }
|
||||
inline Reference( const null &inRHS ) : Pointer<T>((T*)0) { }
|
||||
inline Reference( const T *inValue ) : Pointer<T>( (T*) inValue) { }
|
||||
//inline Reference( T *inValue ) : Pointer(inValue) { }
|
||||
inline Reference( AutoCast inValue ) : Pointer<T>( (T*)inValue.value) { }
|
||||
|
||||
template<typename OTHER>
|
||||
inline Reference( const Reference<OTHER> &inOther )
|
||||
{
|
||||
// Allow reinterpret or not?
|
||||
ptr = (T*)inOther.ptr;
|
||||
}
|
||||
|
||||
template<typename H>
|
||||
inline Reference( const Struct<T,H> &structVal ) : Pointer<T>( &structVal.value ) { }
|
||||
|
||||
inline Reference operator=( const Reference &inRHS ) { return ptr = inRHS.ptr; }
|
||||
|
||||
|
||||
inline T *operator->() const { return ptr; }
|
||||
|
||||
inline operator T &() { return *ptr; }
|
||||
|
||||
};
|
||||
|
||||
template<typename T,typename H>
|
||||
Struct<T,H>::Struct( const Reference<T> &ref ) : value(*ref.ptr) { };
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
class Function
|
||||
{
|
||||
public:
|
||||
T *call;
|
||||
|
||||
inline Function( ) { }
|
||||
inline Function( const Function &inRHS ) : call(inRHS.call) { }
|
||||
inline Function( const Dynamic &inRHS) { call = inRHS==null()?0: (T*)inRHS->__GetHandle(); }
|
||||
inline Function( const null &inRHS ) { call = 0; }
|
||||
inline Function( T *inValue ) : call((T*)(inValue)) { }
|
||||
//inline Function( T *inValue ) : call(inValue) { }
|
||||
inline Function( AutoCast inValue ) : call( (T*)inValue.value) { }
|
||||
inline Function( const hx::AnyCast &inValue ) : call( (T*)inValue.mPtr) { }
|
||||
|
||||
template<typename FROM>
|
||||
inline static Function __new(FROM from)
|
||||
{
|
||||
return Function(from);
|
||||
}
|
||||
|
||||
inline Function operator=( const Function &inRHS ) { return call = inRHS.call; }
|
||||
inline Dynamic operator=( Dynamic &inValue )
|
||||
{
|
||||
call = inValue==null() ? 0 : (T*) inValue->__GetHandle();
|
||||
return inValue;
|
||||
}
|
||||
inline Dynamic operator=( null &inValue ) { call=0; return inValue; }
|
||||
inline bool operator==( const null &inValue ) const { return call==0; }
|
||||
inline bool operator!=( const null &inValue ) const { return call!=0; }
|
||||
|
||||
|
||||
operator Dynamic () const { return CreateDynamicPointer((void *)call); }
|
||||
//operator hx::Val () const { return CreateDynamicPointer((void *)call); }
|
||||
operator T * () { return call; }
|
||||
operator void * () { return (void *)call; }
|
||||
|
||||
inline T &get_call() { return *call; }
|
||||
|
||||
inline bool lt(Function inOther) { return call < inOther.call; }
|
||||
inline bool gt(Function inOther) { return call > inOther.call; }
|
||||
inline bool leq(Function inOther) { return call <= inOther.call; }
|
||||
inline bool geq(Function inOther) { return call >= inOther.call; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline bool operator == (const null &, Function<T> inPtr) { return inPtr.call==0; }
|
||||
template<typename T>
|
||||
inline bool operator != (const null &, Function<T> inPtr) { return inPtr.call!=0; }
|
||||
|
||||
|
||||
|
||||
class Function_obj
|
||||
{
|
||||
public:
|
||||
|
||||
inline static AutoCast getProcAddress(String inLib, String inPrim)
|
||||
{
|
||||
return AutoCast(__hxcpp_get_proc_address(inLib, inPrim,false));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline static AutoCast fromStaticFunction(T *inFunction)
|
||||
{
|
||||
return AutoCast(inFunction);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Pointer_obj
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
inline static AutoCast arrayElem(::Array<T> array, int inIndex) { return AutoCast(&array[inIndex]); }
|
||||
inline static AutoCast arrayElem(Dynamic inVal, int inIndex)
|
||||
{
|
||||
if (inVal==null() || !inVal->__IsArray())
|
||||
return AutoCast(0);
|
||||
hx::ArrayBase *base = (hx::ArrayBase *)inVal.GetPtr();
|
||||
return AutoCast(base->GetBase() + inIndex*base->GetElementSize());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline static AutoCast ofArray(::Array<T> array) { return AutoCast(&array[0]); }
|
||||
inline static AutoCast ofArray(Dynamic inVal)
|
||||
{
|
||||
if (inVal==null() || !inVal->__IsArray())
|
||||
return AutoCast(0);
|
||||
hx::ArrayBase *base = (hx::ArrayBase *)inVal.GetPtr();
|
||||
return AutoCast(base->GetBase());
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline static Pointer<T> addressOf(T &value) { return Pointer<T>(&value); }
|
||||
|
||||
template<typename T>
|
||||
inline static Pointer<void> endOf(hx::ObjectPtr<T> value) { return (void *)(value.mPtr+1); }
|
||||
|
||||
template<typename T>
|
||||
inline static Pointer<T> fromPointer(T *value) { return Pointer<T>(value); }
|
||||
template<typename T>
|
||||
inline static Pointer<T> fromPointer(const T *value) { return Pointer<T>(value); }
|
||||
|
||||
template<typename T>
|
||||
inline static Pointer<T> fromRaw(T *value) { return Pointer<T>(value); }
|
||||
template<typename T>
|
||||
inline static Pointer<T> fromRaw(const T *value) { return Pointer<T>(value); }
|
||||
inline static Pointer<void> fromRaw(const AutoCast &inAutoCast) { return Pointer<void>(inAutoCast.value); }
|
||||
inline static Pointer<void> fromRaw(const RawAutoCast &inAutoCast) { return Pointer<void>(inAutoCast.value); }
|
||||
|
||||
|
||||
inline static AutoCast fromHandle(Dynamic inValue, String inKind)
|
||||
{
|
||||
if (inValue==null() || (inKind!=null() && inKind!=__hxcpp_get_kind(inValue)))
|
||||
return AutoCast(0);
|
||||
return AutoCast(inValue->__GetHandle());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Reference_obj
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // end namespace cpp
|
||||
|
||||
namespace hx
|
||||
{
|
||||
template <typename T>
|
||||
T *StarOf(T &x) { return &x; }
|
||||
}
|
||||
|
||||
|
||||
#endif
|
676
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/Variant.h
Normal file
676
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/Variant.h
Normal file
@ -0,0 +1,676 @@
|
||||
#ifndef CPP_VARIANT_TWICE_H
|
||||
|
||||
|
||||
namespace cpp
|
||||
{
|
||||
#ifndef CPP_VARIANT_ONCE_H
|
||||
#define CPP_VARIANT_ONCE_H
|
||||
|
||||
template<typename T>
|
||||
inline bool isIntType(const T &inRHS) { return false; }
|
||||
template<> inline bool isIntType(const int &inRHS) { return true; }
|
||||
template<> inline bool isIntType(const Dynamic &inRHS);
|
||||
template<> inline bool isIntType(const cpp::Variant &inRHS);
|
||||
|
||||
template<typename T>
|
||||
inline bool isStringType(const T &inRHS) { return false; }
|
||||
template<> inline bool isStringType(const String &inRHS) { return true; }
|
||||
template<> inline bool isStringType(const Dynamic &inRHS);
|
||||
template<> inline bool isStringType(const cpp::Variant &inRHS);
|
||||
|
||||
struct Variant
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
typeObject = 0,
|
||||
typeString,
|
||||
typeDouble,
|
||||
typeInt,
|
||||
typeInt64,
|
||||
typeBool,
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
// Although this is typed as 'char', it might be char16_t in the case of smart strings
|
||||
const char *valStringPtr;
|
||||
hx::Object *valObject;
|
||||
double valDouble;
|
||||
cpp::Int64 valInt64;
|
||||
int valInt;
|
||||
bool valBool;
|
||||
};
|
||||
Type type;
|
||||
unsigned int valStringLen;
|
||||
|
||||
|
||||
|
||||
inline bool isNull() const {
|
||||
return (type==typeObject && !valObject) || (type==typeString && !valStringPtr); }
|
||||
inline bool isNumeric() const;
|
||||
inline bool isBool() const;
|
||||
inline int asInt() const;
|
||||
inline bool isInt() const;
|
||||
inline cpp::Int64 asInt64() const;
|
||||
inline bool isInt64() const;
|
||||
inline bool isString() const;
|
||||
inline double asDouble() const;
|
||||
inline hx::Object *asObject() const { return type==typeObject ? valObject : 0; }
|
||||
inline hx::Object *asDynamic() const{ return type==typeObject ? valObject : toDynamic(); }
|
||||
inline hx::Object *toDynamic() const; // later
|
||||
inline String asString() const;
|
||||
inline String getString() const;
|
||||
|
||||
inline Variant() : valInt64(0), type(typeObject) { }
|
||||
//inline Variant() { copyBuf.b[0] = copyBuf.b[1] = 0; }
|
||||
inline Variant(const null &) : type(typeObject), valObject(0) { }
|
||||
inline Variant(bool inValue) : type(typeBool), valBool(inValue) { }
|
||||
inline Variant(double inValue) : type(typeDouble), valDouble(inValue) { }
|
||||
inline Variant(const ::String &inValue); // later
|
||||
|
||||
inline Variant(cpp::Int64 inValue) : type(typeInt64), valInt64(inValue) { }
|
||||
inline Variant(cpp::UInt64 inValue) : type(typeInt64), valInt64(inValue) { }
|
||||
inline Variant(int inValue) : type(typeInt), valInt(inValue) { }
|
||||
inline Variant(cpp::UInt32 inValue) : type(typeInt), valInt(inValue) { }
|
||||
inline Variant(cpp::Int16 inValue) : type(typeInt), valInt(inValue) { }
|
||||
inline Variant(cpp::UInt16 inValue) : type(typeInt), valInt(inValue) { }
|
||||
inline Variant(cpp::Int8 inValue) : type(typeInt), valInt(inValue) { }
|
||||
inline Variant(cpp::UInt8 inValue) : type(typeInt), valInt(inValue) { }
|
||||
#if defined(__OBJC__) && defined(HXCPP_OBJC)
|
||||
inline Variant(const id inObjc);
|
||||
inline operator id() const;
|
||||
#endif
|
||||
|
||||
|
||||
template<typename SOURCE_>
|
||||
Variant(const hx::ObjectPtr<SOURCE_> &inObjectPtr);
|
||||
|
||||
inline Variant(const Dynamic &inRHS); // later
|
||||
inline Variant(hx::Object *inValue) : type(typeObject), valObject(inValue) { }
|
||||
|
||||
template<typename T,typename H>
|
||||
explicit inline Variant(const cpp::Struct<T,H> &inVal);
|
||||
template<typename T>
|
||||
explicit inline Variant(const cpp::Pointer<T> &inRHS) ;
|
||||
template<typename T>
|
||||
explicit inline Variant(const cpp::Function<T> &inRHS) ;
|
||||
template<typename T>
|
||||
explicit inline Variant(const hx::Native<T> &inRHS) ;
|
||||
|
||||
//inline operator Dynamic() const; // later
|
||||
//inline operator String() const;
|
||||
inline operator double() const { return asDouble(); }
|
||||
inline operator int() const { return asInt(); }
|
||||
inline operator bool() const { return asInt(); }
|
||||
inline operator float () const { return asDouble(); }
|
||||
inline operator unsigned int () const { return asInt(); }
|
||||
inline operator short () const { return asInt(); }
|
||||
inline operator unsigned short () const { return asInt(); }
|
||||
inline operator unsigned char () const { return asInt(); }
|
||||
inline operator char () const { return asInt(); }
|
||||
inline operator signed char () const { return asInt(); }
|
||||
inline operator cpp::Int64 () const { return asInt64(); }
|
||||
inline operator cpp::UInt64 () const { return asInt64(); }
|
||||
inline bool operator !() const { return !asInt(); }
|
||||
|
||||
inline int Compare(hx::Object *inRHS) const;
|
||||
inline int Compare(const Dynamic &inRHS) const;
|
||||
inline int Compare(const cpp::Variant &inRHS) const;
|
||||
|
||||
inline double set(const double &inValue) { type=typeDouble; return valDouble=inValue; }
|
||||
inline double set(const float &inValue) { type=typeDouble; return valDouble=inValue; }
|
||||
|
||||
inline void mark(hx::MarkContext *__inCtx); // later
|
||||
#ifdef HXCPP_VISIT_ALLOCS
|
||||
inline void visit(hx::VisitContext *__inCtx); // later
|
||||
#endif
|
||||
|
||||
|
||||
//inline Variant &operator=(const Variant &inRhs) { copyBuf = inRhs.copyBuf; return *this; }
|
||||
|
||||
template<typename T>
|
||||
bool operator==(const T &inRHS) const;
|
||||
|
||||
template<typename T>
|
||||
bool operator==(const hx::ObjectPtr<T> &inRHS) const
|
||||
{ return Compare(inRHS.mPtr)==0; }
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool operator!=(const hx::ObjectPtr<T> &inRHS) const
|
||||
{ return Compare(inRHS.mPtr)!=0; }
|
||||
|
||||
|
||||
|
||||
inline bool operator==(const null &inRHS) const { return isNull(); }
|
||||
inline bool operator==(const String &inRHS) const;
|
||||
|
||||
inline bool operator!=(const null &inRHS) const { return !isNull(); }
|
||||
inline bool operator!=(const Variant &inRHS) const { return !operator==(inRHS); }
|
||||
inline bool operator!=(const String &inRHS) const;
|
||||
|
||||
|
||||
template<typename RETURN_>
|
||||
RETURN_ Cast() const { return RETURN_(*this); }
|
||||
|
||||
void CheckFPtr();
|
||||
HX_DECLARE_VARIANT_FUNCTIONS
|
||||
|
||||
|
||||
// Operator + is different, since it must consider strings too...
|
||||
inline String operator+(const String &s) const;
|
||||
template<typename T>
|
||||
inline cpp::Variant operator + (const T &inRHS) const;
|
||||
|
||||
inline double operator%(const Dynamic &inRHS) const;
|
||||
inline double operator-() const { return -asDouble(); }
|
||||
inline double operator++() { return set(asDouble()+1); }
|
||||
inline double operator++(int) {double val = asDouble(); set(val+1); return val; }
|
||||
inline double operator--() { return set(asDouble()-1); }
|
||||
inline double operator--(int) {double val = asDouble(); set(val-1); return val; }
|
||||
|
||||
template<typename T>
|
||||
inline double operator / (const T &inRHS) const { return asDouble() / (double)inRHS; } \
|
||||
|
||||
template<typename T>
|
||||
inline cpp::Variant operator - (const T &inRHS) const
|
||||
{
|
||||
if (::cpp::isIntType(inRHS) && isInt() )
|
||||
return asInt() - (int)inRHS;
|
||||
return asDouble() - (double)inRHS;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline cpp::Variant operator * (const T &inRHS) const
|
||||
{
|
||||
if (::cpp::isIntType(inRHS) && isInt())
|
||||
return asInt() * (int)inRHS;
|
||||
return asDouble() * (double)inRHS;
|
||||
}
|
||||
|
||||
inline bool operator < (const String &inRHS) const;
|
||||
inline bool operator <= (const String &inRHS) const;
|
||||
inline bool operator > (const String &inRHS) const;
|
||||
inline bool operator >= (const String &inRHS) const;
|
||||
|
||||
|
||||
|
||||
#define HX_VARIANT_COMPARE_OP( op ) \
|
||||
inline bool operator op (double inRHS) const { return isNumeric() && (asDouble() op inRHS); } \
|
||||
inline bool operator op (cpp::Int64 inRHS) const { return isNumeric() && (asInt64() op inRHS); } \
|
||||
inline bool operator op (cpp::UInt64 inRHS) const { return isNumeric() && ((cpp::UInt64)(asInt64()) op inRHS); } \
|
||||
inline bool operator op (float inRHS) const { return isNumeric() && (asDouble() op inRHS); } \
|
||||
inline bool operator op (int inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
|
||||
inline bool operator op (unsigned int inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
|
||||
inline bool operator op (short inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
|
||||
inline bool operator op (unsigned short inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
|
||||
inline bool operator op (signed char inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
|
||||
inline bool operator op (unsigned char inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
|
||||
inline bool operator op (bool inRHS) const { return isBool() && (asDouble() op (double)inRHS); } \
|
||||
inline bool operator op (const Dynamic &inRHS) const { return Compare(inRHS) op 0; } \
|
||||
|
||||
#define HX_VARIANT_COMPARE_OP_ALL( op ) \
|
||||
inline bool operator op (const null &inRHS) const { return false; } \
|
||||
inline bool operator op (const cpp::Variant &inRHS) const { return Compare(inRHS) op 0; } \
|
||||
HX_VARIANT_COMPARE_OP(op)
|
||||
|
||||
HX_VARIANT_COMPARE_OP( == )
|
||||
HX_VARIANT_COMPARE_OP( != )
|
||||
HX_VARIANT_COMPARE_OP_ALL( < )
|
||||
HX_VARIANT_COMPARE_OP_ALL( <= )
|
||||
HX_VARIANT_COMPARE_OP_ALL( >= )
|
||||
HX_VARIANT_COMPARE_OP_ALL( > )
|
||||
|
||||
|
||||
};
|
||||
|
||||
#else // Second time ...
|
||||
#define CPP_VARIANT_TWICE_H
|
||||
|
||||
bool Variant::isInt() const
|
||||
{
|
||||
return type==typeInt || (type==typeObject && valObject && valObject->__GetType()==vtInt);
|
||||
}
|
||||
bool Variant::isInt64() const
|
||||
{
|
||||
return type==typeInt64 || (type==typeObject && valObject && valObject->__GetType()==vtInt64);
|
||||
}
|
||||
bool Variant::isString() const
|
||||
{
|
||||
return type==typeString || (type==typeObject && valObject && valObject->__GetType()==vtString);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__OBJC__) && defined(HXCPP_OBJC)
|
||||
// Variant type neither adds nor releases references counts while holding the value as an id on the stack
|
||||
// The Dynamic created here owns the id, and we refer to the Dynamic and use his reference count to keep the id alive
|
||||
inline Variant::Variant(const id inObjc) { type=typeObject; valObject = Dynamic(inObjc).mPtr; }
|
||||
#ifdef OBJC_ARC
|
||||
inline Variant::operator id () const { return type==typeObject && valObject ? (__bridge id)valObject->__GetHandle() : 0; }
|
||||
#else
|
||||
inline Variant::operator id () const { return type==typeObject && valObject ? (id)valObject->__GetHandle() : 0; }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
template<> inline bool isIntType(const Dynamic &inRHS) { return inRHS->__GetType()==vtInt; }
|
||||
template<> inline bool isIntType(const cpp::Variant &inRHS) { return inRHS.isInt(); }
|
||||
template<> inline bool isStringType(const Dynamic &inRHS) { return inRHS.mPtr && inRHS->__GetType()==vtString; }
|
||||
template<> inline bool isStringType(const cpp::Variant &inRHS) { return inRHS.isString(); }
|
||||
|
||||
template<typename T,typename H>
|
||||
Variant::Variant(const cpp::Struct<T,H> &inVal) :
|
||||
type(typeObject), valObject(Dynamic(inVal).mPtr) { }
|
||||
|
||||
template<typename T>
|
||||
Variant::Variant(const cpp::Pointer<T> &inRHS) : type(typeObject), valObject( Dynamic(inRHS).mPtr ) { }
|
||||
template<typename T>
|
||||
Variant::Variant(const cpp::Function<T> &inRHS) : type(typeObject), valObject( Dynamic(inRHS).mPtr ) { }
|
||||
template<typename T>
|
||||
Variant::Variant(const hx::Native<T> &inRHS) : type(typeObject), valObject( CreateDynamicPointer(inRHS.ptr).mPtr ) { }
|
||||
|
||||
|
||||
#define HX_ARITH_VARIANT( op ) \
|
||||
inline double operator op (const double &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS;} \
|
||||
inline double operator op (const float &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS;} \
|
||||
inline double operator op (const int &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
inline double operator op (const unsigned int &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
inline double operator op (const signed char &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
inline double operator op (const unsigned char &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
inline double operator op (const signed short &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
inline double operator op (const unsigned short &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
inline double operator op (const cpp::Int64 &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
inline double operator op (const cpp::UInt64 &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
|
||||
|
||||
HX_ARITH_VARIANT( - )
|
||||
HX_ARITH_VARIANT( + )
|
||||
HX_ARITH_VARIANT( / )
|
||||
HX_ARITH_VARIANT( * )
|
||||
|
||||
inline bool Variant::operator==(const String &inString) const
|
||||
{
|
||||
if (isNull()) return inString==null();
|
||||
return type==typeString && asString()==inString;
|
||||
}
|
||||
inline bool Variant::operator!=(const String &inString) const
|
||||
{
|
||||
if (isNull()) return inString!=null();
|
||||
return type!=typeString || asString()!=inString;
|
||||
}
|
||||
inline bool Variant::operator < (const String &inRHS) const { return asString() < inRHS; }
|
||||
inline bool Variant::operator <= (const String &inRHS) const { return asString() < inRHS; }
|
||||
inline bool Variant::operator > (const String &inRHS) const { return asString() > inRHS; }
|
||||
inline bool Variant::operator >= (const String &inRHS) const { return asString() >= inRHS; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Variant::Variant(const ::String &inValue) :
|
||||
type(typeString), valStringPtr(inValue.raw_ptr()), valStringLen(inValue.length) { }
|
||||
|
||||
Variant::Variant(const Dynamic &inRHS) : type(typeObject), valObject(inRHS.mPtr) { }
|
||||
|
||||
template<typename SOURCE_>
|
||||
Variant::Variant(const hx::ObjectPtr<SOURCE_> &inObjectPtr) :
|
||||
type(typeObject), valObject(inObjectPtr.mPtr) { }
|
||||
|
||||
inline void Variant::CheckFPtr()
|
||||
{
|
||||
if (isNull()) Dynamic::ThrowBadFunctionError();
|
||||
}
|
||||
|
||||
HX_IMPLEMENT_INLINE_VARIANT_FUNCTIONS
|
||||
|
||||
|
||||
int Variant::asInt() const
|
||||
{
|
||||
if (type==typeInt)
|
||||
return valInt;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case typeDouble: return valDouble;
|
||||
case typeInt64: return (int)valInt64;
|
||||
case typeBool: return valBool;
|
||||
case typeObject: return valObject ? valObject->__ToInt() : 0;
|
||||
default: ;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cpp::Int64 Variant::asInt64() const
|
||||
{
|
||||
if (type==typeInt64)
|
||||
return valInt64;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case typeDouble: return valDouble;
|
||||
case typeInt: return valInt;
|
||||
case typeBool: return valBool;
|
||||
case typeObject: return valObject ? valObject->__ToInt64() : 0;
|
||||
default: ;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Variant::asDouble() const
|
||||
{
|
||||
if (type==typeDouble)
|
||||
return valDouble;
|
||||
else if (type==typeInt)
|
||||
return valInt;
|
||||
else if (type==typeBool)
|
||||
return valBool ? 1.0 : 0.0;
|
||||
else if (type==typeInt64)
|
||||
return valInt64;
|
||||
else if (type==typeObject)
|
||||
return valObject ? valObject->__ToDouble() : 0.0;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
inline hx::Object *Variant::toDynamic() const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case typeInt: return Dynamic(valInt).mPtr;
|
||||
case typeDouble: return Dynamic(valDouble).mPtr;
|
||||
case typeBool: return Dynamic(valBool).mPtr;
|
||||
case typeString: return Dynamic(String(valStringPtr, valStringLen)).mPtr;
|
||||
case typeInt64: return Dynamic(valInt64).mPtr;
|
||||
case typeObject: return valObject;
|
||||
default: ;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Variant::operator Dynamic() const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case typeInt: return valInt;
|
||||
case typeDouble: return valDouble;
|
||||
case typeBool: return valBool;
|
||||
case typeString: return String(valStringPtr, valStringLen);
|
||||
case typeObject: return valObject;
|
||||
default: ;
|
||||
}
|
||||
return null();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
bool Variant::isNumeric() const
|
||||
{
|
||||
if (type==typeInt || type==typeDouble || type==typeInt64)
|
||||
return true;
|
||||
if (type!=typeObject || valObject==0)
|
||||
return false;
|
||||
|
||||
int t = valObject->__GetType();
|
||||
return t==vtInt || t==vtFloat;
|
||||
}
|
||||
|
||||
bool Variant::isBool() const
|
||||
{
|
||||
if (type==typeBool)
|
||||
return true;
|
||||
if (type!=typeObject || valObject==0)
|
||||
return false;
|
||||
|
||||
return valObject->__GetType() == vtBool;
|
||||
}
|
||||
|
||||
|
||||
String Variant::getString() const { return String(valStringPtr, valStringLen); }
|
||||
String Variant::asString() const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case typeInt: return String(valInt);
|
||||
case typeDouble: return String(valDouble);
|
||||
case typeBool: return String(valBool);
|
||||
case typeString: return String(valStringPtr, valStringLen);
|
||||
case typeInt64: return String(valInt64);
|
||||
case typeObject: return valObject ? valObject->toString() : String();
|
||||
default: ;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
//Variant::operator String() const { return asString(); }
|
||||
|
||||
|
||||
void Variant::mark(hx::MarkContext *__inCtx)
|
||||
{
|
||||
if (type==typeString)
|
||||
{
|
||||
HX_MARK_STRING(valStringPtr);
|
||||
}
|
||||
else if (type==typeObject)
|
||||
{
|
||||
HX_MARK_OBJECT(valObject);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Variant::operator==(const T &inRHS) const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case typeInt: return valInt==(double)inRHS;
|
||||
case typeDouble:return valDouble==(double)inRHS;
|
||||
case typeBool: return valBool==(bool)inRHS;
|
||||
case typeInt64: return valInt64==(cpp::Int64)inRHS;
|
||||
case typeString: return getString()==String(inRHS);
|
||||
case typeObject:
|
||||
if (!valObject)
|
||||
return inRHS == null();
|
||||
return valObject->__Compare( Dynamic(inRHS).mPtr )==0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int Variant::Compare(hx::Object *inPtr) const
|
||||
{
|
||||
if (!inPtr)
|
||||
return isNull() ? 0 : 1;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case typeInt:
|
||||
{
|
||||
double diff = valInt - inPtr->__ToDouble();
|
||||
return diff<0 ? -1 : diff==0 ? 0 : 1;
|
||||
}
|
||||
case typeDouble:
|
||||
{
|
||||
double diff = valDouble - inPtr->__ToDouble();
|
||||
return diff<0 ? -1 : diff==0 ? 0 : 1;
|
||||
}
|
||||
case typeInt64:
|
||||
{
|
||||
cpp::Int64 diff = valInt64 - inPtr->__ToInt64();
|
||||
return diff<0 ? -1 : diff==0 ? 0 : 1;
|
||||
}
|
||||
case typeBool:
|
||||
if (!inPtr) return 1;
|
||||
return valBool==(bool)(inPtr->__ToInt()) ? 1 : 0;
|
||||
case typeString:
|
||||
if (!inPtr) return valStringPtr ? 1 : 0;
|
||||
if (inPtr->__GetType()!=vtString)
|
||||
return 1;
|
||||
return String(valStringPtr, valStringLen)==inPtr->toString() ? 1 : 0;
|
||||
case typeObject:
|
||||
#if (HXCPP_API_LEVEL>=331)
|
||||
return valObject->__Compare( inPtr );
|
||||
#else
|
||||
return valObject->__Compare( inPtr->__GetRealObject() );
|
||||
#endif
|
||||
default: ;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int Variant::Compare(const Dynamic &inD) const { return Compare(inD.mPtr); }
|
||||
int Variant::Compare(const cpp::Variant &inVar) const
|
||||
{
|
||||
if (inVar.type==typeObject)
|
||||
return Compare(inVar.valObject);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case typeInt:
|
||||
{
|
||||
double diff = valInt - inVar.asDouble();
|
||||
return diff<0 ? -1 : diff==0 ? 0 : 1;
|
||||
}
|
||||
case typeDouble:
|
||||
{
|
||||
double diff = valDouble - inVar.asDouble();
|
||||
return diff<0 ? -1 : diff==0 ? 0 : 1;
|
||||
}
|
||||
case typeInt64:
|
||||
{
|
||||
cpp::Int64 diff = valInt64 - inVar.asInt64();
|
||||
return diff<0 ? -1 : diff==0 ? 0 : 1;
|
||||
}
|
||||
case typeBool:
|
||||
return valBool==(bool)(inVar.asInt()) ? 1 : 0;
|
||||
case typeString:
|
||||
if (inVar.type!=typeString)
|
||||
return 1;
|
||||
return String(valStringPtr, valStringLen)==inVar.asString();
|
||||
case typeObject:
|
||||
if (!valObject)
|
||||
return 1;
|
||||
return - inVar.Compare(*this);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
String cpp::Variant::operator+(const String &s) const
|
||||
{
|
||||
return asString() + s;
|
||||
}
|
||||
template<typename T>
|
||||
cpp::Variant Variant::operator + (const T &inRHS) const
|
||||
{
|
||||
if (isString() || ::cpp::isStringType(inRHS))
|
||||
return asString() + String(inRHS);
|
||||
return asDouble() + (double)inRHS;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HXCPP_VISIT_ALLOCS
|
||||
void Variant::visit(hx::VisitContext *__inCtx)
|
||||
{
|
||||
if (type==typeString)
|
||||
{
|
||||
HX_VISIT_STRING(valStringPtr);
|
||||
}
|
||||
else if (type==typeObject)
|
||||
{
|
||||
HX_VISIT_OBJECT(valObject);
|
||||
}
|
||||
}
|
||||
#endif // HXCPP_VISIT_ALLOCS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define HX_VARIANT_OP_ISEQ(T) \
|
||||
inline bool operator == (const T &inLHS,const cpp::Variant &inRHS) { return inRHS==inLHS; } \
|
||||
inline bool operator != (const T &inLHS,const cpp::Variant &inRHS) { return inRHS!=inLHS; }
|
||||
|
||||
|
||||
#define HX_VARIANT_OP_ISEQ(T) \
|
||||
inline bool operator == (const T &inLHS,const cpp::Variant &inRHS) { return inRHS==inLHS; } \
|
||||
inline bool operator != (const T &inLHS,const cpp::Variant &inRHS) { return inRHS!=inLHS; }
|
||||
|
||||
HX_VARIANT_OP_ISEQ(String)
|
||||
HX_VARIANT_OP_ISEQ(double)
|
||||
HX_VARIANT_OP_ISEQ(float)
|
||||
HX_VARIANT_OP_ISEQ(cpp::Int64)
|
||||
HX_VARIANT_OP_ISEQ(cpp::UInt64)
|
||||
HX_VARIANT_OP_ISEQ(int)
|
||||
HX_VARIANT_OP_ISEQ(unsigned int)
|
||||
HX_VARIANT_OP_ISEQ(short)
|
||||
HX_VARIANT_OP_ISEQ(unsigned short)
|
||||
HX_VARIANT_OP_ISEQ(signed char)
|
||||
HX_VARIANT_OP_ISEQ(unsigned char)
|
||||
HX_VARIANT_OP_ISEQ(bool)
|
||||
|
||||
inline bool operator < (bool inLHS,const cpp::Variant &inRHS) { return false; }
|
||||
inline bool operator <= (bool inLHS,const cpp::Variant &inRHS) { return false; }
|
||||
inline bool operator >= (bool inLHS,const cpp::Variant &inRHS) { return false; }
|
||||
inline bool operator > (bool inLHS,const cpp::Variant &inRHS) { return false; }
|
||||
|
||||
|
||||
#define HX_COMPARE_VARIANT_OP( op ) \
|
||||
inline bool operator op (double inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (float inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && ((double)inLHS op (double)inRHS); } \
|
||||
inline bool operator op (cpp::Int64 inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (cpp::UInt64 inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (int inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (unsigned int inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (short inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (unsigned short inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (signed char inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (unsigned char inLHS,const ::cpp::Variant &inRHS) \
|
||||
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
|
||||
inline bool operator op (const null &,const ::cpp::Variant &inRHS) \
|
||||
{ return false; } \
|
||||
|
||||
HX_COMPARE_VARIANT_OP( < )
|
||||
HX_COMPARE_VARIANT_OP( <= )
|
||||
HX_COMPARE_VARIANT_OP( >= )
|
||||
HX_COMPARE_VARIANT_OP( > )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // close cpp
|
||||
namespace hx {
|
||||
template<typename T>
|
||||
bool ObjectPtr<T>::operator==(const cpp::Variant &inRHS) const {
|
||||
return inRHS.Compare(mPtr)==0;
|
||||
}
|
||||
template<typename T>
|
||||
bool ObjectPtr<T>::operator!=(const cpp::Variant &inRHS) const {
|
||||
return inRHS.Compare(mPtr)!=0;
|
||||
}
|
||||
|
||||
} // close hx
|
||||
namespace cpp {
|
||||
|
||||
#endif // not twice
|
||||
|
||||
|
||||
|
||||
} // end namespace cpp
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CPP_VARIANT_TWICE_H
|
727
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/VirtualArray.h
Normal file
727
Kha/Backends/Kinc-hxcpp/khacpp/include/cpp/VirtualArray.h
Normal file
@ -0,0 +1,727 @@
|
||||
namespace cpp
|
||||
{
|
||||
|
||||
// This file is included twice - either side of the Array definition
|
||||
#ifndef HX_VARRAY_DEFINED
|
||||
#define HX_VARRAY_DEFINED
|
||||
|
||||
|
||||
class VirtualArray : public hx::ObjectPtr<VirtualArray_obj>
|
||||
{
|
||||
typedef hx::ObjectPtr<VirtualArray_obj> super;
|
||||
public:
|
||||
typedef Dynamic Elem;
|
||||
|
||||
inline VirtualArray() : super(0) { }
|
||||
inline VirtualArray(VirtualArray_obj *inObj) : super(inObj) { }
|
||||
inline VirtualArray(const null &inNull) : super(0) { }
|
||||
inline VirtualArray(const VirtualArray &inOther) : super( inOther.mPtr ) { }
|
||||
|
||||
// Build from foreign array
|
||||
template<typename SOURCE_> inline VirtualArray( const Array<SOURCE_> &inRHS );
|
||||
|
||||
|
||||
inline VirtualArray( const Dynamic &inRHS ) : super(0) { setDynamic(inRHS); }
|
||||
inline VirtualArray( const cpp::ArrayBase &inRHS ) : super(0) { setDynamic(inRHS); }
|
||||
inline VirtualArray(const ::cpp::Variant &inVariant) { setDynamic(inVariant.asObject()); }
|
||||
|
||||
|
||||
|
||||
|
||||
inline VirtualArray &operator=(const null &inNull) { mPtr = 0; return *this; }
|
||||
inline VirtualArray &operator=(Ptr inRHS) { mPtr = inRHS; return *this; }
|
||||
inline VirtualArray &operator=(const VirtualArray &inRHS) { mPtr = inRHS.mPtr; return *this; }
|
||||
|
||||
inline void setDynamic( const Dynamic &inRHS );
|
||||
|
||||
template<typename T>
|
||||
inline VirtualArray Add(const T &inVal);
|
||||
|
||||
|
||||
inline bool operator==(const Dynamic &value) const { return value==*this; }
|
||||
template<typename SOURCE_> inline bool operator==( const Array<SOURCE_> &inRHS );
|
||||
|
||||
inline bool operator!=(Dynamic value) const { return value!=*this; }
|
||||
template<typename SOURCE_> inline bool operator!=( const Array<SOURCE_> &inRHS ) { return inRHS!=*this; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class HXCPP_EXTERN_CLASS_ATTRIBUTES VirtualArray_obj : public hx::ArrayCommon
|
||||
{
|
||||
typedef hx::ArrayStore ArrayStore;
|
||||
typedef hx::ArrayBase ArrayBase;
|
||||
|
||||
public:
|
||||
HX_IS_INSTANCE_OF enum { _hx_ClassId = hx::clsIdVirtualArray };
|
||||
|
||||
typedef hx::Object super;
|
||||
ArrayStore store;
|
||||
ArrayBase *base;
|
||||
|
||||
VirtualArray_obj(ArrayBase *inBase=0, bool inFixed=false) : base(inBase)
|
||||
{
|
||||
mArrayConvertId = hx::aciVirtualArray;
|
||||
store = inFixed && inBase ? hx::arrayFixed : base ? base->getStoreType() : hx::arrayEmpty;
|
||||
#ifdef HXCPP_GC_GENERATIONAL
|
||||
if (base)
|
||||
HX_OBJ_WB_GET(this,base);
|
||||
#endif
|
||||
}
|
||||
|
||||
VirtualArray_obj(ArrayStore inStore)
|
||||
{
|
||||
mArrayConvertId = hx::aciVirtualArray;
|
||||
store = inStore;
|
||||
}
|
||||
|
||||
hx::Object *__GetRealObject() { return base?(hx::Object *)base:(hx::Object *)this; }
|
||||
|
||||
inline static VirtualArray __new(int inSize=0,int inReserve=0)
|
||||
{
|
||||
VirtualArray result = new VirtualArray_obj(hx::arrayEmpty);
|
||||
if (inSize>0)
|
||||
result->__SetSizeExact(inSize);
|
||||
if (inReserve>0)
|
||||
result->reserve(inReserve);
|
||||
return result;
|
||||
}
|
||||
|
||||
#if (HXCPP_API_LEVEL>330)
|
||||
int __Compare(const hx::Object *inRHS) const;
|
||||
#endif
|
||||
|
||||
|
||||
inline int get_length() const
|
||||
{
|
||||
return base ? base->length : 0;
|
||||
}
|
||||
|
||||
inline void checkBase() const
|
||||
{
|
||||
#ifdef HXCPP_CHECK_POINTER
|
||||
if (store==hx::arrayNull)
|
||||
{
|
||||
hx::NullReference("Array", true);
|
||||
// The handler might have fixed up the null value
|
||||
if (store==hx::arrayNull) hx::NullReference("Array", false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void EnsureStorage(const Dynamic &inValue)
|
||||
{
|
||||
if (!inValue.mPtr)
|
||||
{
|
||||
EnsureNullStorage();
|
||||
}
|
||||
else switch(inValue->__GetType())
|
||||
{
|
||||
case vtBool: EnsureBoolStorage(); break;
|
||||
case vtInt: EnsureIntStorage(); break;
|
||||
case vtFloat: EnsureFloatStorage(); break;
|
||||
case vtString: EnsureStringStorage(); break;
|
||||
case vtInt64: EnsureInt64Storage(); break;
|
||||
default: EnsureObjectStorage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EnsureStorage(const cpp::Variant &inValue)
|
||||
{
|
||||
switch(inValue.type)
|
||||
{
|
||||
case Variant::typeObject:
|
||||
if (!inValue.valObject)
|
||||
EnsureNullStorage();
|
||||
else
|
||||
EnsureObjectStorage();
|
||||
break;
|
||||
case Variant::typeString: EnsureStringStorage(); break;
|
||||
case Variant::typeDouble: EnsureFloatStorage(); break;
|
||||
case Variant::typeInt: EnsureIntStorage(); break;
|
||||
case Variant::typeBool: EnsureBoolStorage(); break;
|
||||
case Variant::typeInt64: EnsureInt64Storage(); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MakeIntArray();
|
||||
void MakeInt64Array();
|
||||
void MakeObjectArray();
|
||||
void MakeFloatArray();
|
||||
void MakeBoolArray();
|
||||
void MakeStringArray();
|
||||
|
||||
void EnsureStorage(const VirtualArray &inValue) { EnsureObjectStorage(); }
|
||||
void EnsureStorage(const unsigned char &inValue) { EnsureIntStorage(); }
|
||||
void EnsureStorage(const bool &inValue) { EnsureBoolStorage(); }
|
||||
void EnsureStorage(const String &inValue) { EnsureStringStorage(); }
|
||||
void EnsureStorage(const double &inValue) { EnsureFloatStorage(); }
|
||||
void EnsureStorage(const float &inValue) { EnsureFloatStorage(); }
|
||||
void EnsureStorage(const int &inValue) { EnsureIntStorage(); }
|
||||
void EnsureStorage(const cpp::Int64 &inValue) { EnsureInt64Storage(); }
|
||||
void EnsureStorage(const cpp::UInt64 &inValue) { EnsureInt64Storage(); }
|
||||
void EnsureStorage(const null &inValue) { EnsureNullStorage(); }
|
||||
template<typename T>
|
||||
void EnsureStorage(const T &inValue) { EnsureObjectStorage(); }
|
||||
|
||||
inline void EnsureBoolStorage()
|
||||
{
|
||||
switch(store)
|
||||
{
|
||||
case hx::arrayNull:
|
||||
case hx::arrayObject:
|
||||
case hx::arrayFixed:
|
||||
case hx::arrayBool:
|
||||
return;
|
||||
case hx::arrayEmpty:
|
||||
MakeBoolArray();
|
||||
break;
|
||||
case hx::arrayInt:
|
||||
case hx::arrayInt64:
|
||||
case hx::arrayFloat:
|
||||
case hx::arrayString:
|
||||
MakeObjectArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
inline void EnsureStringStorage()
|
||||
{
|
||||
switch(store)
|
||||
{
|
||||
case hx::arrayNull:
|
||||
case hx::arrayObject:
|
||||
case hx::arrayFixed:
|
||||
case hx::arrayString:
|
||||
return;
|
||||
case hx::arrayEmpty:
|
||||
MakeStringArray();
|
||||
break;
|
||||
case hx::arrayInt:
|
||||
case hx::arrayInt64:
|
||||
case hx::arrayFloat:
|
||||
case hx::arrayBool:
|
||||
MakeObjectArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
inline void EnsureFloatStorage()
|
||||
{
|
||||
switch(store)
|
||||
{
|
||||
case hx::arrayNull:
|
||||
case hx::arrayFloat:
|
||||
case hx::arrayObject:
|
||||
case hx::arrayFixed:
|
||||
return;
|
||||
case hx::arrayInt:
|
||||
case hx::arrayInt64:
|
||||
case hx::arrayEmpty:
|
||||
MakeFloatArray();
|
||||
break;
|
||||
case hx::arrayBool:
|
||||
case hx::arrayString:
|
||||
MakeObjectArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void EnsureIntStorage()
|
||||
{
|
||||
switch(store)
|
||||
{
|
||||
case hx::arrayNull:
|
||||
case hx::arrayInt:
|
||||
case hx::arrayInt64:
|
||||
case hx::arrayFloat:
|
||||
case hx::arrayObject:
|
||||
case hx::arrayFixed:
|
||||
return;
|
||||
case hx::arrayEmpty:
|
||||
MakeIntArray();
|
||||
break;
|
||||
case hx::arrayBool:
|
||||
case hx::arrayString:
|
||||
MakeObjectArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void EnsureInt64Storage()
|
||||
{
|
||||
switch(store)
|
||||
{
|
||||
case hx::arrayNull:
|
||||
case hx::arrayInt64:
|
||||
case hx::arrayFloat:
|
||||
case hx::arrayObject:
|
||||
case hx::arrayFixed:
|
||||
return;
|
||||
case hx::arrayInt:
|
||||
case hx::arrayEmpty:
|
||||
MakeInt64Array();
|
||||
break;
|
||||
case hx::arrayBool:
|
||||
case hx::arrayString:
|
||||
MakeObjectArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void EnsureObjectStorage()
|
||||
{
|
||||
switch(store)
|
||||
{
|
||||
case hx::arrayNull:
|
||||
case hx::arrayObject:
|
||||
case hx::arrayFixed:
|
||||
return;
|
||||
case hx::arrayEmpty:
|
||||
case hx::arrayInt:
|
||||
case hx::arrayInt64:
|
||||
case hx::arrayFloat:
|
||||
case hx::arrayBool:
|
||||
case hx::arrayString:
|
||||
MakeObjectArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
inline void EnsureNullStorage()
|
||||
{
|
||||
switch(store)
|
||||
{
|
||||
case hx::arrayNull:
|
||||
case hx::arrayObject:
|
||||
case hx::arrayFixed:
|
||||
case hx::arrayString:
|
||||
return;
|
||||
case hx::arrayEmpty:
|
||||
case hx::arrayInt:
|
||||
case hx::arrayInt64:
|
||||
case hx::arrayFloat:
|
||||
case hx::arrayBool:
|
||||
MakeObjectArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename F> void fixType();
|
||||
template<typename F> F castArray();
|
||||
|
||||
void EnsureBase();
|
||||
void CreateEmptyArray(int inLen);
|
||||
|
||||
void EnsureArrayStorage(ArrayStore inValue);
|
||||
void EnsureArrayStorage(VirtualArray inValue);
|
||||
|
||||
void __Mark(hx::MarkContext *__inCtx)
|
||||
{
|
||||
HX_MARK_OBJECT(base);
|
||||
}
|
||||
#ifdef HXCPP_VISIT_ALLOCS
|
||||
void __Visit(hx::VisitContext *__inCtx)
|
||||
{
|
||||
if (base)
|
||||
__inCtx->visitObject( (hx::Object **)&base);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Used by cpp.ArrayBase
|
||||
inline int getElementSize() const { return base ? base->GetElementSize() : 0; }
|
||||
inline int getByteCount() const { return base ? base->getByteCount() : 0; }
|
||||
inline char * getBase() const { return base ? base->GetBase() : 0; }
|
||||
hx::Val __SetField(const String &inString,const hx::Val &inValue ,hx::PropertyAccess inCallProp) { return null(); }
|
||||
|
||||
static hx::Class &__SGetClass() { return hx::ArrayBase::__mClass; }
|
||||
hx::Class __GetClass() const;
|
||||
String toString();
|
||||
String __ToString() const { return const_cast<VirtualArray_obj *>(this)->toString(); }
|
||||
|
||||
void setData(void *inData, int inElements) { EnsureBase(); base->setData(inData, inElements); }
|
||||
void setUnmanagedData(void *inData, int inElements) { EnsureBase(); base->setUnmanagedData(inData, inElements); }
|
||||
|
||||
int __GetType() const { return vtArray; }
|
||||
|
||||
inline size_t size() const { checkBase(); return store==hx::arrayEmpty ? 0 : base->length; }
|
||||
inline int __length() const { checkBase(); return store==hx::arrayEmpty ? 0 : (int)base->length; }
|
||||
|
||||
String ItemString(int inI) { checkBase(); return store==hx::arrayEmpty ? null() : base->ItemString(inI); }
|
||||
|
||||
const char * __CStr() const { return store==hx::arrayEmpty ? "[]" : store==hx::arrayNull ? "null" : base->__CStr(); }
|
||||
inline const char *GetBase() const { return base ? base->GetBase() : 0; }
|
||||
inline char *GetBase() { return base ? base->GetBase() : 0; }
|
||||
|
||||
int GetElementSize() const { checkBase(); return store==hx::arrayEmpty ? 0 : base->GetElementSize(); }
|
||||
|
||||
inline void reserve(int inSize) const
|
||||
{
|
||||
if (base)
|
||||
base->reserve(inSize);
|
||||
}
|
||||
|
||||
inline int capacity()
|
||||
{
|
||||
if (base)
|
||||
return base->capacity();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void resize(int inLen)
|
||||
{
|
||||
if (!base)
|
||||
CreateEmptyArray(inLen);
|
||||
else
|
||||
base->resize(inLen);
|
||||
}
|
||||
void __SetSize(int inLen) { resize(inLen); }
|
||||
|
||||
VirtualArray __SetSizeExact(int inLen=0)
|
||||
{
|
||||
if (!base && inLen)
|
||||
CreateEmptyArray(inLen);
|
||||
else if (base)
|
||||
base->__SetSizeExact(inLen);
|
||||
return this;
|
||||
}
|
||||
|
||||
void safeSort(Dynamic sorter, bool isString) { checkBase(); if (store!=hx::arrayEmpty) base->safeSort(sorter,isString); }
|
||||
|
||||
inline void __unsafeStringReference(String inString) { if (base) base->__unsafeStringReference(inString); }
|
||||
|
||||
|
||||
Dynamic __GetItem(int inIndex) const;
|
||||
Dynamic __SetItem(int inIndex,Dynamic inValue);
|
||||
hx::Val __Field(const String &inString, hx::PropertyAccess inCallProp);
|
||||
|
||||
template<typename T>
|
||||
inline const T &set(int inIdx, const T &inVal)
|
||||
{
|
||||
if (store!=hx::arrayFixed)
|
||||
{
|
||||
if (inIdx>(store==hx::arrayEmpty ? 0 : (int)base->length) )
|
||||
EnsureObjectStorage();
|
||||
else
|
||||
EnsureStorage(inVal);
|
||||
}
|
||||
base->set(inIdx, inVal);
|
||||
return inVal;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline int push(const T &inVal)
|
||||
{
|
||||
if (store!=hx::arrayFixed) EnsureStorage(inVal);
|
||||
return base->__push(Dynamic(inVal));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline VirtualArray_obj *Add(const T &inVal)
|
||||
{
|
||||
if (store!=hx::arrayFixed) EnsureStorage(inVal);
|
||||
base->__push(Dynamic(inVal));
|
||||
return this;
|
||||
}
|
||||
|
||||
inline Dynamic pop() { checkBase(); return store==hx::arrayEmpty ? null() : base->__pop(); }
|
||||
|
||||
inline bool contains(Dynamic inValue)
|
||||
{
|
||||
checkBase();
|
||||
if (store==hx::arrayEmpty)
|
||||
return false;
|
||||
EnsureStorage(inValue);
|
||||
return base->__contains(inValue);
|
||||
}
|
||||
|
||||
inline bool remove(Dynamic inValue)
|
||||
{
|
||||
checkBase();
|
||||
if (store==hx::arrayEmpty)
|
||||
return false;
|
||||
EnsureStorage(inValue);
|
||||
return base->__remove(inValue);
|
||||
}
|
||||
|
||||
inline bool removeAt(int inIndex) { checkBase(); return (store!=hx::arrayEmpty) && base->__removeAt(inIndex); }
|
||||
|
||||
int indexOf(Dynamic inValue, Dynamic fromIndex = null())
|
||||
{
|
||||
checkBase();
|
||||
if (store==hx::arrayEmpty)
|
||||
return -1;
|
||||
EnsureStorage(inValue);
|
||||
return (int)base->__indexOf(inValue,fromIndex);
|
||||
}
|
||||
int lastIndexOf(Dynamic inValue, Dynamic fromIndex = null())
|
||||
{
|
||||
checkBase();
|
||||
if (store==hx::arrayEmpty)
|
||||
return -1;
|
||||
EnsureStorage(inValue);
|
||||
return (int)base->__lastIndexOf(inValue,fromIndex);
|
||||
}
|
||||
|
||||
Dynamic shift() { checkBase(); return store==hx::arrayEmpty ? null() : base->__shift(); }
|
||||
|
||||
VirtualArray concat( VirtualArray inTail )
|
||||
{
|
||||
inTail->checkBase();
|
||||
EnsureArrayStorage(inTail);
|
||||
if (inTail->__length()<1)
|
||||
return copy();
|
||||
return new VirtualArray_obj( base->__concat(inTail), store==hx::arrayFixed );
|
||||
}
|
||||
VirtualArray copy( )
|
||||
{
|
||||
checkBase();
|
||||
if (store==hx::arrayEmpty)
|
||||
return new VirtualArray_obj(hx::arrayEmpty);
|
||||
|
||||
return new VirtualArray_obj(base->__copy(), store==hx::arrayFixed);
|
||||
}
|
||||
VirtualArray slice(int inPos, Dynamic end = null())
|
||||
{
|
||||
checkBase();
|
||||
if (store==hx::arrayEmpty)
|
||||
return new VirtualArray_obj(hx::arrayEmpty);
|
||||
return new VirtualArray_obj(base->__slice(inPos,end), store==hx::arrayFixed);
|
||||
}
|
||||
VirtualArray splice(int inPos, int len);
|
||||
VirtualArray map(Dynamic inFunc);
|
||||
VirtualArray filter(Dynamic inFunc);
|
||||
|
||||
template<typename T>
|
||||
inline VirtualArray init(int inIndex, const T &inVal)
|
||||
{
|
||||
if (store!=hx::arrayFixed) EnsureStorage(inVal);
|
||||
__SetItem(inIndex,inVal);
|
||||
return this;
|
||||
}
|
||||
|
||||
inline Dynamic __unsafe_set(int inIndex, const Dynamic &val) { return __SetItem(inIndex,val); }
|
||||
inline Dynamic __unsafe_get(int inIndex) { return __GetItem(inIndex); }
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline void insert(int inPos, const T &inValue)
|
||||
{
|
||||
if (store!=hx::arrayFixed)
|
||||
{
|
||||
if (inPos>(store==hx::arrayEmpty ? 0 : (int)base->length) )
|
||||
EnsureObjectStorage();
|
||||
else
|
||||
EnsureStorage(inValue);
|
||||
}
|
||||
|
||||
base->__insert(inPos,inValue);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void unshift(const T& inValue)
|
||||
{
|
||||
if (store!=hx::arrayFixed) EnsureStorage(inValue);
|
||||
base->__unshift(inValue);
|
||||
}
|
||||
|
||||
inline void reverse() { checkBase(); if (store!=hx::arrayEmpty) base->__reverse(); }
|
||||
|
||||
inline void qsort(Dynamic inSorter) { checkBase(); if (base) base->__qsort(inSorter); }
|
||||
|
||||
inline void sort(Dynamic inSorter) { checkBase(); if (base) base->__sort(inSorter); }
|
||||
|
||||
Dynamic iterator() { checkBase(); return !base ? getEmptyIterator() : base->__iterator(); }
|
||||
static Dynamic getEmptyIterator();
|
||||
|
||||
Dynamic keyValueIterator() { checkBase(); return !base ? getEmptyIterator() : base->__keyValueIterator(); }
|
||||
|
||||
bool IsByteArray() const { checkBase(); return store!=hx::arrayEmpty && base->IsByteArray(); }
|
||||
|
||||
void zero(Dynamic inFirst, Dynamic inCount) { checkBase(); if (store!=hx::arrayEmpty) base->zero(inFirst,inCount); }
|
||||
|
||||
inline int memcmp(VirtualArray inOther)
|
||||
{
|
||||
checkBase();
|
||||
if (store==hx::arrayEmpty)
|
||||
return inOther->__length() == 0;
|
||||
return base->__memcmp(inOther);
|
||||
}
|
||||
inline void blit(int inDestElement, cpp::VirtualArray inSourceArray, int inSourceElement, int inElementCount)
|
||||
{
|
||||
inSourceArray->checkBase();
|
||||
EnsureArrayStorage(inSourceArray);
|
||||
if (base)
|
||||
base->__blit(inDestElement, inSourceArray, inSourceElement, inElementCount);
|
||||
}
|
||||
|
||||
String join(String inSeparator) { checkBase(); if (!base) return HX_CSTRING(""); return base->__join(inSeparator); }
|
||||
|
||||
|
||||
Dynamic __get(int inIndex) const { checkBase(); if (store==hx::arrayEmpty) return null(); return base->__GetItem(inIndex); }
|
||||
|
||||
Dynamic concat_dyn();
|
||||
Dynamic copy_dyn();
|
||||
Dynamic insert_dyn();
|
||||
Dynamic iterator_dyn();
|
||||
Dynamic keyValueIterator_dyn();
|
||||
Dynamic join_dyn();
|
||||
Dynamic pop_dyn();
|
||||
Dynamic push_dyn();
|
||||
Dynamic contains_dyn();
|
||||
Dynamic remove_dyn();
|
||||
Dynamic removeAt_dyn();
|
||||
Dynamic indexOf_dyn();
|
||||
Dynamic lastIndexOf_dyn();
|
||||
Dynamic reverse_dyn();
|
||||
Dynamic shift_dyn();
|
||||
Dynamic slice_dyn();
|
||||
Dynamic splice_dyn();
|
||||
Dynamic sort_dyn();
|
||||
Dynamic toString_dyn();
|
||||
Dynamic unshift_dyn();
|
||||
Dynamic map_dyn();
|
||||
Dynamic filter_dyn();
|
||||
Dynamic __SetSize_dyn();
|
||||
Dynamic __SetSizeExact_dyn();
|
||||
Dynamic __unsafe_get_dyn();
|
||||
Dynamic __unsafe_set_dyn();
|
||||
Dynamic blit_dyn();
|
||||
Dynamic zero_dyn();
|
||||
Dynamic memcmp_dyn();
|
||||
Dynamic resize_dyn();
|
||||
};
|
||||
|
||||
|
||||
//typedef hx::ObjectPtr< VirtualArray_obj > VirtualArray;
|
||||
|
||||
|
||||
|
||||
#else // !HX_VARRAY_DEFINED
|
||||
|
||||
|
||||
// Build dynamic array from foreign array
|
||||
template<typename SOURCE_>
|
||||
VirtualArray::VirtualArray( const Array<SOURCE_> &inRHS )
|
||||
: super( !inRHS.mPtr ? 0 : new VirtualArray_obj( inRHS.mPtr, true) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline VirtualArray VirtualArray::Add(const T &inVal)
|
||||
{
|
||||
mPtr->push(inVal);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline void VirtualArray::setDynamic( const Dynamic &inRHS )
|
||||
{
|
||||
hx::Object *ptr = inRHS.GetPtr();
|
||||
if (ptr)
|
||||
{
|
||||
if (ptr->__GetClass().mPtr == super::__SGetClass().mPtr )
|
||||
{
|
||||
cpp::VirtualArray_obj *varray = dynamic_cast<cpp::VirtualArray_obj *>(ptr);
|
||||
if (varray)
|
||||
mPtr = varray;
|
||||
else
|
||||
mPtr = new VirtualArray_obj(dynamic_cast<cpp::ArrayBase_obj *>(ptr), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename F>
|
||||
void VirtualArray_obj::fixType()
|
||||
{
|
||||
if (store==hx::arrayFixed)
|
||||
return;
|
||||
|
||||
store = hx::arrayFixed;
|
||||
if (base && base->length>0)
|
||||
{
|
||||
Array<F> fixedArray = Dynamic(base);
|
||||
base = fixedArray.mPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
base = new Array_obj<F>(0,0);
|
||||
}
|
||||
#ifdef HXCPP_GC_GENERATIONAL
|
||||
if (base)
|
||||
HX_OBJ_WB_GET(this,base);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename ARRAY >
|
||||
ARRAY VirtualArray_obj::castArray()
|
||||
{
|
||||
if (store==hx::arrayFixed)
|
||||
return Dynamic(base);
|
||||
|
||||
store = hx::arrayFixed;
|
||||
if (base && base->length>0)
|
||||
{
|
||||
ARRAY fixedArray = Dynamic(base);
|
||||
base = fixedArray.mPtr;
|
||||
#ifdef HXCPP_GC_GENERATIONAL
|
||||
if (base)
|
||||
HX_OBJ_WB_GET(this,base);
|
||||
#endif
|
||||
return fixedArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARRAY fixedArray(0,0);
|
||||
base = fixedArray.mPtr;
|
||||
#ifdef HXCPP_GC_GENERATIONAL
|
||||
if (base)
|
||||
HX_OBJ_WB_GET(this,base);
|
||||
#endif
|
||||
return fixedArray;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename SOURCE_>
|
||||
inline bool VirtualArray::operator==( const Array<SOURCE_> &inRHS )
|
||||
{
|
||||
if (!mPtr)
|
||||
return inRHS.mPtr;
|
||||
return mPtr->castArray< Array<SOURCE_> >() == inRHS;
|
||||
}
|
||||
|
||||
} // end namespace cpp
|
||||
|
||||
HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic _hx_reslove_virtual_array(cpp::VirtualArray inArray);
|
||||
|
||||
|
||||
|
||||
namespace hx
|
||||
{
|
||||
// For type inference when marking
|
||||
template<> inline void MarkMember(cpp::VirtualArray &outT,hx::MarkContext *__inCtx)
|
||||
{ HX_MARK_OBJECT(outT.mPtr); }
|
||||
|
||||
#ifdef HXCPP_VISIT_ALLOCS
|
||||
template<> inline void VisitMember(cpp::VirtualArray &outT,hx::VisitContext *__inCtx)
|
||||
{
|
||||
HX_VISIT_OBJECT(outT.mPtr);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace hx
|
||||
|
||||
namespace cpp
|
||||
{
|
||||
#endif // HX_VARRAY_DEFINED
|
||||
}
|
||||
|
Reference in New Issue
Block a user