[Home]Pretty Oarchive

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

Playing with serialization for container printing. first take some udt's:

  struct Inner {
    int ii;
    template <class Ar>
    void serialize(Ar& ar, unsigned)
       ar & make_nvp("i", i);

  struct Outer {
    int oi;  
    Inner inner;
    template <class Ar>
    void serialize (Ar7 ar, unsigned)
        ar & make_nvp("oi", oi);
        ar & make_nvp("inner", inner);

  ostream& operator<<(ostream& ostr, const Outer& obj)
     pretty_oarchive oarch(ostr);
     oarch << make_nvp("obj", obj);
     return ostr;

or thereabouts means you can do:

  Outer myouter;

  cout << myouter;

and get (pretty_oarchive is basically just xml with different formatting)

    oi: 33
      i: 42

which is nice enough but you're stuck with the structure expressed by the serialization methods for the standard containers (which already exist), e.g.

  vector<int> vi;
  cout << vi;   // assuming operator<< for vector<T> uses a pretty_oarchive

gets you

    size: 3
    item: 41
    item: 611
    item: 1

or with a map<int,int> something like

    size: 2
      first: 3
      second: 4
      first: 61
      second: 33

also not nice given that you'd probably prefer


though you could override oserialization for these certain container types by adding overloads in the oarchive, it still isn't going to play nice with facets or help leverage any of the other stuff about operator<<(ostream&, ..)

BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited May 14, 2007 10:58 pm (diff)
Disclaimer: This site not officially maintained by Boost Developers