CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    boost::serialization with boost::any

    Hi there.

    Has any of you found a generic method of making boost::any serializable? The net doesn't provide anything more than a couple of unfinished ideas, as far as I have searched.

    Exampla code:
    Code:
    #include <boost/any.hpp>
    #include <boost/config.hpp>
    #include <boost/archive/xml_iarchive.hpp>
    #include <boost/archive/xml_oarchive.hpp>
    
    int main()
    {
       boost::any a;
       a = ...[insert some value here];
       std::ofstream ofs("C:\\fiel.xml");
       boost::archive::xml_oarchive oa(ofs);
       oa << BOOST_SERIALIZATION_NVP(a);
       return 0;
    }
    Of course, one could modify boost::any. That's not my first option, to be honest.

    Any ideas, thoughts?
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  2. #2
    Join Date
    Feb 2006
    Location
    London
    Posts
    238

    Re: boost::serialization with boost::any

    Boost serialisation does provide means of serialising objects which were not not desigened to be compatible with that library. You may have a look at implementation of that functionality for std::vector or boost::shared_ptr (files are in boost serialisation folder).
    This mechanism is described in boost serialisation documentation as well.

  3. #3
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    Re: boost::serialization with boost::any

    Quote Originally Posted by DragForce
    Boost serialisation does provide means of serialising objects which were not not desigened to be compatible with that library. You may have a look at implementation of that functionality for std::vector or boost::shared_ptr (files are in boost serialisation folder).
    This mechanism is described in boost serialisation documentation as well.

    Hi.

    Am am of course aware that boost::serialization offers non-intrusive serialization for a large number of well known constructs, like std::vector or boost::shared_ptr.

    However, there is no (official) method for serializing boost::any. I was hopping that someone here has found a (more or less) generical method for that, as I didn't want to begin ym own attempt.

    The issue has been discussed on the boost mailing list, but, as I said, to no more than some ideas. One can hope that a future release of boost will cover the issue.

    In the meanwhile, I see three options:
    • write an own implementation, that covers strictly the needs of my project (i.e. non-generic)
    • drop boost::any and use something else, like boost::variant or an own construct
    • attempt an own gnerical implementation and upload it to the boost vault, hoping that it gets accepted


    I dislike the first option because of aesthetical reasons The third option is rather time consuming, and would mean a digression in my project. The second option is probably the most pragmatical one...
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured