Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions include/Array.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#ifndef HX_ARRAY_H
#define HX_ARRAY_H
#include <limits>
#include <vector>
#include <cpp/FastIterator.h>

// --- hx::ReturnNull ------------------------------------------------------
Expand Down Expand Up @@ -59,78 +57,6 @@ template<> struct ArrayTraits<Dynamic> { enum { StoreType = arrayObject }; };
template<> struct ArrayTraits<String> { enum { StoreType = arrayString }; };
template<> struct ArrayTraits< ::cpp::Int64> { enum { StoreType = arrayInt64 }; };

template<class ELEM>
class SafeSorter
{
typedef
#if (HXCPP_API_LEVEL>=500)
::hx::Callable<int(Dynamic, Dynamic)>
#else
Dynamic
#endif
SorterFunc;

struct ArraySorter
{
ELEM* mArray;
SorterFunc mSorter;

ArraySorter(ELEM* inArray, SorterFunc inSorter) : mArray(inArray), mSorter(inSorter) {};

bool operator()(int inA, int inB)
{
return mSorter(mArray[inA], mArray[inB]) < 0;
}
};

template<class STORE>
static void SortImpl(ELEM* inArray, const int inLength, SorterFunc inSorter)
{
auto index = std::vector<STORE>(inLength);
for (auto i = 0; i < inLength; i++)
{
index[i] = static_cast<STORE>(i);
}

std::stable_sort(index.begin(), index.end(), ArraySorter(inArray, inSorter));

// Put the results back ...
for (int i = 0; i < inLength; i++)
{
int from = index[i];
while (from < i)
from = index[from];
if (from != i)
{
std::swap(inArray[i], inArray[from]);
index[i] = from;
}
}
}

public:
static void Sort(ELEM* base, const int length, SorterFunc sorter)
{
if (length < 2)
{
return;
}

if (length <= std::numeric_limits<uint8_t>::max())
{
SortImpl<uint8_t>(base, length, sorter);
}
else if (length <= std::numeric_limits<uint16_t>::max())
{
SortImpl<uint16_t>(base, length, sorter);
}
else
{
SortImpl<uint32_t>(base, length, sorter);
}
}
};

}


Expand Down
257 changes: 90 additions & 167 deletions include/hx/FieldRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,92 +21,57 @@ namespace hx


#define HX_FIELD_REF_MEM_OP(op,ret) \
inline ret operator op (const FieldRef &inA) \
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
inline ret operator op (const IndexRef &inA); \
template<typename T> inline ret operator op (const T& inA) \
{ return this->operator Dynamic() op inA; }

#define HX_FIELD_REF_IMPL_MEM_OP(op,ret) \
inline ret hx::FieldRef::operator op (const IndexRef &inA) \
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
ret operator op (const FieldRef& inA); \
ret operator op (const IndexRef& inA); \
ret operator op (const hx::Val& inA);

class FieldRef
{
public:
explicit FieldRef(hx::Object *inObj,const String &inName) : mObject(inObj), mName(inName)
{
}

hx::Val operator=(const hx::Val &inRHS)
{
return mObject->__SetField(mName,inRHS, HX_PROP_DYNAMIC );
}
inline operator hx::Val() const { return mObject ? mObject->__Field(mName, HX_PROP_DYNAMIC) : null(); }
inline operator Dynamic() const { return mObject ? Dynamic(mObject->__Field(mName, HX_PROP_DYNAMIC)) : null(); }
inline operator double() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
inline operator float() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
inline operator int() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
inline operator cpp::UInt64() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }
inline operator cpp::Int64() const { return mObject->__Field(mName, HX_PROP_DYNAMIC); }


// post-increment
inline double operator++(int)
{
double d = mObject->__Field(mName, HX_PROP_DYNAMIC);
mObject->__SetField(mName,d+1, HX_PROP_DYNAMIC);
return d;
}
// pre-increment
inline double operator++()
{
double d = ((double)mObject->__Field(mName, HX_PROP_DYNAMIC)) + 1;
mObject->__SetField(mName,d, HX_PROP_DYNAMIC);
return d;
}
// post-decrement
inline double operator--(int)
{
double d = mObject->__Field(mName, HX_PROP_DYNAMIC);
mObject->__SetField(mName,d-1, HX_PROP_DYNAMIC);
return d;
}
// pre-decrement
inline double operator--()
{
double d = (double)(mObject->__Field(mName, HX_PROP_DYNAMIC)) - 1;
mObject->__SetField(mName,d, HX_PROP_DYNAMIC);
return d;
}
bool operator !() { return ! ((int)(mObject->__Field(mName, HX_PROP_DYNAMIC))); }
int operator ~() { return ~ ((int)mObject->__Field(mName, HX_PROP_DYNAMIC)); }

inline bool operator==(const null &) const { return !mObject; }
inline bool operator!=(const null &) const { return mObject; }

double operator -() { return - (double)(mObject->__Field(mName, HX_PROP_DYNAMIC)); }

bool HasPointer() const { return mObject; }


HX_FIELD_REF_MEM_OP(==,bool)
HX_FIELD_REF_MEM_OP(!=,bool)
HX_FIELD_REF_MEM_OP(<,bool)
HX_FIELD_REF_MEM_OP(<=,bool)
HX_FIELD_REF_MEM_OP(>,bool)
HX_FIELD_REF_MEM_OP(>=,bool)

HX_FIELD_REF_MEM_OP(+,Dynamic)
HX_FIELD_REF_MEM_OP(*,double)
HX_FIELD_REF_MEM_OP(/,double)
HX_FIELD_REF_MEM_OP(-,double)
HX_FIELD_REF_MEM_OP(%,double)



String mName;
hx::Object *mObject;
explicit FieldRef(hx::Object* inObj, const String& inName);

hx::Val operator=(const hx::Val& inRHS);
operator hx::Val();
operator Dynamic() const;
operator double() const;
operator float() const;
operator int() const;
operator cpp::UInt64() const;
operator cpp::Int64() const;

// post-increment
double operator++(int);
// pre-increment
double operator++();
// post-decrement
double operator--(int);
// pre-decrement
double operator--();
bool operator !();
int operator ~();

bool operator==(const null&) const;
bool operator!=(const null&) const;

double operator -();

bool HasPointer() const;

HX_FIELD_REF_MEM_OP(==,bool)
HX_FIELD_REF_MEM_OP(!=,bool)
HX_FIELD_REF_MEM_OP(<,bool)
HX_FIELD_REF_MEM_OP(<=,bool)
HX_FIELD_REF_MEM_OP(>,bool)
HX_FIELD_REF_MEM_OP(>=,bool)

HX_FIELD_REF_MEM_OP(+,Dynamic)
HX_FIELD_REF_MEM_OP(*,double)
HX_FIELD_REF_MEM_OP(/,double)
HX_FIELD_REF_MEM_OP(-,double)
HX_FIELD_REF_MEM_OP(%,double)

String mName;
hx::Object *mObject;
};

// We can define this one now...
Expand Down Expand Up @@ -141,81 +106,53 @@ HX_FIELD_REF_OP(%,double)
//

#define HX_INDEX_REF_MEM_OP(op,ret) \
inline ret operator op (const IndexRef &inA) \
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
inline ret operator op (const FieldRef &inA) \
{ return this->operator Dynamic() op inA.operator Dynamic(); } \
template<typename T> inline ret operator op (const T& inA) \
{ return this->operator Dynamic() op inA; }

ret operator op (const IndexRef &inA); \
ret operator op (const FieldRef &inA); \
ret operator op (const hx::Val& inA);

class IndexRef
{
public:
explicit IndexRef(hx::Object *inObj,int inIndex) : mObject(inObj), mIndex(inIndex)
{
}

Dynamic operator=(const Dynamic &inRHS)
{
return mObject->__SetItem(mIndex,inRHS);
}
inline operator Dynamic() const { return mObject->__GetItem(mIndex); }
inline operator double() const { return mObject->__GetItem(mIndex); }
inline operator int() const { return mObject->__GetItem(mIndex); }

// post-increment
inline double operator++(int)
{
double d = mObject->__GetItem(mIndex)->__ToDouble();
mObject->__SetItem(mIndex,d+1);
return d;
}
// pre-increment
inline double operator++()
{
double d = mObject->__GetItem(mIndex)->__ToDouble() + 1;
mObject->__SetItem(mIndex,d);
return d;
}
// post-decrement
inline double operator--(int)
{
double d = mObject->__GetItem(mIndex)->__ToDouble();
mObject->__SetItem(mIndex,d-1);
return d;
}
// pre-decrement
inline double operator--()
{
double d = mObject->__GetItem(mIndex)->__ToDouble() - 1;
mObject->__SetItem(mIndex,d);
return d;
}
bool operator !() { return ! mObject->__GetItem(mIndex)->__ToInt(); }
int operator ~() { return ~ mObject->__GetItem(mIndex)->__ToInt(); }
double operator -() { return - mObject->__GetItem(mIndex)->__ToDouble(); }

inline bool operator==(const null &) const { return !mObject; }
inline bool operator!=(const null &) const { return mObject; }

HX_INDEX_REF_MEM_OP(==,bool)
HX_INDEX_REF_MEM_OP(!=,bool)
HX_INDEX_REF_MEM_OP(<,bool)
HX_INDEX_REF_MEM_OP(<=,bool)
HX_INDEX_REF_MEM_OP(>,bool)
HX_INDEX_REF_MEM_OP(>=,bool)

HX_INDEX_REF_MEM_OP(+,Dynamic)
HX_INDEX_REF_MEM_OP(*,double)
HX_INDEX_REF_MEM_OP(/,double)
HX_INDEX_REF_MEM_OP(-,double)
HX_INDEX_REF_MEM_OP(%,double)

bool HasPointer() const { return mObject; }

int mIndex;
hx::Object *mObject;
explicit IndexRef(hx::Object* inObj, int inIndex);

Dynamic operator=(const Dynamic& inRHS);
operator Dynamic() const;
operator double() const;
operator int() const;

// post-increment
double operator++(int);
// pre-increment
double operator++();
// post-decrement
double operator--(int);
// pre-decrement
double operator--();

bool operator !();
int operator ~();
double operator -();

bool operator==(const null&) const;
bool operator!=(const null&) const;

HX_INDEX_REF_MEM_OP(== , bool)
HX_INDEX_REF_MEM_OP(!= , bool)
HX_INDEX_REF_MEM_OP(< , bool)
HX_INDEX_REF_MEM_OP(<= , bool)
HX_INDEX_REF_MEM_OP(> , bool)
HX_INDEX_REF_MEM_OP(>= , bool)

HX_INDEX_REF_MEM_OP(+, Dynamic)
HX_INDEX_REF_MEM_OP(*, double)
HX_INDEX_REF_MEM_OP(/ , double)
HX_INDEX_REF_MEM_OP(-, double)
HX_INDEX_REF_MEM_OP(%, double)

bool HasPointer() const;

int mIndex;
hx::Object *mObject;
};

// We can define this one now...
Expand Down Expand Up @@ -243,20 +180,6 @@ HX_INDEX_REF_OP(-,double)
HX_INDEX_REF_OP(%,double)


// Implement once IndexRef has been defined.
HX_FIELD_REF_IMPL_MEM_OP(==,bool)
HX_FIELD_REF_IMPL_MEM_OP(!=,bool)
HX_FIELD_REF_IMPL_MEM_OP(<,bool)
HX_FIELD_REF_IMPL_MEM_OP(<=,bool)
HX_FIELD_REF_IMPL_MEM_OP(>,bool)
HX_FIELD_REF_IMPL_MEM_OP(>=,bool)

HX_FIELD_REF_IMPL_MEM_OP(+,Dynamic)
HX_FIELD_REF_IMPL_MEM_OP(*,double)
HX_FIELD_REF_IMPL_MEM_OP(/,double)
HX_FIELD_REF_IMPL_MEM_OP(-,double)
HX_FIELD_REF_IMPL_MEM_OP(%,double)

// Disambiguate Dynamic operators...

#define HX_INDEX_REF_OP_DYNAMIC(op,ret) \
Expand Down
Loading