//--------------------------------------------------------------------------- #ifndef ITSLibFH #define ITSLibFH //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- #ifndef __ITSLIb_EXPORT__ #pragma comment(lib, "ITSLib.lib") #endif // #ifndef __ITSLIb_EXPORT__ //--------------------------------------------------------------------------- #include #include #include #include #include #include /* *************************************************************************************************** * STL Define ***************************************************************************************************/ #ifndef FOR_STL #define FOR_STL(_class, _pointer, _list) for(_class _pointer = (_list).GetHead(); !(_list).IsEnd(); _pointer = (_list).GetNext()) #endif #ifndef REV_STL #define REV_STL(_class, _pointer, _list) for(_class _pointer = (_list).GetTail(); !(_list).IsBegin(); _pointer = (_list).GetPrev()) #endif /* *************************************************************************************************** * DB JOB Define ***************************************************************************************************/ #define DB_INIT 0 #define DB_NEW 1 #define DB_DELETE 2 #define DB_UPDATE 3 /* *************************************************************************************************** * STL OBJECT ***************************************************************************************************/ namespace ITSLib { class TITSAutoLock { public: TITSAutoLock(CRITICAL_SECTION *ACS); ~TITSAutoLock(); private: protected: CRITICAL_SECTION *CS; }; //--------------------------------------------------------------------------- template class TITSStlMap { protected: typedef std::map MapObject; typedef typename std::map::iterator Iter; typedef typename std::map::reverse_iterator RIter; Iter FCurrPos; RIter FRevsPos; CRITICAL_SECTION CS; public: MapObject FObjects; TITSStlMap() { FObjects.clear(); InitializeCriticalSection(&CS); }; virtual ~TITSStlMap() { RemoveAll(); DeleteCriticalSection(&CS); }; public: inline CRITICAL_SECTION* __fastcall GetLock() { return &CS; }; inline bool __fastcall Lock() { EnterCriticalSection(&CS); return true; }; inline void __fastcall UnLock() { LeaveCriticalSection(&CS); }; inline bool __fastcall Push(Key AKey, T AData) { std::pair pairTwo; pairTwo = FObjects.insert(std::make_pair(AKey, AData)); return pairTwo.second; }; inline T __fastcall Find(Key AKey) { Iter it; it = FObjects.find(AKey); if (it != FObjects.end()) return (it->second); return (T)NULL; } inline void __fastcall RemoveAll() { Iter it; for (it = FObjects.begin(); it != FObjects.end(); ++it) { T data = (it->second); if (data) delete data; } FObjects.clear(); } inline void __fastcall Clear() { FObjects.clear(); } inline bool __fastcall Remove(Key AKey) { Iter it; it = FObjects.find(AKey); if (it != FObjects.end()) { T data = (it->second); if (data) delete data; FObjects.erase(AKey); return true; } return false; } inline bool __fastcall Erase(Key AKey) { Iter it; it = FObjects.find(AKey); if (it != FObjects.end()) { FObjects.erase(AKey); return true; } return false; } inline int __fastcall Size() { return (int)FObjects.size(); } inline bool __fastcall IsExist(Key AKey) { Iter it; it = FObjects.find(AKey); return (iter != FObjects.end()); } inline bool __fastcall IsEmpty() { return FObjects.empty(); }; inline T __fastcall GetHead() { FCurrPos = FObjects.begin(); if (FCurrPos != FObjects.end()) return (FCurrPos->second); return (T)NULL; } inline T __fastcall GetNext() { if (FCurrPos != FObjects.end()) { FCurrPos++; if (FCurrPos != FObjects.end()) return (FCurrPos->second); } return (T)NULL; } inline bool __fastcall IsEnd() { return (FCurrPos == FObjects.end()); } inline T __fastcall GetTail() { FRevsPos = FObjects.rbegin(); if (FRevsPos != FObjects.rend()) return (*FRevsPos); return (T)NULL; } inline T __fastcall GetRNext() { if (FRevsPos != FObjects.rend()) { FRevsPos++; if (FRevsPos != FObjects.rend()) return (*FRevsPos); } return (T)NULL; } inline bool __fastcall IsREnd() { return (FRevsPos == FObjects.rend()); } inline T __fastcall GetValue(int AIndex) { if ((FObjects.size() <= AIndex) || (AIndex < 0)) return (T)NULL; #if 1 Iter it = FObjects.begin(); if (it == FObjects.end()) return (T)NULL; for (int ii = 0; ii < AIndex; ii++) { it++; } #else Iter it = (FObjects.begin() + AIndex); #endif if (it != FObjects.end()) return (it->second); return (T)NULL; }; inline T operator[](size_t AIndex) { return GetValue(AIndex)); }; }; //----------------------------------------------------------------------- template class TITSStlList { protected: typedef std::list ListObject; typedef typename std::list::iterator Iter; typedef typename std::list::reverse_iterator RIter; Iter FCurrPos; RIter FRevsPos; CRITICAL_SECTION CS; public: ListObject FObjects; TITSStlList() { FObjects.clear(); InitializeCriticalSection(&CS); }; virtual ~TITSStlList() { Clear(); /* RemoveAll(È£ÃâÇÏÁö ¾ÊÀ½) : Æ÷ÀÎÅͰ´Ã¼¸¦ »ç¿ëÇÏÁö ¾ÊÀ» ¼ö ÀÖÀ½ */ DeleteCriticalSection(&CS); }; public: inline CRITICAL_SECTION* __fastcall GetLock() { return &CS; }; inline bool __fastcall Lock() { EnterCriticalSection(&CS); return true; }; inline void __fastcall UnLock() { LeaveCriticalSection(&CS); }; inline void __fastcall Push(T AData) { FObjects.push_back(AData); }; inline T __fastcall Find() { return NULL; /* std::list ¿¡¼­´Â »ç¿ëÇÏÁö ¾ÊÀ½ */ } inline void __fastcall RemoveAll() { ListObject::const_iterator eIter(FObjects.end()); for (ListObject::const_iterator iter = FObjects.begin(); iter != eIter; ++iter) { T data = (*iter); delete data; } FObjects.clear(); }; inline void __fastcall Clear() { FObjects.clear(); }; inline bool __fastcall Remove(T AData) { Iter iter = std::find(FObjects.begin(), FObjects.end(), AData); if (iter != FObjects.end()) { T data = (*iter); FObjects.erase(iter); FCurrPos = iter; if (data) delete data; return true; } return false; } inline bool __fastcall Erase(T AData) { ITer iter = std::find(FObjects.begin(), FObjects.end(), AData); if (iter != FObjects.end()) { FObjects.erase(iter); FCurrPos = iter; return true; } return false; } inline int __fastcall Size() { return ((int)FObjects.size()); }; inline bool __fastcall IsExist(T AData) { Iter iter = std::find(FObjects.begin(), FObjects.end(), AData); return (iter != FObjects.end()); }; inline bool __fastcall IsEmpty() { return FObjects.empty(); }; inline T __fastcall GetHead() { FCurrPos = FObjects.begin(); if (FCurrPos == FObjects.end()) return (T)NULL; return (*FCurrPos); }; inline T __fastcall GetNext() { if (FCurrPos != FObjects.end()) { FCurrPos++; if (FCurrPos != FObjects.end()) return (*FCurrPos); } return (T)NULL; }; inline bool __fastcall IsEnd() { return (FCurrPos == FObjects.end()); } inline T __fastcall GetTail() { FRevsPos = FObjects.rbegin(); if (FRevsPos != FObjects.rend()) return (*FRevsPos); return (T)NULL; } inline T __fastcall GetRNext() { if (FRevsPos != FObjects.rend()) { FRevsPos++; if (FRevsPos != FObjects.rend()) return (*FRevsPos); } return (T)NULL; } inline bool __fastcall IsREnd() { return (FRevsPos == FObjects.rend()); } inline T __fastcall GetValue(size_t AIndex) { if ((FObjects.size() <= index) || (index < 0)) return (T)NULL; ITer iter = (FObjects.begin() + AIndex); if (iter != FObjects.end()) return (*iter); return (T)NULL; }; inline T operator[](size_t AIndex) { return GetValue(AIndex)); }; }; //----------------------------------------------------------------------- } // namespace //--------------------------------------------------------------------------- #define TItsAutoLock ITSLib::TITSAutoLock #define TItsMap ITSLib::TITSStlMap #define TItsList ITSLib::TITSStlList //--------------------------------------------------------------------------- /* ***************************************************************************** * Extern Function Prototypes ***************************************************************************** */ extern "C" { } /* extern "C" */ #endif