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

M

Michael Schuerig

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
 
J

Jeff Flinn

Michael said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top