#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 #include #include #include #include using namespace std; //help note //数据对象是JSON格式的树状结构 //对象有俩个成员,m_value 还有 vector> //它俩当中必须有一个是有效的,先检查vector,若空 m_value有效. //JSON定义中数组的定义不要用,因为无法转换到XML对象. //XML定义中不要用属性,因为无法转换到JSON对象. //JSON定义为主,XML支持为辅. //ini定义只有俩层. //不要在key定义中使用 【.】 ,因为Boost会把【.】看成是模块的切换点. //get 用法 //["key"],[idx],[xx].get("key"),[xx].get(); //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 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 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> m_vec; public: ResDataObject(void); ~ResDataObject(void); //open close template bool loadFile(const T *pfileName);//支持xml,json,ini扩展名 template 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 bool eraseAllOf(const T *pKey); template bool eraseOneOf(const T *pKey,size_t idx = 0); //set ResDataObject& operator = (const char tValue); ResDataObject& operator = (const unsigned char tValue); template 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 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 const wchar_t* GetKey(T idx) { return GetKey((size_t)idx); }; //get operator char(); operator unsigned char(); operator const wchar_t*(); template 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 bool add(const T0* pKey,ResDataObject &dataobj); template 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); };