C++序列化库的实现(5)

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4027141282656c44471a7b6eeb1dc451.html