Files
smartservice_native/hdssd/huslib/DataStruct.h
T
2026-05-20 03:08:08 +09:00

112 lines
2.0 KiB
C++

#ifndef DATA_STRUCT__H_
#define DATA_STRUCT__H_
#ifdef _WIN32
#pragma once
#endif
#include <list>
#include <vector>
#include <map>
#if 0
template<class _T>
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 _T>
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<HString>
{
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<HString>
{
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<HString, HString>
{
public:
HStrStrMap() {}
~HStrStrMap() {}
inline void Insert(const char * pszKey, const char * pszValue)
{
insert(std::pair<HString, HString>(pszKey, pszValue));
}
};
#endif // DATA_STRUCT__H