I have made the below changes to have customised names for tags. And the below code changes worked successfully and i could create a xml doc with customised names.
namespace boost { namespace serialization {
template <typename Ar>
void serialize(Ar& ar,std::pair<int const , Myclass::Pgroups>& p, unsigned) {
ar & make_nvp("assetid", p.first) & make_nvp("assetdata", p.second);
}
} }
namespace boost { namespace serialization {
template <typename Ar>
void serialize(Ar& ar,std::pair<int const , values>& p, unsigned) {
ar & make_nvp("hacc_groupid", p.first) & make_nvp("hacc_groupdata", p.second);
}
} }
But this seems to be a problem deserialising the xml to the object, i get boost error
template<class Archive, class Object>
std::string serialise_to_string(const char* tag,Object & obj)
{
std::ostringstream os (std::ios::binary);
Archive arch ( os );
arch << boost::serialization::make_nvp(tag,obj);
return os.str();
}
template<class Archive , class Object>
void deserialise_to_obj( std::string const &s1,Object &outObj)
{
std::stringstream is( s1, std::ios_base::binary| std::ios_base::out| std::ios_base::in);
Archive arch (is);
arch >> boost::serialization::make_nvp("tag",outObj);
};
Without boost namespace customisation the serialisation and deserialisation are perfectly working , but with change in boost namespace for having customised tag names , the deserialisation has issue .
Error with the above code , i.e with const in namespace argvoid serialize(Ar& ar,std::pair<int const , values>& p, unsigned)
In file included from main.cpp:1:
In file included from /usr/local/include/boost/archive/binary_oarchive.hpp:21:
In file included from /usr/local/include/boost/archive/binary_oarchive_impl.hpp:22:
In file included from /usr/local/include/boost/archive/basic_binary_oarchive.hpp:33:
In file included from /usr/local/include/boost/archive/detail/common_oarchive.hpp:22:
In file included from /usr/local/include/boost/archive/detail/interface_oarchive.hpp:23:
In file included from /usr/local/include/boost/archive/detail/oserializer.hpp:68:
/usr/local/include/boost/archive/detail/check.hpp:162:5: error: static_assert failed "typex::value"
BOOST_STATIC_ASSERT(typex::value);
^ ~~~~~~~~~~~~
/usr/local/include/boost/static_assert.hpp:70:41: note: expanded from macro 'BOOST_STATIC_ASSERT'
# define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
^ ~~~~~~~~~~~
/usr/local/include/boost/archive/detail/iserializer.hpp:603:13: note: in instantiation of function template specialization 'boost::archive::detail::check_const_loading<const int>' requested here
detail::check_const_loading< T >();
^
/usr/local/include/boost/archive/detail/common_iarchive.hpp:66:18: note: in instantiation of function template specialization 'boost::archive::load<boost::archive::xml_iarchive, const int>' requested here
archive::load(* this->This(), t);
^
/usr/local/include/boost/archive/basic_xml_iarchive.hpp:78:39: note: in instantiation of function template specialization 'boost::archive::detail::common_iarchive<boost::archive::xml_iarchive>::load_override<const int>' requested here
this->detail_common_iarchive::load_override(t.value());
^
/usr/local/include/boost/archive/xml_iarchive.hpp:95:38: note: in instantiation of function template specialization 'boost::archive::basic_xml_iarchive<boost::archive::xml_iarchive>::load_override<const int>' requested here
basic_xml_iarchive<Archive>::load_override(t);
^
/usr/local/include/boost/archive/detail/interface_iarchive.hpp:68:23: note: in instantiation of function template specialization 'boost::archive::xml_iarchive_impl<boost::archive::xml_iarchive>::load_override<const boost::serialization::nvp<const int> >' requested here
this->This()->load_override(t);
^
/usr/local/include/boost/archive/detail/interface_iarchive.hpp:75:32: note: (skipping 45 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
return *(this->This()) >> t;
^
/usr/local/include/boost/archive/basic_xml_iarchive.hpp:78:39: note: in instantiation of function template specialization 'boost::archive::detail::common_iarchive<boost::archive::xml_iarchive>::load_override<Myclass>' requested here
this->detail_common_iarchive::load_override(t.value());
^
/usr/local/include/boost/archive/xml_iarchive.hpp:95:38: note: in instantiation of function template specialization 'boost::archive::basic_xml_iarchive<boost::archive::xml_iarchive>::load_override<Myclass>' requested here
basic_xml_iarchive<Archive>::load_override(t);
^
/usr/local/include/boost/archive/detail/interface_iarchive.hpp:68:23: note: in instantiation of function template specialization 'boost::archive::xml_iarchive_impl<boost::archive::xml_iarchive>::load_override<const boost::serialization::nvp<Myclass> >' requested here
this->This()->load_override(t);
If const-ness is removed from the boost namespace , deserialise_to_obj and serialise_to_string functions ,the code compiles and runs without any issue but doesn't customise the tag name
Hope my information is clear, Iam stuck at an issue where iam really not sure whether the deserialisation to object can smoothly happen with customised tag names. Please advice me what has to be done
Sample code foe serialisation and deserialisation with custom tag names live at coliru
sample working code without deserialzation and custom tag names live at coliru
Thanks Tejas