How to select the name of class definition instead of variable name in XML archive

In following code - archive results in tag name as T as T is used in BOOST_SERIALIZATION_NVP(T) statement. Instead I want actual type name for T, instead of just T as Tag name, how to achieve this ??? template<class T> void Serialize(const char * filename) { std::ofstream ofs(filename); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(T); ofs.close(); }

People have asked this before, its really needed, but as far as anyone knows, there is no portable way to do this. Depending on your needs type_id might return a string you can use. Robert Ramey "Piyush Kapadia" <piyush.kapadia@gmail.com> wrote in message news:435aa424.08d6201b.180b.68ff@mx.gmail.com... In following code - archive results in tag name as T as T is used in BOOST_SERIALIZATION_NVP(T) statement. Instead I want actual type name for T, instead of just T as Tag name, how to achieve this ??? template<class T> void Serialize(const char * filename) { std::ofstream ofs(filename); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(T); ofs.close(); } ------------------------------------------------------------------------------ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

So instead of oa << BOOST_SERIALIZATION_NVP(T); can we use following to have type name printed in xml file ? oa << boost::serialization::make_nvp(typeid(T).name(), T); _____ From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Saturday, October 22, 2005 8:40 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] How to select the name of class definitioninstead ofvariable name in XML archive People have asked this before, its really needed, but as far as anyone knows, there is no portable way to do this. Depending on your needs type_id might return a string you can use. Robert Ramey "Piyush Kapadia" <piyush.kapadia@gmail.com> wrote in message news:435aa424.08d6201b.180b.68ff@mx.gmail.com... In following code - archive results in tag name as T as T is used in BOOST_SERIALIZATION_NVP(T) statement. Instead I want actual type name for T, instead of just T as Tag name, how to achieve this ??? template<class T> void Serialize(const char * filename) { std::ofstream ofs(filename); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(T); ofs.close(); } _____ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Something like this might be made to work. Be aware that the tag name will vary across compilers. For the serialization system this won't be problem as the tag name really isn't used for anything. But, depending on what you plan to use the tag name for, this might or might not be a problem. Robert Ramey "Piyush Kapadia" <piyush.kapadia@gmail.com> wrote in message news:435b6d4a.334ce710.5f89.ffffb4c0@mx.gmail.com... So instead of oa << BOOST_SERIALIZATION_NVP(T); can we use following to have type name printed in xml file ? oa << boost::serialization::make_nvp(typeid(T).name(), T); ------------------------------------------------------------------------------ From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Saturday, October 22, 2005 8:40 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] How to select the name of class definitioninstead ofvariable name in XML archive People have asked this before, its really needed, but as far as anyone knows, there is no portable way to do this. Depending on your needs type_id might return a string you can use. Robert Ramey "Piyush Kapadia" <piyush.kapadia@gmail.com> wrote in message news:435aa424.08d6201b.180b.68ff@mx.gmail.com... In following code - archive results in tag name as T as T is used in BOOST_SERIALIZATION_NVP(T) statement. Instead I want actual type name for T, instead of just T as Tag name, how to achieve this ??? template<class T> void Serialize(const char * filename) { std::ofstream ofs(filename); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(T); ofs.close(); } ---------------------------------------------------------------------------- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users ------------------------------------------------------------------------------ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

This only works for a small subset of typeid names since many of them are not valid XML tags (for one thing any template class cannot be used). And you really do not wan to leave out the variable name. I really think the library should provide an archive OPTION to include the typename enclosed in quotations (preferrably, primitive types should have this options too). Sean ----- Original Message ----- From: Robert Ramey To: boost-users@lists.boost.org Sent: Sunday, October 23, 2005 11:44 AM Subject: Re: [Boost-users] How to select the name of classdefinitioninsteadofvariable name in XML archive Something like this might be made to work. Be aware that the tag name will vary across compilers. For the serialization system this won't be problem as the tag name really isn't used for anything. But, depending on what you plan to use the tag name for, this might or might not be a problem. Robert Ramey "Piyush Kapadia" <piyush.kapadia@gmail.com> wrote in message news:435b6d4a.334ce710.5f89.ffffb4c0@mx.gmail.com... So instead of oa << BOOST_SERIALIZATION_NVP(T); can we use following to have type name printed in xml file ? oa << boost::serialization::make_nvp(typeid(T).name(), T);
participants (3)
-
Piyush Kapadia
-
Robert Ramey
-
Sean Huang