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

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

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

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