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

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

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

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