Loading...
Searching...
No Matches
EnumFlagger.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32#ifndef DRAIN_ENUM_FLAGGER
33#define DRAIN_ENUM_FLAGGER
34
35
36//#include <drain/Dictionary.h>
37#include <drain/Enum.h>
38#include "Flags.h"
39
40namespace drain {
41
42
43
44
46
55template <class F> // F =SingleFlagger<E>
56class EnumFlagger : public F {
57
58public:
59
60 typedef F fbase_t;
61 typedef typename F::value_t value_t;
62 typedef typename F::storage_t storage_t;
63 typedef typename F::dict_t dict_t;
64 typedef FlagResolver::ivalue_t ivalue_t;
65
67 inline
68 EnumFlagger(): fbase_t(Enum<value_t>::dict){
69 }
70
72 inline
73 EnumFlagger(const storage_t & v): fbase_t(Enum<value_t>::dict) {
74 this->value = v;
75 }
76
77 /*
78 inline
79 EnumFlagger(value_t v): fbase_t(v) {
80 }
81 */
82
84 template <typename ... T>
85 inline
86 EnumFlagger(const T & ... arg): fbase_t(Enum<value_t>::dict, arg...) { // designed for MultiFlagger
87 }
88
89 /* // keep
90 virtual void reset() override {
91 this->value = Enum<value_t>::defaultValue; // ALERT! enums need neutral value.
92 };
93 */
94
96
107
111 static
112 ivalue_t getValueNEW(const std::string & key){
113 return (ivalue_t)Enum<value_t>::dict.getValue(key);
114 };
115
116 // Raise?
117 /*
118 static inline
119 std::string getKeysNEW2(const storage_t & value, char separator = ','){
120 // currentStr = FlagResolver::getKeys(dict, this->value, this->separator);
121 return FlagResolver::getKeys(Enum<value_t>::dict, value, separator);
122 }
123 */
124
136 inline
138 this->set(flagger.value);
139 return *this;
140 }
141
142 template <class T>
143 inline
144 EnumFlagger<F> & operator=(const T & v){
145 this->set(v);
146 return *this;
147 }
148
149};
150
151
152
153} // drain::
154
155
156
157#endif
Flagger accepting values of enum type E.
Definition EnumFlagger.h:56
EnumFlagger(const storage_t &v)
Constructor with initial value.
Definition EnumFlagger.h:73
EnumFlagger()
Default constructor.
Definition EnumFlagger.h:68
EnumFlagger< F > & operator=(const EnumFlagger< F > &flagger)
Definition EnumFlagger.h:137
static ivalue_t getValueNEW(const std::string &key)
Returns the static dictionary created for this value_t .
Definition EnumFlagger.h:112
Definition DataSelector.cpp:1277
A container for a static dictionary of enumeration values.
Definition Enum.h:51
static E getValue(const E &value, bool lenient=true)
Convenience for object.set(...) like commands.
Definition Enum.h:96