|
Boost Users : |
From: Gross, Steve (SGross_at_[hidden])
Date: 2007-08-07 18:09:40
Hi folks. I'm learning the basics of the serialization library right
now. I'd like to know if there's a known tactic for archiving enums with
textual tokens, rather than the int value itself. For instance, consider
the following code: I set up an enum called status_t, and a class Foo
that has a status_t as a data member. In Foo's serialize function, I
record the status_t (myStatus).
enum status_t { ON, OFF };
class Foo {
status_t myStatus;
friend class boost::serialization::access;
template<class Archive> serialize(...) {
ar & BOOST_SERIALIZATION_NVP(myStatus);
}
};
The xml output file looks sort of like this:
<Foo>
<myStatus>0</myStatus>
</Foo>
The file that is generated when serialize() is invoked certainly works,
but the value for myStatus appears as an int. What if I want to convert
the int to a string in the archive? That is, I want the xml file to look
like this:
<Foo>
<myStatus>ON</myStatus>
</Foo>
Are there any good strategies for doing this?
Thanks,
--Steve (sgross_at_[hidden])
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net