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; // 編號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 0;
}
接下來是完整庫截圖
// 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=0):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 (¶m)[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)¶m;
return (*this);
}
template<typename param_type,int NUM>
_My& operator >>(param_type (¶m)[NUM])
{
(*this)¶m;
return (*this);
}
void clear()
{
basic_archive<storage_class>::_storage_pos = (storagepos)0;
}
};
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 (¶m)[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)¶m;
return (*this);
}
template<typename param_type,int NUM>
_My& operator <<(const param_type (¶m)[NUM])
{
(*this)¶m;
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 + 1);
}
};
/// 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 = 0;
converter::lexical_cast<unsigned int> cast(size,pstorage);
pos +=(storagepos)(cast.length + 1);
// 取數據
pstorage = storage.c_str();
pstorage += (int)pos;
param.append(pstorage,size);
pos +=(storagepos)(size+1);
}
};
/// 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()[0];
}
};
/// 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 + 1);
}
};
/// 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 = 0;
converter::lexical_cast<unsigned int> cast(size,pstorage);
pos +=(storagepos)(cast.length + 1);
// 取數據
pstorage = storage.c_str();
pstorage += (int)pos;
param.append(pstorage,size);
pos +=(storagepos)(size+1);
}
};
/// 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()[0];
}
};
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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 = 0;
iarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,size);
for (unsigned int i=0; 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 (¶m)[NUM])
{
unsigned int size = 0;
From_Archive_Helper<_storage_type,storage_class,unsigned int> f_a_h(*helper._storage,size,*helper._storage_pos);
for (unsigned int i=0; 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 (¶m)[NUM])
{
oarchive_impl_helper<unsigned int,storage_class,_storage_type> impl(helper,(unsigned int)NUM);
for (unsigned int i=0; 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()[0];
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()[0];
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