I plan to create my own archive, for example boost :: archive :: xml_oachive, and I found good examples in the boost / libs / serialization / example folder.
See the following code (in the directory above):
...
class simple_log_archive
{
...
template <class Archive>
struct save_primitive
{
template <class T>
static void invoke(Archive& ar, const T& t)
{
}
};
template <class Archive>
struct save_only
{
template <class T>
static void invoke(Archive& ar, const T& t)
{
boost::serialization::serialize_adl(ar, const_cast<T&>(t),
::boost::serialization::version<T>::value);
}
};
template <class T>
void save(const T& t)
{
typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<boost::is_enum<T>,
boost::mpl::identity<save_enum_type<simple_log_archive> >,
BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<
boost::mpl::equal_to<
boost::serialization::implementation_level<T>,
boost::mpl::int_<boost::serialization::primitive_type>
>,
boost::mpl::identity<save_primitive<simple_log_archive> >,
boost::mpl::identity<save_only<simple_log_archive> >
> >::type typex;
typex::invoke(*this, t);
}
public:
template<class T>
simple_log_archive & operator<<(T const & t){
m_os << ' ';
save(t);
return * this;
}
template<class T>
simple_log_archive & operator<<(T * const t){
m_os << " ->";
if(NULL == t)
m_os << " null";
else
*this << * t;
return * this;
}
...
};
In the same way, I created my own archive. But my code and above is not automatically casting a base pointer to a derived pointer. For instance,
Base* base = new Derived;
{
boost::archive::text_oarchive ar(std::cout);
ar << base;
}
{
simple_log_archive ar;
ar << base;
}
could you help me? How to get a base pointer to a derived pointer?
source
share