41#include <drain/TypeName.h>
73 typedef typename dict_t::key_t key_t;
97 SingleFlagger(
const dict_t & dict,
const storage_t &v) : dict(dict) {
107 SingleFlagger(
const dict_t & dict, storage_t & v,
char sep=
',') : flagger_t(v, sep), dict(dict){
117 bool isSet(
const storage_t & x)
const override {
118 return (this->value == x);
123 void set(
const key_t & key){
131 void set(
const value_t & value){
137 this->value = flagger.value;
144 SingleFlagger<E> & operator=(
const T & v){
151 const key_t &
str()
const override {
164 void assign(
const std::string & key)
override {
168 if ((key.find(
',')!= std::string::npos)||(key.find(
'|')!= std::string::npos)){
169 Logger mout(__FILE__, __FUNCTION__);
173 if (this->
getDict().hasKey(key)){
177 Logger mout(__FILE__, __FUNCTION__);
178 value_t v =
static_cast<value_t
>(atoi(key.c_str()));
180 mout.
suspicious(
"value: ", v,
" corresponds to no value in dict:", this->
getDict());
197std::ostream & operator<<(std::ostream & ostr,
const SingleFlagger<E> & flagger) {
198 ostr << flagger.str();
202DRAIN_TYPENAME_T0(SingleFlagger,E);
212template <
typename E,
typename T=
size_t>
223 typedef typename dict_t::key_t key_t;
230 template <
typename ... V>
258 bool isSet(
const storage_t & x)
const override {
259 return ((this->value & x) == x);
265 return ((this->value & x) != 0);
271 this->value = (this->value & ~x);
282 template <
typename ... V>
284 void set(
const V &... args) {
291 template <
typename V,
typename ...VV>
293 void add(
const V & arg,
const VV &... args) {
301 const key_t &
str()
const override {
325 void assign(
const std::string & s)
override {
335 void addOne(
const key_t & key){
342 void addOne(
const storage_t & value){
343 this->value |= value;
346 template <
typename T2>
348 void addOne(
const T2 & value){
351 this->value |=
static_cast<value_t
>(value);
355 std::string currentStr;
362template <
typename E,
typename T>
368DRAIN_TYPENAME_T0(MultiFlagger,E);
388 typedef typename F::value_t value_t;
389 typedef typename F::dict_t dict_t;
393 const dict_t & getDict()
const {
419 Flags2(
const std::initializer_list<typename dict_t::entry_t> & list) : dict(list){
428 Flags2<F> & operator=(
const T & v){
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:61
const K & getKey(const V &value, bool lenient=true) const
Identity mapping useful for type deduction of template arguments in functions.
Definition Dictionary.h:170
const V & getValue(const K &key, bool lenient=true) const
Given a key, return the first value associated with it.
Definition Dictionary.h:147
bool hasValue(const V &value) const
Given a key, return the first value associated with it.
Definition Dictionary.h:141
static ivalue_t getIntValue(const drain::Dictionary< key_t, T > &dict, const std::string &keys, char separator=',')
Computes bitwise OR function on the numeric or alphabetic value(s) presented by a string.
Definition FlagBase.h:195
static std::ostream & keysToStream(const drain::Dictionary< key_t, T > &dict, ivalue_t value, std::ostream &ostr, char separator=',')
Write keys in a stream, in numeric order.
Definition FlagBase.h:276
static std::string getKeys(const drain::Dictionary< key_t, T > &dict, ivalue_t, char separator=',')
Given an integer, retrieves dictionary keys corresponding to each index of set bits.
Definition FlagBase.h:264
Definition FlagBase.h:359
Flagger with own dictionary, and accepting values of (integer) type T.
Definition Flags.h:383
Flags2()
Definition Flags.h:409
Flags2(const std::initializer_list< typename dict_t::entry_t > &list)
Constructor for relatively short dictionaries.
Definition Flags.h:419
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & error(const TT &... args)
Echoes.
Definition Log.h:417
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition Log.h:501
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:512
virtual std::string & str()
For importing values. After assignment, update() should be called. Experimental.
Definition Flags.h:310
void unset(const storage_t &x)
Unset some bit(s).
Definition Flags.h:270
MultiFlagger(const dict_t &dict, storage_t &target, char sep=',')
Definition Flags.h:240
void add(const V &arg, const VV &... args)
Add bit values.
Definition Flags.h:293
virtual void assign(const std::string &s) override
Split a string to separate keys and/or values and set them.
Definition Flags.h:325
virtual bool isSet(const storage_t &x) const override
Return true, all the bits of argument x are set.
Definition Flags.h:258
bool isAnySet(const storage_t &x) const
Return true, all the bits of argument x are set.
Definition Flags.h:264
void set(const V &... args)
Set bits, accepting numeric values or keys.
Definition Flags.h:284
virtual const dict_t & getDict() const override
Returns the static dictionary created for this value_t .
Definition Flags.h:248
virtual const key_t & str() const override
For exporting values.
Definition Flags.h:301
virtual void set(const value_t &value)
Set a single flag.
Definition Flags.h:131
virtual bool isSet(const storage_t &x) const override
Return true, if value is exactly x .
Definition Flags.h:117
virtual const dict_t & getDict() const override
Returns the static dictionary created for this value_t .
Definition Flags.h:83
virtual const key_t & str() const override
String corresponding the current value. Returns empty, if not found.
Definition Flags.h:151
virtual void assign(const std::string &key) override
Assign key. Expects a single key, not a combination of keys.
Definition Flags.h:164
Definition DataSelector.cpp:1277
Default implementation.
Definition TypeName.h:54