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 ;
}

接下来是完整库截图

// 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

C++序列化库的实现的更多相关文章

  1. cereal:C++实现的开源序列化库

    闲来无事发现了一个基于C++实现的序列化工具,相比于其他(比如Boost serialization或Google protobuf,恰巧都用过,以后再介绍),使用简单,感觉不错,下面做个摸索. ce ...

  2. 除了cPickle,cjson外还有没有更高效点的序列化库了

    除了cPickle,cjson外还有没有更高效点的序列化库了 http://blog.csdn.net/chen_lovelotus/article/details/7228745 msgpack最快 ...

  3. #华为云·寻找黑马程序员# 如何实现一个优雅的Python的Json序列化库

    在Python的世界里,将一个对象以json格式进行序列化或反序列化一直是一个问题.Python标准库里面提供了json序列化的工具,我们可以简单的用json.dumps来将一个对象序列化.但是这种序 ...

  4. 性能超四倍的高性能.NET二进制序列化库

    二进制序列化在.NET中有很多使用场景,如我们使用分布式缓存时,通常将缓存对象序列化为二进制数据进行缓存,在ASP.NET中,很多中间件(如认证等)也都是用了二进制序列化. 在.NET中我们通常使用S ...

  5. 序列化库MessagePack应用(C++)

    介绍 MessagePack(简称msgpack)是一个小巧而高效的序列化/反序列化库,支持多种开发语言.官方网站:http://msgpack.org/ . 下面是官方的一个简介: It's lik ...

  6. c# 开发可替换的通用序列化库

    开篇继续吹牛.... 其实没有什么可吹的了,哈哈哈哈哈 主要是写一个通用库,既可以直接用,又方便替换,我的序列化都是采用第三方的哈. 我不上完整代码了,只是给大家讲讲过程. 1.写一个序列化的类,我是 ...

  7. Google序列化库FlatBuffers 1.1发布,及与protobuf的比较

    个人总结: FlatBuffer相对于Protobuffer来讲,优势如下: 1. 由于省去了编解码的过程,所以从速度上快于Protobuffer,个人测试结果100w次编解码,编码上FlatBuff ...

  8. Swifter.Json 可能是 .Net 平台迄今为止性能最佳的 Json 序列化库【开源】

    Json 简介 Json (JavaScript Object Notation) 是一种轻量级的数据交换格式.它作为目前最欢迎的数据交换格式,也是各大开源贡献者的必争之地,如:阿里爸爸的 fastj ...

  9. Microsoft开源跨平台的序列化库——Bond

    上个月Microsoft开源了Bond,一个跨平台的模式化数据处理框架.Bond支持跨语言的序列化/反序列化,支持强大的泛型机制能够对数据进行有效地处理.该框架在Microsoft公司内部的高扩展服务 ...

随机推荐

  1. [FJSC2014]异或之

    [题目描述] 给定n个非负整数A[1], A[2], ……, A[n]. 对于每对(i, j)满足1 <= i < j <= n,得到一个新的数A[i] xor A[j],这样共有n ...

  2. 把这两天遇到的码(e)农(xin)题记下来

    1019: [SHOI2008]汉诺塔 1858: [Scoi2010]序列操作 1058: [ZJOI2007]报表统计

  3. unity3d 制造自己的水体water effect(一)

    first,I wish you a happy new year, and study in spring festival’s eve means you are hardworking,haha ...

  4. Java第一次写的流布局图形界面,留个纪念

    package jisuanqi; import java.awt.*; public class MyFrame extends Frame{ //继承Frame类 public MyFrame() ...

  5. Java IO复习(一)

    package com.zyw.file; import java.io.*; /** * Created by zyw on 2016/3/10. */ public class IOTest { ...

  6. HDU 1502 Regular Words DP+高精度

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1502 题目大意:找出总的满足条件的字符串数,num(a)=num(b)=num(c)且任何前缀均满足n ...

  7. VMware虚拟机里Ubuntu14.04下安装及配置MySQL

    更新源列表 快捷键"Ctrl+Alt+t"打开"Terminal终端窗口",输入"sudo apt-get update"-->回车- ...

  8. 什么要缓存curl资源

    在看公司的代码框架底层时,发现了一个问题,如下: 代码中调用接口时,使用的是curl,框架将curl资源以IP :端口的形式缓存了下来,例如: 10.10.10.10:80     curl1 10. ...

  9. 【基础】多线程更新窗体UI的若干方法

    一.前言 在单线程中设置窗体某个控件的值很简单的事,只需要设置控件文本的值就可以了,但是有的业务场景很是复杂,界面上的控件也很多,这种情况下当数据量比较多的时候,在单线程中更新UI不可避免地会发生假死 ...

  10. 【Android - 框架】之Retrofit+RxJava的使用

    前几天分别对Retrofit和RxJava进行了总结,这个帖子打算把Retrofit结合RxJava使用的方法总结以下.有还不了解Retrofit或RxJava的朋友可以参考下面的帖子学习~ [And ...