| 988 | |
| 989 | template<typename ELEM_> |
| 990 | class Array : public hx::ObjectPtr< Array_obj<ELEM_> > |
| 991 | { |
| 992 | typedef hx::ObjectPtr< Array_obj<ELEM_> > super; |
| 993 | typedef Array_obj<ELEM_> OBJ_; |
| 994 | |
| 995 | public: |
| 996 | typedef ELEM_ Elem; |
| 997 | typedef Array_obj<ELEM_> *Ptr; |
| 998 | using super::mPtr; |
| 999 | using super::GetPtr; |
| 1000 | |
| 1001 | Array() { } |
| 1002 | Array(int inSize,int inReserve) : super( OBJ_::__new(inSize,inReserve) ) { } |
| 1003 | Array(const null &inNull) : super(0) { } |
| 1004 | Array(Ptr inPtr) : super(inPtr) { } |
| 1005 | |
| 1006 | #ifdef HXCPP_CHECK_POINTER |
| 1007 | inline OBJ_ *CheckGetPtr() const |
| 1008 | { |
| 1009 | if (!mPtr) hx::NullReference("Array", true); |
| 1010 | // The handler might have fixed up the null value |
| 1011 | if (!mPtr) hx::NullReference("Array", false); |
| 1012 | return mPtr; |
| 1013 | } |
| 1014 | #else |
| 1015 | inline OBJ_ *CheckGetPtr() const { return mPtr; } |
| 1016 | #endif |
| 1017 | |
| 1018 | // Construct from our type ... |
| 1019 | Array ( const hx::ObjectPtr< OBJ_ > &inArray ) |
| 1020 | : hx::ObjectPtr< OBJ_ >(inArray) { } |
| 1021 | |
| 1022 | Array(const Array<ELEM_> &inArray) : super(inArray.GetPtr()) { } |
| 1023 | |
| 1024 | // Build dynamic array from foreign array |
| 1025 | template<typename SOURCE_> |
| 1026 | Array( const Array<SOURCE_> &inRHS ) : super(0) |
| 1027 | { |
| 1028 | Array_obj<SOURCE_> *ptr = inRHS.GetPtr(); |
| 1029 | if (ptr) |
| 1030 | { |
| 1031 | OBJ_ *arr = dynamic_cast<OBJ_ *>(ptr); |
| 1032 | if (!arr) |
| 1033 | { |
| 1034 | // Non-identical type (syntactically, should be creating from Array<Dynamic>) |
| 1035 | // Copy elements one-by-one |
| 1036 | // Not quite right, but is the best we can do... |
| 1037 | int n = ptr->__length(); |
| 1038 | *this = Array_obj<ELEM_>::__new(n); |
| 1039 | for(int i=0;i<n;i++) |
| 1040 | mPtr->__unsafe_set(i,ptr->__GetItem(i)); |
| 1041 | } |
| 1042 | else |
| 1043 | mPtr = arr; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | #ifdef HX_VARRAY_DEFINED |