123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- #pragma once
- #ifndef LIB_LISTSTRUCT_EXPORTS
- #ifdef WIN_64BIT
- #ifdef _DEBUG
- #pragma comment(lib, "libListStructX64D.lib")
- #else
- #pragma comment(lib, "libListStructX64.lib")
- #endif
- #else
- #ifdef _DEBUG
- #pragma comment(lib, "libListStructD.lib")
- #else
- #pragma comment(lib, "libListStruct.lib")
- #endif
- #endif
- #endif
- #include <utility>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <sstream>
- using namespace std;
- //help note
- //数据对象是JSON格式的树状结构
- //对象有俩个成员,m_value 还有 vector<pair<string,数据对象>>
- //它俩当中必须有一个是有效的,先检查vector,若空 m_value有效.
- //JSON定义中数组的定义不要用,因为无法转换到XML对象.
- //XML定义中不要用属性,因为无法转换到JSON对象.
- //JSON定义为主,XML支持为辅.
- //ini定义只有俩层.
- //不要在key定义中使用 【.】 ,因为Boost会把【.】看成是模块的切换点.
- //get 用法
- //["key"],[idx],[xx].get<double>("key"),[xx].get<double>();
- //add 用法:不解释
- //update 用法:key,val,idx的形式,没有匹配值的情况用add,有值的情况update
- class ResDataObjectExption : public std::exception
- {
- std::wstring m_ExpContext;
- public:
- ResDataObjectExption(const wchar_t *pExp);
- ~ResDataObjectExption(void);
- const wchar_t *what();
- };
- //缺省的值和字符串以外不要用
- class EDATAOBJECT {
- protected:
- std::wstring m_value;
- public:
- EDATAOBJECT();
- ~EDATAOBJECT();
- //set
- EDATAOBJECT& operator = (const char* pVal);
- EDATAOBJECT& operator = (const wchar_t* pVal);
- template<typename T> EDATAOBJECT& operator = (const T tValue)
- {
- std::wstringstream strm;
- strm << tValue;
- (*this) = strm.str().c_str();
- return (*this);
- };
- //get
- operator char();
- operator unsigned char();
- operator const wchar_t*();
- template<typename T> operator T()
- {
- T ret1 = 0;
- std::wstringstream strm;
- strm << (const wchar_t*)(*this);
- strm >> ret1;
- return ret1;
- };
- };
- class ResDataObject
- {
- protected:
- std::wstring m_encode;//serialize
- std::wstring m_value;
- vector<pair<wstring,ResDataObject>> m_vec;
- public:
- ResDataObject(void);
- ~ResDataObject(void);
- //open close
- template<class T> bool loadFile(const T *pfileName);//支持xml,json,ini扩展名
- template<class T> bool SaveFile( const T *pfileName );//支持xml,json,ini扩展名
- //serialize
- const wchar_t *encode();
- bool decode(const wchar_t *pdata);
- //commons
- void clear();
- size_t size();
- bool IsObject();
- //erase
- template<typename T> bool eraseAllOf(const T *pKey);
- template<typename T> bool eraseOneOf(const T *pKey,size_t idx = 0);
- //set
- ResDataObject& operator = (const char tValue);
- ResDataObject& operator = (const unsigned char tValue);
- template<typename T> ResDataObject& operator = (const T tValue)
- {
- std::wstringstream strm;
- strm << tValue;
- (*this) = strm.str().c_str();
- return (*this);
- };
- ResDataObject& operator = (const char* pVal);
- ResDataObject& operator = (const wchar_t* pVal);
- //get
- ResDataObject &operator [](size_t idx);
- template<class T> ResDataObject &operator [](T idx)
- {
- return (*this)[(size_t)idx];
- };
- ResDataObject &operator [](const char *pKey);
- ResDataObject &operator [](const wchar_t *pKey);
- bool SetKey(size_t idx,const char *pKey);
- bool SetKey(size_t idx,const wchar_t *pKey);
- const wchar_t* GetKey(size_t idx);
- template<typename T> const wchar_t* GetKey(T idx)
- {
- return GetKey((size_t)idx);
- };
- //get
- operator char();
- operator unsigned char();
- operator const wchar_t*();
- template<typename T> operator T()
- {
- T ret1 = 0;
- std::wstringstream strm;
- strm << (const wchar_t*)(*this);
- strm >> ret1;
- return ret1;
- };
- //same name in the row
- int GetFirstOf(const char *pKey);
- int GetFirstOf(const wchar_t *pKey);
- int GetNextOf(const char *pKey,int PrevIdx);
- int GetNextOf(const wchar_t *pKey,int PrevIdx);
- //add
- template<typename T0> bool add(const T0* pKey,ResDataObject &dataobj);
- template<typename T0,typename T> bool add(const T0* pKey,const T tValue)
- {
- ResDataObject val1;
- val1 = tValue;
-
- return add(pKey,val1);
- return true;
- };
- };
- class libListInitial {
- public:
- libListInitial();
- ~libListInitial();
- bool testList();
- //void PrintObject(ResDataObject &obj,int level1);
- };
|