Serialization: how to inject context into save/load free functions?
I have a POD struct that I de/serialize through appropriately overloaded save and load free functions[*]. In my case, de/serialization involves translating between different representations (uid <-> username, gid <-> groupname). This translation is encapsulated in a class Etc and currently I just have a local variable of class Etc in both methods. I'd prefer a way to inject the Etc instance into save and load. The ideal solution would meet these criteria: * The Etc instance is created externally to save/load. * No global or quasi-global (static or singleton) variables. * No changes to the serialized struct (i.e. not an additional pointer to an Etc instance). * Usable with existing archive classes without extension. As far as I can tell, so far, I can't get all of these. I'm hoping that there is a way that I have overlooked. Michael [*] https://github.com/mschuerig/preserfs/blob/master/src/DirectoryMetadata.cpp#... -- Michael Schuerig mailto:michael@schuerig.de http://www.schuerig.de/michael/
Dear All, I am a new user of the Boost MSM library and I was wondering how to post internal events. It seems that only events can be sent from the back end, am I wrong? Thank you for your reply. Cyril.
I am a new user of the Boost MSM library and I was wondering how to post internal events. It seems that only events can be sent from the back end, am I wrong?
Yes they can only be sent from the back-end but it it shouldn't be a
problem. You can define a functor doing this
(http://svn.boost.org/svn/boost/trunk/libs/msm/doc/HTML/ch03s03.html#d0e1298),
for example:
struct store_cd_info
{
template
Many thanks, this is the answer I needed! Cyril. On 18/06/2011 11:06, Christophe Henry wrote:
I am a new user of the Boost MSM library and I was wondering how to post internal events. It seems that only events can be sent from the back end, am I wrong?
Yes they can only be sent from the back-end but it it shouldn't be a problem. You can define a functor doing this (http://svn.boost.org/svn/boost/trunk/libs/msm/doc/HTML/ch03s03.html#d0e1298), for example:
struct store_cd_info { template
void operator()(Evt const&, Fsm& fsm, SourceState&,TargetState& ) { fsm.process_event(play()); } }; The "Fsm" template parameter is the back-end. With eUML you also have a process_ function.
Only the basic front-end really is too simple. Inside this front-end, you could static_cast to the back-end type but this would really not be a good solution, so I advise you to switch to the more powerful front-ends, or to at least mix and use a "Row" instead of the xxx_row versions for the transitions when you need to post another event (you can mix row types).
HTH, Christophe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- ************************************** Dr. Cyril Ballagny R&D Department Softeam, ModelioSoft, France http://www.softeam.com/ http://www.modeliosoft.com/ Tel. +33 130121675 (office) **************************************
participants (3)
-
Christophe Henry
-
Cyril Ballagny
-
Michael Schuerig