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

/// 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(" ");
    }
};

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

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