#ifndef __ZCPPMAIIN__ZTCARRAY_H__ #define __ZCPPMAIIN__ZTCARRAY_H__ #include "ZCppMain/ZMainHead.H" namespace ZNsMain { template< typename TType , typename TTypArg=const TType&, typename TSize =long > class ZtCArray ////////////////////////// { public: typedef TType Type ; typedef TType TypeData; typedef TTypArg TypeArg ; typedef TSize TypeSize; public: class ZCDataPoint; public: typedef Type* IterEasy; typedef ZCDataPoint iterator; typedef ZCDataPoint TypeIter; public: typedef const IterEasy IterEasyC; typedef const ZCDataPoint iteratorC; typedef const TypeData TypeDataC; public: typedef const ZCDataPoint const_iterator; public: class ZCDataPoint { private: mutable Type* mp_Data ; mutable TSize ml_ElePos; // *mp_Data 가 배열에서 차지하는 위치 ZtCArray* mp_CArray; public: ZCDataPoint() { mp_Data =0; mp_CArray=0; ml_ElePos=0; }/* ZCDataPoint()*/ ZCDataPoint(ZtCArray& AR_CArray, Type& AR_CData, TSize AL_ElePos) { mp_Data =&AR_CData ; mp_CArray=&AR_CArray; ml_ElePos=AL_ElePos ; }/* ZCDataPoint(ZtCArray& AR_CArray, Type& AR_CData, TSize AL_ElePos)*/ ZCDataPoint(ZtCArray& AR_CArray) { mp_Data = AR_CArray.mp_TypeArr ; mp_CArray=&AR_CArray ; ml_ElePos=(AR_CArray.size()>0 ? 1 : 0 ) ; }/* ZCDataPoint(ZtCArray& AR_CArray)*/ ZCDataPoint(const ZtCArray& AR_CArray) { mp_Data = AR_CArray.mp_TypeArr ; mp_CArray= const_cast(&AR_CArray); ml_ElePos= (AR_CArray.size()>0 ? 1 : 0 ) ; }/* ZCDataPoint(const ZtCArray& AR_CArray)*/ Type& operator*( ){return *mp_Data;} Type* operator->(){return mp_Data;} const Type& operator* () const{return *mp_Data;} const Type* operator->() const{return mp_Data;} ZCDataPoint& operator++( ){++mp_Data; ++ml_ElePos; return *this;} ZCDataPoint operator++(int){++mp_Data; ++ml_ElePos; return *this;} const ZCDataPoint& operator++( ) const{++mp_Data; ++ml_ElePos; return *this;} const ZCDataPoint operator++(int) const{++mp_Data; ++ml_ElePos; return *this;} ZCDataPoint operator+(TSize AL_AddPos) const { return ZCDataPoint(*this, mp_Data+AL_AddPos, ml_ElePos+AL_AddPos); }/* ZCDataPoint operator+(TSize AL_AddPos) const*/ public: };/* class ZCDataPoint public :*/ protected: enum{ZEAddSize=20}; protected: Type* mp_TypeArr ; TypeSize ml_AllSize ; TypeSize ml_UseSize ; TypeSize ml_AddSize ; /* TSize ml_AddSize 는 추가 메모리를 지정. 한 개의 원소가 삽입되서 재할당해야 할 경우, ml_AddSize 개 만큼을 미리 할당한다. protected:*/ public : ZtCArray() { mp_TypeArr =0; ml_AllSize =0; ml_UseSize =0; ml_AddSize =ZEAddSize; }/* ZtCArray()*/ ZtCArray(const ZtCArray& rhs) { mp_TypeArr =0; ml_AllSize =0; ml_UseSize =0; ml_AddSize =ZEAddSize; *this=rhs; }/* ZtCArray(const ZtCArray& rhs)*/ ~ZtCArray() { Delete(); }/* ~ZtCArray()*/ ZtCArray& operator=(const ZtCArray& rhs) { if(this==&rhs) return *this ; ReAlloc(rhs.ml_UseSize, false); ml_UseSize = rhs.ml_UseSize; ml_AllSize = rhs.ml_AllSize; for(TypeSize i=0; i=1) ml_AddSize=AL_NewAddSize; }/* void SetAddSize(TypeSize AL_NewAddSize)*/ void SetUseSize(TypeSize AL_NewUseSize) { if(AL_NewUseSize>=0 && AL_NewUseSize<=ml_AllSize) { ml_UseSize = AL_NewUseSize; }/* if(AL_NewUseSize>=0 && AL_NewUseSize<=ml_AllSize)*/ }/* void SetUseSize(TypeSize AL_NewUseSize)*/ void ReAlloc(TypeSize AL_AllocSize, bool AB_DoKeep=true) { if(AL_AllocSize<1) return ; if(AL_AllocSize::assign(size_type _Count, const type&); void assign(TypeSize AL_AllocSize, bool AB_DoKeep=true) { this->ReAlloc(AL_AllocSize, AB_DoKeep); this->SetUseSize(AL_AllocSize); }/* void assign(TypeSize AL_AllocSize, bool AB_DoKeep=true)*/ Type& operator[](TypeSize AL_Index) { return mp_TypeArr[AL_Index] ; }/* Type& operator[](TypeSize AL_Index)*/ const Type& operator[](TypeSize AL_Index) const { return mp_TypeArr[AL_Index] ; }/* const Type& operator[](TypeSize AL_Index) const*/ Type& GetData(TypeSize AL_Index) { return mp_TypeArr[AL_Index] ; }/* Type& GetData(TypeSize AL_Index)*/ const Type& GetData(TypeSize AL_Index) const { return mp_TypeArr[AL_Index]; }/* const Type& GetData(TypeSize AL_Index) const*/ void AddHead(TypeArg AR_TypeArg) { ReAlloc((ml_UseSize++)+1); for(TypeSize i=ml_UseSize-2; i>=0; --i) { mp_TypeArr[i+1]=mp_TypeArr[i] ; } /*:::::::::::::::::::::::::::::::::::*/ mp_TypeArr[0]=AR_TypeArg ; }/* void AddHead(TypeArg AR_TypeArg)*/ Type& AddHead() { // 앞에 빈 원소를 삽입하고 그 원소를 반환한다. ReAlloc((ml_UseSize++)+1); for(TypeSize i=ml_UseSize-2; i>=0; --i) { mp_TypeArr[i+1]=mp_TypeArr[i] ; } /*:::::::::::::::::::::::::::::::::::*/ return mp_TypeArr[0] ; }/* Type& AddHead()*/ void AddTail(TypeArg AR_TypeArg) { ReAlloc((ml_UseSize++)+1); mp_TypeArr[ml_UseSize-1]=AR_TypeArg ; }/* void AddTail(TypeArg AR_TypeArg)*/ Type& AddTail() { // 끝에 빈 원소를 삽입하고 그 원소를 반환한다. ReAlloc((ml_UseSize++)+1); return mp_TypeArr[ml_UseSize-1]; }/* Type& AddTail()*/ operator Type&() { return AddTail(); }/* operator Type&()*/ void push_front(TypeArg AR_TypeArg){AddHead(AR_TypeArg);} void push_back (TypeArg AR_TypeArg){AddTail(AR_TypeArg);} Type& push_front(){return AddHead();} Type& push_back (){return AddTail();} /***/ ZCDataPoint begin() {return ZCDataPoint(*this);} const ZCDataPoint begin() const{return ZCDataPoint(*this);} template void IterElement(TFunctor AO_Functor) { Type* VP_TypeArr = mp_TypeArr; __for0(TypeSize, i, ml_UseSize) { ZNsMain::ZtCTypeData:: GetObjRef(AO_Functor)( *VP_TypeArr ); ++VP_TypeArr; ////////////////// }/* __for0(TypeSize, i, ml_UseSize)*/ }/* template void IterElement(TFunctor AO_Functor)*/ template void IterElement(TFunctor AO_Functor, TTypeHelp AO_TypeHelp) { typedef ZNsMain:: ZtCCheckRef ZCCheckRef; Type* VP_TypeArr = mp_TypeArr; __for0(TypeSize, i, ml_UseSize) { ZNsMain::ZtCTypeData::GetObjRef(AO_Functor) ( *VP_TypeArr, ZCCheckRef::PassData(AO_TypeHelp) ); ++VP_TypeArr; /////////////////////////////////////// }/* __for0(TypeSize, i, ml_UseSize)*/ }/* template void IterElement(TFunctor AO_Functor, TTypeHelp AO_TypeHelp)*/ template /*#####################################################*/ < typename TFunctor , typename TTypeHelp1 , typename TTypeHelp2 > void IterElement ( TFunctor AO_Functor , TTypeHelp1 AO_TypeHelp1 , TTypeHelp2 AO_TypeHelp2 ) /*##############################################################*/ { typedef ZNsMain::ZtCCheckRef ZCCheckRef1; typedef ZNsMain::ZtCCheckRef ZCCheckRef2; Type* VP_TypeArr = mp_TypeArr; __for0(TypeSize, i, ml_UseSize) { ZNsMain::ZtCTypeData::GetObjRef(AO_Functor) ( *VP_TypeArr , ZCCheckRef1::PassData(AO_TypeHelp1) , ZCCheckRef2::PassData(AO_TypeHelp2) ); ++VP_TypeArr; /////////////////////////////////////// }/* __for0(TypeSize, i, ml_UseSize)*/ }/* template ######################################################### < typename TFunctor , typename TTypeHelp1 , typename TTypeHelp2 > void IterElement ( TFunctor AO_Functor , TTypeHelp1 AO_TypeHelp1 , TTypeHelp2 AO_TypeHelp2 ) ################################################################*/ /*/////////////////////////////////////////////////////////////////////////// ■ IterElement() 예제. #include #include "ZCppMain/ZtCArray.H" using namespace std ; using namespace ZNsMain; int main() { typedef ZtCArray CArray ; typedef CArray::IterEasy IterEasy; CArray VO_Array; VO_Array.AddTail(10); VO_Array.AddTail(20); VO_Array.AddTail(30); VO_Array.AddTail(40); class CHelpObj { public: CHelpObj() { } CHelpObj(const CHelpObj& rhs) { cout<<"* CHelpObj(const CHelpObj& rhs)"<