#ifndef DATA_STRUCT__H_ #define DATA_STRUCT__H_ #ifdef _WIN32 #pragma once #endif #include #include #include #if 0 template class HBuffer { public: HBuffer() { m_pBuf = NULL; m_nSize = 0; } HBuffer(size_t n) { if (n) m_pBuf = (_T *)malloc(n * sizeof(_T)); else m_pBuf = NULL; m_nSize = n; } virtual ~HBuffer() { if (m_pBuf) free(m_pBuf); } inline _T * GetPtr() { return m_pBuf; } inline size_t GetSize() { return m_nSize; } inline void Create(size_t n) { if (n) m_pBuf = (_T *)malloc(n * sizeof(_T)); m_nSize = n; } inline bool Copy(_T * pData, size_t nSize) { if (pData == NULL || nSize <= 0) return false; memcpy(m_pBuf, pData, nSize); } protected: _T * m_pBuf; size_t m_nSize; }; #endif template class HDynamicArray { public: HDynamicArray(size_t n) { if (n) m_p = (_T *)malloc(n * sizeof(_T)); else m_p = NULL; } HDynamicArray(_T * p) { m_p = p; } ~HDynamicArray() { if (m_p) free(m_p); } inline void Attach(_T * p) { m_p = p; } inline void Detatch() { m_p = NULL; } inline void Realloc(size_t n) { free(m_p); m_p = (_T *)malloc(n * sizeof(_T)); } inline void Restruct(_T * p) { free(m_p); m_p = p; } _T * m_p; }; class HStrList : public std::list { public: HStrList() {} ~HStrList() {} inline void SplitAdd(const HString & str, char chDelimiter) { HStringTokenizer token(str, chDelimiter); for (size_t i = 0; i < token.GetCount(); i++) { push_back(token[i]); } } }; class HStrVector : public std::vector { public: HStrVector() {} ~HStrVector() {} inline void Remove(const char * psz) { erase(std::remove(begin(), end(), psz), end()); } inline bool IsExist(const char * psz) { HString str = psz; return std::find(begin(), end(), str) != end(); } }; class HStrStrMap : public std::map { public: HStrStrMap() {} ~HStrStrMap() {} inline void Insert(const char * pszKey, const char * pszValue) { insert(std::pair(pszKey, pszValue)); } }; #endif // DATA_STRUCT__H