Boost logo

Boost :

Subject: Re: [boost] Answers re BENUM library for automated enum streaming
From: Tony D (tony_in_da_uk_at_[hidden])
Date: 2008-09-16 11:57:09

> From Manuel Fiorelli: > You could try to look at [boost preprocessor lib docs] to avoid variadic macros. > I am not sure if it is applicable at your library, though. As best I understand it, they're not applicable :-(. Perhaps David will confirm. Also appreciate if someone can fill me in on boost's (historical?) attitude to facilities with this dependency. FWIW, lists compilers with __VA_ARGS__ support (GCC 3.0+, VC++2005+, C++Builder 2006+). > From: Marcus Lindblom <macke_at_[hidden]> > However, is it possible to define a separate mapping if one would like? > > For instance, I like my strings to be lower case, and without prefixes, > whereas my enums need a bit more scaffolding: > > enum Context { CXT_APP, CXT_PHYS, CXT_VIS } > enum Aspect { ASP_APP, ASP_PHYS} > CXT_APP = "app", CXT_PHYS = "phys", etc. > ASP_APP = "app", ASP_PHYS = "phys", etc. Hi Marcus, There are several points of customisation that do or might allow it. For example, derive an "Info_Container" (into which identifier/value pairs are inserted via registration callback) with your callback performing simple automated substitutions like removal of text up to and including an underscore and conversion to lower case. At worst - not recommended as it requires manual maintainence - you can resort to ignoring the automated registration and hardcode one-by-one insertions using arbitrary identifiers, or even create a completely customer Info_Container class hardcoding support for a specific enum. The main BENUM macro also allows specification of extra functions to include in the generated class (a set of such precanned "features" are provided in benum_features.h). I haven't tried it, but I suspect a static method could be introduced to perform a transformation, but it would need to be called before first use. > > - smart enums requires user-maintained "meta-data" - from the smart enum docs: > > bool init = (::EnumIO<Foo>::the() (Bar, "bar") (Baz, "baz")), true; > > EnumIO only does that, and it hides the usage of EnumIO<> from the > header file, thus it is very lean and efficient. > How much extra template code is instantiated in each source file > including BENUM-use? Not so much: - only a thin wrapper is instantiated for each type, performing type casting as it interacts with a single instance of the core storage/lookup code that works with int enumeration values - there's a preprocessor #ifdef to control whether one of the implementation files is sucked into the related header for convenience vs out-of-line for decoupling physical dependency / faster compiles Regards, Tony

Boost list run by bdawes at, gregod at, cpdaniel at, john at