123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- //---------------------------------------------------------------------------
- #ifndef ITSLibFH
- #define ITSLibFH
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- #ifndef __ITSLIb_EXPORT__
- #pragma comment(lib, "ITSLib.lib")
- #endif // #ifndef __ITSLIb_EXPORT__
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <map>
- #include <list>
- #include <vector>
- #include <algorithm>
- #include <Classes.hpp>
- /*
- ***************************************************************************************************
- * 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 <typename Key, class T>
- class TITSStlMap
- {
- protected:
- typedef std::map<Key, T> MapObject;
- typedef typename std::map<Key, T>::iterator Iter;
- typedef typename std::map<Key, T>::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<Iter, bool> pairTwo;
- pairTwo = FObjects.insert(std::make_pair<Key, T>(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 T>
- class TITSStlList
- {
- protected:
- typedef std::list<T> ListObject;
- typedef typename std::list<T>::iterator Iter;
- typedef typename std::list<T>::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
|