32#ifndef DRAIN_ENUM_UTILS
33#define DRAIN_ENUM_UTILS
35#include "Dictionary.h"
51template <
class E,
class OWNER=E>
69 const std::string &
str(
const E & value){
79 bool setValue(
const std::string & key, E & value){
97 E
getValue(
const E & value,
bool lenient=
true){
107 E
getValue(
const std::string &key,
bool lenient=
true){
145 const std::string &
getKey(
const std::string & s,
bool lenient=
true){
150 const char *
getKey(
const char * s,
bool lenient=
true){
155 const std::string &
getKey(
const E & value,
bool lenient=
true){
156 return dict.
getKey(value, lenient);
184template <
typename E,
bool STRICT=true>
200 template <
typename T>
201 void set(
const T & value){
233 template <
typename T>
240 void set(
const std::string &arg){
244 void set(
const char * arg){
248 void set(
const MultiEnumWrapper &arg){
252 template <
typename T>
253 void set(
const T & value){
299 typedef typename F::value_t value_t;
300 typedef typename F::storage_t storage_t;
301 typedef typename F::dict_t dict_t;
302 typedef FlagResolver::ivalue_t ivalue_t;
322 template <
typename ... T>
376 this->set(flagger.value);
392#define DRAIN_ENUM_DICT(enumtype) template <> const drain::EnumDict<enumtype>::dict_t drain::EnumDict<enumtype>::dict
393#define DRAIN_ENUM_DICT2(enumtype,owner) template <> const drain::EnumDict<enumtype,owner>::dict_t drain::EnumDict<enumtype,owner>::dict
395#define DRAIN_ENUM_ENTRY(nspace, key) {#key, nspace::key}
397#define DRAIN_ENUM_OSTREAM(enumtype) inline std::ostream & operator<<(std::ostream &ostr, const enumtype & e){return ostr << drain::EnumDict<enumtype>::dict.getKey(e);}
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
const K & getKey(const V &value, bool lenient=true) const
Identity mapping useful for type deduction of template arguments in functions.
Definition Dictionary.h:172
const V & getValue(const K &key, bool lenient=true) const
Given a key, return the first value associated with it.
Definition Dictionary.h:149
Flagger accepting values of enum type E.
Definition EnumUtils.h:294
EnumFlagger(const storage_t &v)
Constructor with initial value.
Definition EnumUtils.h:311
EnumFlagger()
Default constructor.
Definition EnumUtils.h:306
EnumFlagger< F > & operator=(const EnumFlagger< F > &flagger)
Definition EnumUtils.h:375
static ivalue_t getValueNEW(const std::string &key)
Returns the static dictionary created for this value_t .
Definition EnumUtils.h:350
Definition EnumUtils.h:185
EnumWrapper(const E &x)
All the other constructors, including default constructor.
Definition EnumUtils.h:196
Definition EnumUtils.h:215
MultiEnumWrapper(const T &arg)
Default constructor.
Definition EnumUtils.h:235
Definition DataSelector.cpp:1277
A container for a static dictionary of enumeration values.
Definition EnumUtils.h:52
static E getValue(const char *key, bool lenient=true)
Convenience for object.set(...) like commands.
Definition EnumUtils.h:117
static const std::string & str(const E &value)
Convenience.
Definition EnumUtils.h:69
static E getValue(const E &value, bool lenient=true)
Convenience for object.set(...) like commands.
Definition EnumUtils.h:97
static bool setValue(const std::string &key, E &value)
Assign string values to an enumeration type.
Definition EnumUtils.h:79
static const std::string & getKey(const std::string &s, bool lenient=true)
Convenience for object.set(...) like commands.
Definition EnumUtils.h:145
static E getValue(const std::string &key, bool lenient=true)
Convenience for object.set(...) like commands.
Definition EnumUtils.h:107