C++序列化库的实现

C++中经常需要用到序列化与反序列化功能,由于C++标准中没有提供此功能,于是就出现了各式各样的序列化库,如boost中的,如谷歌的开源项目,但是很多库都依赖其他库过于严重,导致库变得很庞大.今天来分享一个我写的序列化库,在写库的时候,我有一个使用上是否方便的标准,那就是别人用了你的库,需要写多少行代码.下面将要提供的这个库理论上是夸平台的,因为用的都是C++标准语法.这个库性能,以前写的时候就拿来跟boost中的还是谷歌的开源项目相比较过(具体是哪个,时间久忘了是),结果我记得很清楚,速度上慢了一倍.后来发现是实现上多了一次拷贝,所以还是有提升空间的.

这个库使用上相当方便,只需要使用三种操作符即可: << , >> , & , 同时需要用到traits库,想要获取traits请看上一篇博文.

这个库提供两类archive,一种是string(wstring也可以),一种是fstream,本来还想提供xml格式的和二进制格式的,但是由于后来工作忙就没有继续提供,序列化的对象包括基本类型,用户自定义类型,stl库里常用的容器,不支持的容器各位可以拿来扩展一下,到时候别忘了分享给我哈.

废话不说,上代码,老规矩,先写用例,接下来再贴完整的库,把各个hpp文件拷贝下来即可使用(这里不支持上传文件,贴库好辛苦,要体谅):

#include<iostream>
#include "../../traits/traits.hpp"
#include "../../serialization/archive.hpp" using namespace std; struct Student
{
int _idx;
float _weigth;
std::string _name;
std::list<std::string> _familyName_list; // 要定义成public的
template<typename Arch>
void serialize(Arch& arch, unsigned int ver)
{
// ver是版本号
arch & _idx
& _weigth
& _name
& _familyName_list;
}
}; int main()
{
Student stu; // 有一个学生
stu._idx = ; // 编号1
stu._weigth = 120.45f;// 重120多斤 浮点精度可通过宏SERIALIZATION_FLOAT_PRECISION控制
stu._name = "小明";//名字叫小明
stu._familyName_list.push_back("爸爸");
stu._familyName_list.push_back("妈妈");
stu._familyName_list.push_back("姐姐"); // 定义一个archive类型
std::string ostr;
// 定义一个序列化对象,它的原型是typedef serialization::string_iarchive<std::string> default_string_iarchive;
serialization::default_string_oarchive oarch(ostr); // // 奇迹来了
oarch & stu; // 或者写oarch<<stu;
cout << ostr << endl; // 反序列化
Student stu2;
serialization::default_string_iarchive iarch(ostr);
iarch & stu2; // 或者写iarch>>stu2; 调试模式下观看stu2的值 // 关于指针的序列化
std::string ostr2;
serialization::default_string_oarchive oarch2(ostr2); // // 这个序化出来的是地址,并非值,之所以有这样的设定,是因为serialization序列化的是变量的值,并不是变量指
// 向的值,如果不这样设定,那在反序列化的时候会遇到内存分配的尴尬
// 读者亲自试验一下便懂得这个道理
char* pchar = "fdsfdsfsf";
oarch2 & pchar; return ;
}

接下来是完整库截图

C++序列化库的实现

// archive.hpp
#ifndef ARCHIVE_INCLUDE
#define ARCHIVE_INCLUDE #include "string_archive.hpp"
#include "wstring_archive.hpp"
#include "stream_archive.hpp"
#include "wstream_archive.hpp"
#include "xml_archive.hpp" #include <string>
#include <fstream> #ifdef USE_XML_ARCHIVE
#include "tinyxml/tinyxml.h"
#endif NAMESPACE_SERIALIZATION_BEGIN typedef serialization::string_iarchive<std::string> default_string_iarchive;
typedef serialization::string_oarchive<std::string> default_string_oarchive; typedef serialization::wstring_iarchive<std::wstring> default_wstring_iarchive;
typedef serialization::wstring_oarchive<std::wstring> default_wstring_oarchive; typedef serialization::stream_iarchive<std::ifstream> file_stream_iarchive;
typedef serialization::stream_oarchive<std::ofstream> file_stream_oarchive; typedef serialization::wstream_iarchive<std::wifstream> file_wstream_iarchive;
typedef serialization::wstream_oarchive<std::wofstream> file_wstream_oarchive; NAMESPACE_SERIALIZATION_END
#endif
// archive_config.hpp
#ifndef ARCHIVE_CONFIG_INCLUDE
#define ARCHIVE_CONFIG_INCLUDE #define NAMESPACE_SERIALIZATION_BEGIN namespace serialization{
#define NAMESPACE_SERIALIZATION_END } #define _SERIALIZATION_VERSION_H(h) ((unsigned short)(h)) << 16
#define _SERIALIZATION_VERSION_L(l) ((unsigned short)(l))
#define _SERIALIZATION_VERSION(h,l) (_SERIALIZATION_VERSION_H(h) | _SERIALIZATION_VERSION_L(l))
#define SERIALIZATION_VERSION _SERIALIZATION_VERSION(1,0)
#define SERIALIZATION_VERSION_L(v) (((unsigned int)(v)) & (0xFFFF))
#define SERIALIZATION_VERSION_H(v) (((unsigned int)(v)) >> 16)
#define SERIALIZATION_FLOAT_PRECISION 16 // 浮点精度 NAMESPACE_SERIALIZATION_BEGIN #ifdef _MSC_VER typedef long long _int64_;
typedef unsigned long long _uint64_; #elif __GNUC__ typedef int64_t _int64_;
typedef uint64_t _uint64_; #else // unknown typedef int _int64_;
typedef unsigned int _uint64_; #endif class storagepos;
struct storage_type; typedef _int64_ vehicleoff; class storagepos
{
public: typedef storagepos _My; storagepos(vehicleoff _off=):m_vehicle_off(_off){} operator vehicleoff()const{ return m_vehicle_off; } vehicleoff operator -(const _My& _right)const
{
return (m_vehicle_off - (vehicleoff)_right);
} _My& operator -=(const _My& _right)
{
m_vehicle_off -= (vehicleoff)_right;
return (*this);
} vehicleoff operator +(const _My& _right)const
{
return (m_vehicle_off + (vehicleoff)_right);
} _My& operator +=(const _My& _right)
{
m_vehicle_off += (vehicleoff)_right;
return (*this);
} bool operator ==(const _My& _right)const
{
return (m_vehicle_off==(vehicleoff)_right);
} bool operator !=(const _My& _right)const
{
return !(*this==_right);
} private:
vehicleoff m_vehicle_off;
}; struct storage_type
{
typedef unsigned int VEHICLE_TYPE; enum
{
_ISTREAM_TYPE,
_OSTREAM_TYPE, _ISTRING_TYPE,
_OSTRING_TYPE, _WISTREAM_TYPE,
_WOSTREAM_TYPE, _WISTRING_TYPE,
_WOSTRING_TYPE, _IXML_TYPE,
_OXML_TYPE
};
}; template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type> class basic_iarchive_impl;
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type> class basic_oarchive_impl; template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_param_deliverer
{
basic_iarchive_impl<storage_class,_storage_type>* m_bii;
storage_class* _storage;
storagepos* _storage_pos;
}; template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_param_deliverer
{
basic_oarchive_impl<storage_class,_storage_type>* m_boi;
storage_class* _storage;
storagepos* _storage_pos;
}; NAMESPACE_SERIALIZATION_END
#endif
//baisc_from_to_archive.hpp

#ifndef BASIC_ARCHIVE_INCLUDE
#define BASIC_ARCHIVE_INCLUDE #include "archive_config.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class>
class basic_archive; template<typename storage_class>
class basic_archive
{
protected:
storage_class* _storage; // 仓库
storagepos _storage_pos; protected:
basic_archive(const storage_class* sc)
{
_storage = const_cast<storage_class*>(sc);
} basic_archive();
basic_archive(const basic_archive&); public:
virtual ~basic_archive(){}
}; NAMESPACE_SERIALIZATION_END
#endif
// basic_archive.hpp

#ifndef BASIC_ARCHIVE_INCLUDE
#define BASIC_ARCHIVE_INCLUDE #include "archive_config.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class>
class basic_archive; template<typename storage_class>
class basic_archive
{
protected:
storage_class* _storage; // 仓库
storagepos _storage_pos; protected:
basic_archive(const storage_class* sc)
{
_storage = const_cast<storage_class*>(sc);
} basic_archive();
basic_archive(const basic_archive&); public:
virtual ~basic_archive(){}
}; NAMESPACE_SERIALIZATION_END
#endif
// basic_iarchive_impl.hpp

#ifndef BASIC_IARCHIVE_IMPL_INCLUDE
#define BASIC_IARCHIVE_IMPL_INCLUDE #include "basic_archive.hpp"
#include "iarchive_impl_helper.hpp"
#include "archive_config.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class,typename storage_type::VEHICLE_TYPE>
class basic_iarchive_impl; template<typename storage_class,typename storage_type::VEHICLE_TYPE _storage_type>
class basic_iarchive_impl : public basic_archive<storage_class>
{
public: typedef basic_iarchive_impl<storage_class,_storage_type> _My; protected: basic_iarchive_impl(const storage_class& storage)
:basic_archive<storage_class>(&storage){} virtual ~basic_iarchive_impl(){} public: template<typename param_type>
_My& operator &(param_type& param)
{
iarchive_param_deliverer<storage_class,_storage_type> param_helper;
param_helper.m_bii = this;
param_helper._storage = basic_archive<storage_class>::_storage;
param_helper._storage_pos = &(basic_archive<storage_class>::_storage_pos); iarchive_impl_helper<param_type,storage_class,_storage_type> helper(param_helper,param);
return (*this);
} template<typename param_type,int NUM>
_My& operator &(param_type (&param)[NUM])
{
iarchive_param_deliverer<storage_class,_storage_type> param_helper;
param_helper.m_bii = this;
param_helper._storage = basic_archive<storage_class>::_storage;
param_helper._storage_pos = &(basic_archive<storage_class>::_storage_pos); iarchive_impl_helper<param_type(&)[NUM],storage_class,_storage_type> helper(param_helper,param);
return (*this);
} template<typename param_type>
_My& operator >>(param_type& param)
{
(*this)&param;
return (*this);
} template<typename param_type,int NUM>
_My& operator >>(param_type (&param)[NUM])
{
(*this)&param;
return (*this);
} void clear()
{
basic_archive<storage_class>::_storage_pos = (storagepos);
} }; NAMESPACE_SERIALIZATION_END
#endif
// basic_oarchive_impl.hpp

#ifndef BASIC_OARCHIVE_IMPL_INCLUDE
#define BASIC_OARCHIVE_IMPL_INCLUDE #include "basic_archive.hpp"
#include "oarchive_impl_helper.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class, storage_type::VEHICLE_TYPE>
class basic_oarchive_impl; template<typename storage_class,typename storage_type::VEHICLE_TYPE _storage_type>
class basic_oarchive_impl : public basic_archive<storage_class>
{
public: typedef basic_oarchive_impl<storage_class,_storage_type> _My; protected: basic_oarchive_impl(storage_class& storage)
:basic_archive<storage_class>(&storage){} virtual ~basic_oarchive_impl(){} public: template<typename param_type>
_My& operator &(const param_type& param)
{
oarchive_param_deliverer<storage_class,_storage_type> param_helper;
param_helper.m_boi = this;
param_helper._storage = basic_archive<storage_class>::_storage;
param_helper._storage_pos = &(basic_archive<storage_class>::_storage_pos); oarchive_impl_helper<param_type,storage_class,_storage_type> helper(param_helper,param);
return (*this);
} template<typename param_type,int NUM>
_My& operator &(const param_type (&param)[NUM])
{
oarchive_param_deliverer<storage_class,_storage_type> param_helper;
param_helper.m_boi = this;
param_helper._storage = basic_archive<storage_class>::_storage;
param_helper._storage_pos = &(basic_archive<storage_class>::_storage_pos); oarchive_impl_helper<param_type (&)[NUM],storage_class,_storage_type> helper(param_helper,param);
return (*this);
} template<typename param_type>
_My& operator <<(const param_type& param)
{
(*this)&param;
return (*this);
} template<typename param_type,int NUM>
_My& operator <<(const param_type (&param)[NUM])
{
(*this)&param;
return (*this);
}
}; NAMESPACE_SERIALIZATION_END
#endif
// from_archive.hpp

#ifndef FROM_ARCHIVE_INCLUDE
#define FROM_ARCHIVE_INCLUDE #include "archive_config.hpp"
#include "converter/lexical_cast.hpp"
#include "converter/codecvt.hpp" NAMESPACE_SERIALIZATION_BEGIN template<storage_type::VEHICLE_TYPE _type,typename storage_class,typename param_type> struct From_Archive_Helper; template<storage_type::VEHICLE_TYPE _type,typename storage_class,typename param_type>
struct From_Archive_Helper{}; /// istring
template<typename storage_class,typename param_type>
struct From_Archive_Helper<storage_type::_ISTRING_TYPE,storage_class,param_type>
{
From_Archive_Helper(storage_class& storage,param_type& param,storagepos& pos)
{
const char* pstorage = storage.c_str();
pstorage += (int)pos;
converter::lexical_cast<param_type> cast(param,pstorage);
pos +=(storagepos)(cast.length + );
}
}; /// istring
template<typename storage_class>
struct From_Archive_Helper<storage_type::_ISTRING_TYPE,storage_class,std::string>
{
From_Archive_Helper(storage_class& storage,std::string& param,storagepos& pos)
{
const char* pstorage = storage.c_str();
pstorage += (int)pos; // 取大小
unsigned int size = ;
converter::lexical_cast<unsigned int> cast(size,pstorage);
pos +=(storagepos)(cast.length + ); // 取数据
pstorage = storage.c_str();
pstorage += (int)pos;
param.append(pstorage,size);
pos +=(storagepos)(size+);
}
}; /// istring
template<typename storage_class>
struct From_Archive_Helper<storage_type::_ISTRING_TYPE,storage_class,std::wstring>
{
From_Archive_Helper(storage_class& storage,std::wstring& param,storagepos& pos)
{
std::string new_str;
From_Archive_Helper<storage_type::_ISTRING_TYPE,storage_class,std::string>(storage,new_str,pos);
converter::multi_to_utf16(param,new_str);
}
}; /// istring
template<typename storage_class>
struct From_Archive_Helper<storage_type::_ISTRING_TYPE,storage_class,wchar_t>
{
From_Archive_Helper(storage_class& storage,wchar_t& param,storagepos& pos)
{
char c;
From_Archive_Helper<storage_type::_ISTRING_TYPE,storage_class,char>(storage,c,pos); // char 转 wchar_t
std::string str;
str.push_back(c); std::wstring wstr;
converter::multi_to_utf16(wstr,str);
param = wstr.c_str()[];
}
}; /// iwstring
template<typename storage_class,typename param_type>
struct From_Archive_Helper<storage_type::_WISTRING_TYPE,storage_class,param_type>
{
From_Archive_Helper(storage_class& storage,param_type& param,storagepos& pos)
{
const wchar_t* pstorage = storage.c_str();
pstorage += (int)pos;
converter::lexical_cast<param_type> cast(param,pstorage);
pos +=(storagepos)(cast.length + );
}
}; /// iwstring
template<typename storage_class>
struct From_Archive_Helper<storage_type::_WISTRING_TYPE,storage_class,std::wstring>
{
From_Archive_Helper(storage_class& storage,std::wstring& param,storagepos& pos)
{
const wchar_t* pstorage = storage.c_str();
pstorage += (int)pos; // 取大小
unsigned int size = ;
converter::lexical_cast<unsigned int> cast(size,pstorage);
pos +=(storagepos)(cast.length + ); // 取数据
pstorage = storage.c_str();
pstorage += (int)pos;
param.append(pstorage,size);
pos +=(storagepos)(size+);
}
}; /// iwstring
template<typename storage_class>
struct From_Archive_Helper<storage_type::_WISTRING_TYPE,storage_class,std::string>
{
From_Archive_Helper(storage_class& storage,std::string& param,storagepos& pos)
{
std::wstring new_str;
From_Archive_Helper<storage_type::_WISTRING_TYPE,storage_class,std::wstring>(storage,new_str,pos);
converter::utf16_to_multi(param,new_str);
}
}; /// iwstring
template<typename storage_class>
struct From_Archive_Helper<storage_type::_WISTRING_TYPE,storage_class,char>
{
From_Archive_Helper(storage_class& storage,char& param,storagepos& pos)
{
wchar_t c;
From_Archive_Helper<storage_type::_WISTRING_TYPE,storage_class,wchar_t>(storage,c,pos); // wchar_t 转 char
std::wstring wstr;
wstr.push_back(c); std::string str;
converter::utf16_to_multi(str,wstr);
param = str.c_str()[];
}
}; template<typename storage_class,typename param_type>
struct From_Archive_Helper<storage_type::_ISTREAM_TYPE,storage_class,param_type>
{
From_Archive_Helper(storage_class& storage,param_type& param,storagepos& pos)
{
//From_Stream_Archive<storage_class,param_type,storage_type::_ISTREAM_TYPE> from(storage,param,pos);
}
}; template<typename storage_class,typename param_type>
struct From_Archive_Helper<storage_type::_WISTREAM_TYPE,storage_class,param_type>
{
From_Archive_Helper(storage_class& storage,param_type& param,storagepos& pos)
{
//WFrom_Stream_Archive<storage_class,param_type,storage_type::_WISTREAM_TYPE> from(storage,param,pos);
}
}; NAMESPACE_SERIALIZATION_END
#endif
// iarchive_impl_helper.hpp

#ifndef IARCHIVE_IMPL_HELPER_INCLUDE
#define IARCHIVE_IMPL_HELPER_INCLUDE #include "archive_config.hpp" #include "from_archive.hpp"
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include "traits/traits.hpp" NAMESPACE_SERIALIZATION_BEGIN // 自定义
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,param_type& param)
{
param_type& p = const_cast<param_type&>(param);
unsigned int version = SERIALIZATION_VERSION;
p.serialize(*helper.m_bii,version); // archive ,in=true(表示输出还是输入) ,version
}
}; // const 用以报错
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<const param_type,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,const param_type& param)
{
// 不能使用const
param_type p;
param = p;
}
}; // 指针
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<param_type*,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,param_type*& param)
{
unsigned int addr;
From_Archive_Helper<_storage_type,storage_class,unsigned int> f_a_h(*(helper._storage),addr,*helper._storage_pos);
param = traits::pointer_integer_traits<param_type*>(addr);
}
}; // std::string
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::string,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::string& param)
{
From_Archive_Helper<_storage_type,storage_class,std::string> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // std::wstring
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::wstring,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::wstring& param)
{
From_Archive_Helper<_storage_type,storage_class,std::wstring> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // std::list
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::list<param_type>,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::list<param_type>& param)
{
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
param.push_back(p);
}
}
}; // std::vector
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::vector<param_type>,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::vector<param_type>& param)
{
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
param.push_back(p);
}
}
}; // std::stack
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::stack<param_type>,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::stack<param_type>& param)
{
std::stack<param_type> new_param;
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
new_param.push(p);
} while(!new_param.empty())
{
param.push(new_param.top());
new_param.pop();
}
}
}; // std::queue
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::queue<param_type>,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::queue<param_type>& param)
{
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
param.push(p);
}
}
}; // std::map
template<typename param_type,typename param_type2,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::map<param_type,param_type2>,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::map<param_type,param_type2>& param)
{
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
param_type2 p2; iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
iarchive_impl_helper<param_type2,storage_class,_storage_type> impl2(helper,p2); param.insert(std::make_pair(p,p2));
}
}
}; // std::set
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::set<param_type>,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::set<param_type>& param)
{
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
param.insert(p);
}
}
}; // std::multiset
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::multiset<param_type>,storage_class,_storage_type>
{
inline iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::multiset<param_type>& param)
{
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
param.insert(p);
}
}
}; // std::multimap
template<typename param_type,typename param_type2,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<std::multimap<param_type,param_type2>,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,std::multimap<param_type,param_type2>& param)
{
unsigned int size = ;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=; i<size; ++i)
{
param_type p;
param_type2 p2; iarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,p);
iarchive_impl_helper<param_type2,storage_class,_storage_type> impl2(helper,p2); param.insert(std::make_pair(p,p2));
}
}
}; // 数组
template<typename param_type,int NUM,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<param_type(&)[NUM],storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,param_type (&param)[NUM])
{
unsigned int size = ;
From_Archive_Helper<_storage_type,storage_class,unsigned int> f_a_h(*helper._storage,size,*helper._storage_pos);
for (unsigned int i=; i<size; ++i)
From_Archive_Helper<_storage_type,storage_class,param_type> f_a_h(*helper._storage,param[i],*helper._storage_pos);
}
}; // char
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<unsigned char,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,unsigned char& param)
{
From_Archive_Helper<_storage_type,storage_class,unsigned char> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // unsigned char
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<char,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,char& param)
{
From_Archive_Helper<_storage_type,storage_class,char> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // wchar_t
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<wchar_t,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,wchar_t& param)
{
From_Archive_Helper<_storage_type,storage_class,wchar_t> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // float
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<float,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,float& param)
{
From_Archive_Helper<_storage_type,storage_class,float> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // double
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<double,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,double& param)
{
From_Archive_Helper<_storage_type,storage_class,double> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // int
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<int,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,int& param)
{
From_Archive_Helper<_storage_type,storage_class,int> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // unsigned int
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<unsigned int,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,unsigned int& param)
{
From_Archive_Helper<_storage_type,storage_class,unsigned int> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // long
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<long,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,long& param)
{
From_Archive_Helper<_storage_type,storage_class,long> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // unsigned long
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<unsigned long,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,unsigned long& param)
{
From_Archive_Helper<_storage_type,storage_class,unsigned long> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // _int64_
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<_int64_,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,_int64_& param)
{
From_Archive_Helper<_storage_type,storage_class,_int64_> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // _uint64_
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<_uint64_,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,_uint64_& param)
{
From_Archive_Helper<_storage_type,storage_class,_uint64_> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // short
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<short,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,short& param)
{
From_Archive_Helper<_storage_type,storage_class,short> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // unsigned short
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<unsigned short,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,unsigned short& param)
{
From_Archive_Helper<_storage_type,storage_class,unsigned short> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; // bool
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct iarchive_impl_helper<bool,storage_class,_storage_type>
{
iarchive_impl_helper(iarchive_param_deliverer<storage_class,_storage_type>& helper,bool& param)
{
From_Archive_Helper<_storage_type,storage_class,bool> f_a_h(*helper._storage,param,*helper._storage_pos);
}
}; NAMESPACE_SERIALIZATION_END
#endif
// oarchive_impl_helper.hpp

#ifndef OARCHIVE_IMPL_HELPER_INCLUDE
#define OARCHIVE_IMPL_HELPER_INCLUDE #include "archive_config.hpp"
#include "to_archive.hpp"
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include "traits/traits.hpp" NAMESPACE_SERIALIZATION_BEGIN // 自定义
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const param_type& param)
{
param_type& p = const_cast<param_type&>(param);
unsigned int version = SERIALIZATION_VERSION;
p.serialize(*helper.m_boi,version);//archive ,out=false ,version
}
}; // 指针
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<param_type*,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const param_type* param)
{
// 序列化指针指向的地址
unsigned int addr = traits::pointer_integer_traits<unsigned int>(param);
To_Archive_Helper<_storage_type,storage_class,unsigned int> t_a_h(*(helper._storage),addr);
}
}; /////////for stl // std::string
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::string,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::string& param)
{
To_Archive_Helper<_storage_type,storage_class,std::string> t_a_h(*(helper._storage),param);
}
}; /// std::wstring
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::wstring,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::wstring& param)
{
To_Archive_Helper<_storage_type,storage_class,std::wstring> t_a_h(*(helper._storage),param);
}
}; /// std::list
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::list<param_type>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::list<param_type>& param)
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)param.size());
for (typename std::list<param_type>::const_iterator iter=param.begin(); iter!=param.end(); ++iter)
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)(*iter));
}
}; /// std::vector
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::vector<param_type>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::vector<param_type>& param)
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)param.size());
for (typename std::vector<param_type>::const_iterator iter=param.begin(); iter!=param.end(); ++iter)
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)(*iter));
}
}; /// std::stack
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::stack<param_type>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::stack<param_type>& param)
{
std::stack<param_type> new_param = param;
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)new_param.size());
while(!new_param.empty())
{
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)new_param.top());
new_param.pop();
}
}
}; /// std::queue
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::queue<param_type>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::queue<param_type>& param)
{
std::queue<param_type> new_param = param;
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)new_param.size());
while(!new_param.empty())
{
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)new_param.front());
new_param.pop();
}
}
}; /// std::map
template<typename param_type,typename param_type2,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::map<param_type,param_type2>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::map<param_type,param_type2>& param)
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)param.size());
for (typename std::map<param_type,param_type2>::const_iterator iter=param.begin();iter!=param.end(); ++iter)
{
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)(iter->first));
oarchive_impl_helper<param_type2,storage_class,_storage_type> impl2(helper,(param_type2)(iter->second));
}
}
}; /// std::Set
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::set<param_type>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::set<param_type>& param)
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)param.size());
for (typename std::set<param_type>::const_iterator iter=param.begin(); iter!=param.end(); ++iter)
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)(*iter));
}
}; /// std::multiset
template<typename param_type,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::multiset<param_type>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::multiset<param_type>& param)
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)param.size());
for (typename std::set<param_type>::const_iterator iter=param.begin(); iter!=param.end(); ++iter)
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)(*iter));
}
}; /// std::multimap
template<typename param_type,typename param_type2,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<std::multimap<param_type,param_type2>,storage_class,_storage_type>
{
inline oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const std::multimap<param_type,param_type2>& param)
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)param.size());
for (typename std::multimap<param_type,param_type2>::const_iterator iter=param.begin();iter!=param.end(); ++iter)
{
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,(param_type)(iter->first));
oarchive_impl_helper<param_type2,storage_class,_storage_type> impl2(helper,(param_type2)(iter->second));
}
}
}; ///////////////////// stl end ////////////////// /// array
template<typename param_type,unsigned int NUM,typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<param_type(&)[NUM],storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const param_type (&param)[NUM])
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)NUM);
for (unsigned int i=; i<NUM; ++i)
oarchive_impl_helper<param_type,storage_class,_storage_type> impl(helper,param[i]);
}
}; /// char
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<char,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const char& param)
{
To_Archive_Helper<_storage_type,storage_class,char> t_a_h(*helper._storage,param);
}
}; /// unsigned char
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<unsigned char,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const unsigned char& param)
{
To_Archive_Helper<_storage_type,storage_class,unsigned char> t_a_h(*helper._storage,param);
}
}; /// wchar_t
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<wchar_t,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const wchar_t& param)
{
To_Archive_Helper<_storage_type,storage_class,wchar_t> t_a_h(*helper._storage,param);
}
}; /// float
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<float,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const float& param)
{
To_Archive_Helper<_storage_type,storage_class,float> t_a_h(*helper._storage,param);
}
}; /// double
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<double,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const double& param)
{
To_Archive_Helper<_storage_type,storage_class,double> t_a_h(*helper._storage,param);
}
}; /// int
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<int,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const int& param)
{
To_Archive_Helper<_storage_type,storage_class,int> t_a_h(*helper._storage,param);
}
}; /// unsigned int
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<unsigned int,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const unsigned int& param)
{
To_Archive_Helper<_storage_type,storage_class,unsigned int> t_a_h(*helper._storage,param);
}
}; /// long
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<long,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const long& param)
{
To_Archive_Helper<_storage_type,storage_class,long> t_a_h(*helper._storage,param);
}
}; /// unsigned long
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<unsigned long,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const unsigned long& param)
{
To_Archive_Helper<_storage_type,storage_class,unsigned long> t_a_h(*helper._storage,param);
}
}; /// _uint64_
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<_uint64_,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const _uint64_& param)
{
To_Archive_Helper<_storage_type,storage_class,_uint64_> t_a_h(*helper._storage,param);
}
}; /// _int64_
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<_int64_,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const _int64_& param)
{
To_Archive_Helper<_storage_type,storage_class,_int64_> t_a_h(*helper._storage,param);
}
}; /// short
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<short,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const short& param)
{
To_Archive_Helper<_storage_type,storage_class,short> t_a_h(*helper._storage,param);
}
}; /// unsigned short
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<unsigned short,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const unsigned short& param)
{
To_Archive_Helper<_storage_type,storage_class,unsigned short> t_a_h(*helper._storage,param);
}
}; /// bool
template<typename storage_class,storage_type::VEHICLE_TYPE _storage_type>
struct oarchive_impl_helper<bool,storage_class,_storage_type>
{
oarchive_impl_helper(oarchive_param_deliverer<storage_class,_storage_type>& helper,const bool& param)
{
To_Archive_Helper<_storage_type,storage_class,bool> t_a_h(*helper._storage,param);
}
}; NAMESPACE_SERIALIZATION_END
#endif
// stream_archive.hpp

#ifndef STREAM_ARCHIVE_INCLUDE
#define STREAM_ARCHIVE_INCLUDE #include "archive_config.hpp"
#include "basic_iarchive_impl.hpp"
#include "basic_oarchive_impl.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class> class stream_iarchive;
template<typename storage_class> class stream_oarchive; //Vehicle_Class 遵循的是流的标准
template<typename storage_class>
class stream_iarchive : public basic_iarchive_impl<storage_class,storage_type::_ISTREAM_TYPE>
{
public: stream_iarchive(const storage_class& storage)
:basic_iarchive_impl<storage_class,storage_type::_ISTREAM_TYPE>(storage){} ~stream_iarchive(){} }; template<typename storage_class>
class stream_oarchive : public basic_oarchive_impl<storage_class,storage_type::_OSTREAM_TYPE>
{
public: stream_oarchive(storage_class& storage)
:basic_oarchive_impl<storage_class,storage_type::_OSTREAM_TYPE>(storage){} ~stream_oarchive(){}
}; NAMESPACE_SERIALIZATION_END
#endif
// string_archive.hpp

#ifndef STRING_ARCHIVE_INCLUDE
#define STRING_ARCHIVE_INCLUDE #include "archive_config.hpp"
#include "basic_iarchive_impl.hpp"
#include "basic_oarchive_impl.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class> class string_iarchive;
template<typename storage_class> class string_oarchive; template<typename storage_class>
class string_iarchive : public basic_iarchive_impl<storage_class,storage_type::_ISTRING_TYPE>
{
public: string_iarchive(const storage_class& storage)
:basic_iarchive_impl<storage_class,storage_type::_ISTRING_TYPE>(storage){} ~string_iarchive(){}
}; template<typename storage_class>
class string_oarchive : public basic_oarchive_impl<storage_class,storage_type::_OSTRING_TYPE>
{
public: string_oarchive(storage_class& storage)
:basic_oarchive_impl<storage_class,storage_type::_OSTRING_TYPE>(storage){} ~string_oarchive(){}
}; NAMESPACE_SERIALIZATION_END
#endif
// to_archive.hpp

#ifndef TO_ARCHIVE_INCLUDE
#define TO_ARCHIVE_INCLUDE #include "archive_config.hpp"
#include "converter/lexical_cast.hpp"
#include "converter/codecvt.hpp" NAMESPACE_SERIALIZATION_BEGIN template<storage_type::VEHICLE_TYPE _type,typename storage_class,typename param_type> struct To_Archive_Helper; template<storage_type::VEHICLE_TYPE _type,typename storage_class,typename param_type>
struct To_Archive_Helper{}; // ostring
template<typename storage_class,typename param_type>
struct To_Archive_Helper<storage_type::_OSTRING_TYPE,storage_class,param_type>
{
To_Archive_Helper(storage_class& storage,const param_type& param)
{
converter::lexical_cast<storage_class>(storage,param,true);
storage.append(" ");
}
}; // ostring
template<typename storage_class>
struct To_Archive_Helper<storage_type::_OSTRING_TYPE,storage_class,std::string>
{
To_Archive_Helper(storage_class& storage,const std::string& param)
{
converter::lexical_cast<storage_class>(storage,(unsigned int)(param.length()),true);
storage.append(" ");
converter::lexical_cast<storage_class>(storage,param,true);
storage.append(" ");
}
}; // ostring
template<typename storage_class>
struct To_Archive_Helper<storage_type::_OSTRING_TYPE,storage_class,std::wstring>
{
To_Archive_Helper(storage_class& storage,const std::wstring& param)
{
std::string new_str;
converter::utf16_to_multi(new_str,param);
To_Archive_Helper<storage_type::_OSTRING_TYPE,storage_class,std::string>(storage,new_str);
}
}; // ostring
template<typename storage_class>
struct To_Archive_Helper<storage_type::_OSTRING_TYPE,storage_class,wchar_t>
{
To_Archive_Helper(storage_class& storage,const wchar_t& param)
{
// wchar 转 char
std::wstring wstr;
wstr.push_back(param); std::string str;
converter::utf16_to_multi(str,wstr);
char c = str.c_str()[]; To_Archive_Helper<storage_type::_OSTRING_TYPE,storage_class,char>(storage,c);
}
}; // owstring
template<typename storage_class,typename param_type>
struct To_Archive_Helper<storage_type::_WOSTRING_TYPE,storage_class,param_type>
{
To_Archive_Helper(storage_class& storage,const param_type& param)
{
converter::lexical_cast<storage_class>(storage,param,true);
storage.append(L" ");
}
}; // owstring
template<typename storage_class>
struct To_Archive_Helper<storage_type::_WOSTRING_TYPE,storage_class,std::wstring>
{
To_Archive_Helper(storage_class& storage,const std::wstring& param)
{
converter::lexical_cast<storage_class>(storage,(unsigned int)(param.length()),true);
storage.append(L" ");
converter::lexical_cast<storage_class>(storage,param,true);
storage.append(L" ");
}
}; // owstring
template<typename storage_class>
struct To_Archive_Helper<storage_type::_WOSTRING_TYPE,storage_class,std::string>
{
To_Archive_Helper(storage_class& storage,const std::string& param)
{
std::wstring new_str;
converter::multi_to_utf16(new_str,param);
To_Archive_Helper<storage_type::_WOSTRING_TYPE,storage_class,std::wstring>(storage,new_str);
}
}; // owstring
template<typename storage_class>
struct To_Archive_Helper<storage_type::_WOSTRING_TYPE,storage_class,char>
{
To_Archive_Helper(storage_class& storage,const char& param)
{
// char 转 wchar_t
std::string str;
str.push_back(param); std::wstring wstr;
converter::multi_to_utf16(wstr,str);
wchar_t c = wstr.c_str()[]; To_Archive_Helper<storage_type::_WOSTRING_TYPE,storage_class,wchar_t>(storage,c);
}
}; // ostream
template<typename storage_class,typename param_type>
struct To_Archive_Helper<storage_type::_OSTREAM_TYPE,storage_class,param_type>
{
To_Archive_Helper(storage_class& storage,const param_type& param)
{ }
}; // owstream
template<typename storage_class,typename param_type>
struct To_Archive_Helper<storage_type::_WOSTREAM_TYPE,storage_class,param_type>
{
To_Archive_Helper(storage_class& storage,const param_type& param)
{
//WTo_Stream_Archive<storage_class,param_type,storage_type::_WOSTREAM_TYPE> to(storage,param);
}
}; NAMESPACE_SERIALIZATION_END
#endif
// wstream_archive.hpp
#ifndef WSTREAM_ARCHIVE_INCLUDE
#define WSTREAM_ARCHIVE_INCLUDE #include "archive_config.hpp"
#include "basic_iarchive_impl.hpp"
#include "basic_oarchive_impl.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class> class wstream_iarchive;
template<typename storage_class> class wstream_oarchive; template<typename storage_class>
class wstream_iarchive : public basic_iarchive_impl<storage_class,storage_type::_WISTREAM_TYPE>
{
public: wstream_iarchive(const storage_class& storage)
:basic_iarchive_impl<storage_class,storage_type::_WISTREAM_TYPE>(storage){} ~wstream_iarchive(){} }; template<typename storage_class>
class wstream_oarchive : public basic_oarchive_impl<storage_class,storage_type::_WOSTREAM_TYPE>
{
public: wstream_oarchive(storage_class& storage)
:basic_oarchive_impl<storage_class,storage_type::_WOSTREAM_TYPE>(storage){
} ~wstream_oarchive(){} }; NAMESPACE_SERIALIZATION_END
#endif
// wstring_archive.hpp
#ifndef WSTRING_ARCHIVE_INCLUDE
#define WSTRING_ARCHIVE_INCLUDE #include "archive_config.hpp"
#include "basic_iarchive_impl.hpp"
#include "basic_oarchive_impl.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class> class wstring_iarchive;
template<typename storage_class> class wstring_oarchive; // from
template<typename storage_class>
class wstring_iarchive : public basic_iarchive_impl<storage_class,storage_type::_WISTRING_TYPE>
{
public:
wstring_iarchive(const storage_class& storage)
:basic_iarchive_impl<storage_class,storage_type::_WISTRING_TYPE>(storage){} ~wstring_iarchive(){}
}; /// to
template<typename storage_class>
class wstring_oarchive : public basic_oarchive_impl<storage_class,storage_type::_WOSTRING_TYPE>
{
public:
wstring_oarchive(storage_class& storage)
:basic_oarchive_impl<storage_class,storage_type::_WOSTRING_TYPE>(storage){} ~wstring_oarchive(){}
}; NAMESPACE_SERIALIZATION_END
#endif
//xml_archive.hpp
#ifndef XML_ARCHIVE_INCLUDE
#define XML_ARCHIVE_INCLUDE #include "archive_config.hpp" NAMESPACE_SERIALIZATION_BEGIN template<typename storage_class> class xml_iarchive;
template<typename storage_class> class xml_oarchive; template<typename storage_class>
class xml_iarchive : public basic_iarchive_impl<storage_class,storage_type::_IXML_TYPE>
{
public: xml_iarchive(const storage_class& storage)
:basic_iarchive_impl<storage_class,storage_type::_IXML_TYPE>(storage){} ~xml_iarchive(){} }; template<typename storage_class>
class xml_oarchive : public basic_oarchive_impl<storage_class,storage_type::_OXML_TYPE>
{
public: xml_oarchive(storage_class& storage)
:basic_oarchive_impl<storage_class,storage_type::_OXML_TYPE>(storage){} ~xml_oarchive(){}
}; NAMESPACE_SERIALIZATION_END
#endif
上一篇:JAVA并发编程学习笔记------协作对象之间发生的死锁


下一篇:【selenium+python】之Python Flask 开发环境搭建(Windows)