46#include <drain/String.h>
47#include <drain/Type.h>
49#include "Dictionary.h"
81 typedef typename dict_t::key_t key_t;
105 SingleFlagger(
const dict_t & dict,
const storage_t &v) : dict(dict) {
115 SingleFlagger(
const dict_t & dict, storage_t & v,
char sep=
',') : flagger_t(v, sep), dict(dict){
125 bool isSet(
const storage_t & x)
const override {
126 return (this->value == x);
131 void set(
const key_t & key){
139 void set(
const value_t & value){
145 this->value = flagger.value;
152 SingleFlagger<E> & operator=(
const T & v){
159 const key_t &
str()
const override {
172 void assign(
const std::string & key)
override {
176 if ((key.find(
',')!= std::string::npos)||(key.find(
'|')!= std::string::npos)){
177 Logger mout(__FILE__, __FUNCTION__);
181 if (this->
getDict().hasKey(key)){
185 Logger mout(__FILE__, __FUNCTION__);
186 value_t v =
static_cast<value_t
>(atoi(key.c_str()));
188 mout.
suspicious(
"value: ", v,
" corresponds to no value in dict:", this->
getDict());
206 ostr << flagger.
str();
219template <
typename E,
typename T=
size_t>
230 typedef typename dict_t::key_t key_t;
237 template <
typename ... V>
261 bool isSet(
const storage_t & x)
const override {
262 return ((this->value & x) == x);
268 return ((this->value & x) != 0);
274 this->value = (this->value & ~x);
285 template <
typename ... V>
287 void set(
const V &... args) {
294 template <
typename V,
typename ...VV>
296 void add(
const V & arg,
const VV &... args) {
304 const key_t &
str()
const override {
328 void assign(
const std::string & s)
override {
338 void addOne(
const key_t & key){
345 void addOne(
const storage_t & value){
346 this->value |= value;
349 template <
typename T2>
351 void addOne(
const T2 & value){
354 this->value |=
static_cast<value_t
>(value);
358 std::string currentStr;
365template <
typename E,
typename T>
390 typedef typename F::value_t value_t;
391 typedef typename F::dict_t dict_t;
395 const dict_t & getDict()
const {
421 Flags2(
const std::initializer_list<typename dict_t::entry_t> & list) : dict(list){
430 Flags2<F> & operator=(
const T & v){
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
bool hasValue(const V &value) const
Given a key, return the first value associated with it.
Definition Dictionary.h:143
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:199
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:278
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:266
Definition FlagBase.h:361
Flagger with own dictionary, and accepting values of (integer) type T.
Definition Flags.h:385
Flags2()
Definition Flags.h:411
Flags2(const std::initializer_list< typename dict_t::entry_t > &list)
Constructor for relatively short dictionaries.
Definition Flags.h:421
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & error(const TT &... args)
Echoes.
Definition Log.h:416
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition Log.h:500
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:511
virtual std::string & str()
For importing values. After assignment, update() should be called. Experimental.
Definition Flags.h:313
void unset(const storage_t &x)
Unset some bit(s).
Definition Flags.h:273
MultiFlagger(const dict_t &dict, storage_t &target, char sep=',')
Definition Flags.h:247
void add(const V &arg, const VV &... args)
Add bit values.
Definition Flags.h:296
virtual void assign(const std::string &s) override
Split a string to separate keys and/or values and set them.
Definition Flags.h:328
virtual bool isSet(const storage_t &x) const override
Return true, all the bits of argument x are set.
Definition Flags.h:261
bool isAnySet(const storage_t &x) const
Return true, all the bits of argument x are set.
Definition Flags.h:267
void set(const V &... args)
Set bits, accepting numeric values or keys.
Definition Flags.h:287
virtual const dict_t & getDict() const override
Returns the static dictionary created for this value_t .
Definition Flags.h:255
virtual const key_t & str() const override
For exporting values.
Definition Flags.h:304
virtual void set(const value_t &value)
Set a single flag.
Definition Flags.h:139
virtual bool isSet(const storage_t &x) const override
Return true, if value is exactly x .
Definition Flags.h:125
virtual const dict_t & getDict() const override
Returns the static dictionary created for this value_t .
Definition Flags.h:91
virtual const key_t & str() const override
String corresponding the current value. Returns empty, if not found.
Definition Flags.h:159
virtual void assign(const std::string &key) override
Assign key. Expects a single key, not a combination of keys.
Definition Flags.h:172
Definition DataSelector.cpp:1277