Boost serialization: how to inject a context into free load/save funcs?

Discussion in 'C++' started by Michael Schuerig, May 30, 2011.

  1. I haven't been using C++ for years and I've never used Boost before, so
    I might well be missing something obvious.

    I'm using Boost serialization on a class holding a vector of plain
    structs. In order to keep anything related to serialization out of the
    interface, I have defined free functions for load and save. This works
    as expected.

    However, for the external representation of the data I need to do a
    little bit of mapping from user and group IDs to respective names. I
    have another class, Etc, for this task and currently the load and save
    functions just have a local Etc variable. This, unfortunately, ties the
    code to a specific implementation of the functionality and precludes
    caching of mappings in a single Etc instance.

    So, what I'm looking for is a way to inject "context" into the load and
    save functions that would allow me to keep one Etc instance and pass it
    along to where it is needed.

    If anyone is interested in the actual code, it can be found here:
    https://github.com/mschuerig/preserfs/tree/master/src

    Michael

    --
    Michael Schuerig
    mailto:
    http://www.schuerig.de/michael/
     
    Michael Schuerig, May 30, 2011
    #1
    1. Advertising

  2. Michael Schuerig

    Jeff Flinn Guest

    Re: Boost serialization: how to inject a context into free load/savefuncs?

    Michael Schuerig wrote:
    > I haven't been using C++ for years and I've never used Boost before, so
    > I might well be missing something obvious.
    >
    > I'm using Boost serialization on a class holding a vector of plain
    > structs. In order to keep anything related to serialization out of the
    > interface, I have defined free functions for load and save. This works
    > as expected.
    >
    > However, for the external representation of the data I need to do a
    > little bit of mapping from user and group IDs to respective names. I
    > have another class, Etc, for this task and currently the load and save
    > functions just have a local Etc variable. This, unfortunately, ties the
    > code to a specific implementation of the functionality and precludes
    > caching of mappings in a single Etc instance.
    >
    > So, what I'm looking for is a way to inject "context" into the load and
    > save functions that would allow me to keep one Etc instance and pass it
    > along to where it is needed.
    >
    > If anyone is interested in the actual code, it can be found here:
    > https://github.com/mschuerig/preserfs/tree/master/src


    Well the Archive is the 'context'. IIUC, you would create your own
    archive class. There are docs and examples on doing this. The boost
    mailing list would provide support for your endeavor.

    Jeff
     
    Jeff Flinn, May 31, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    2,310
    deadsea
    Jan 2, 2005
  2. Replies:
    3
    Views:
    1,084
  3. Dimitri Ognibene
    Replies:
    4
    Views:
    820
    Dimitri Ognibene
    Sep 2, 2006
  4. Ramunas Urbonas
    Replies:
    1
    Views:
    427
    Dino Chiesa [Microsoft]
    Jul 27, 2004
  5. Peña, Botp

    inject does not inject last value

    Peña, Botp, Aug 7, 2006, in forum: Ruby
    Replies:
    4
    Views:
    198
    Peña, Botp
    Aug 7, 2006
Loading...

Share This Page