Boost logo

Boost Users :

From: Nat Goodspeed (ngoodspeed_at_[hidden])
Date: 2006-09-16 08:34:44


> ________________________________________
> From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
> Sent: Saturday, September 16, 2006 2:27 AM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] [boost::serialization] Convert enumeration
tostringand back again
>
> class param_choice {
> enum
> {
> PARAM_CHOICE_UINT8,
> PARAM_CHOICE_UINT16,
> PARAM_CHOICE_UINT32,
> PARAM_CHOICE_INT8,
> PARAM_CHOICE_BOOL
> } m_current_value;
> template<class Archive>
> save(Archive &ar, unsigned int version) {
> std::string svalue;
> switch(m_current_value){

[Nat] If I were going to do this "by hand," I'd at least want to
construct a map. From that I'd populate another for the reverse lookup.
But that's probably because I haven't yet read up on Boost.MultiIndex.

> case PARAM_CHOICE_UINT8:
> svalue = "PARAM_CHOICE_UINT8";
> ...
> }
> ar << BOOST_SERIALIZATION_NVP(svalue);
> }
> template<class Archive>
> load(Archive &ar, unsigned int version){
> std::string svalue;
> ar >> BOOST_SERIALIZATION_NVP(svalue);
> if(svalue == std::string("PARAM_CHOICE_UINT8")
> m_current_value = PARAM_CHOICE_UINT8;
> else
> if(...
> ...
> }
> };


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