46#include <drain/StringTools.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>
265 bool isSet(
const storage_t & x)
const override {
266 return ((this->value & x) == x);
272 return ((this->value & x) != 0);
278 this->value = (this->value & ~x);
289 template <
typename ... V>
291 void set(
const V &... args) {
298 template <
typename V,
typename ...VV>
300 void add(
const V & arg,
const VV &... args) {
308 const key_t &
str()
const override {
332 void assign(
const std::string & s)
override {
342 void addOne(
const key_t & key){
349 void addOne(
const storage_t & value){
350 this->value |= value;
353 template <
typename T2>
355 void addOne(
const T2 & value){
358 this->value |=
static_cast<value_t
>(value);
362 std::string currentStr;
369template <
typename E,
typename T>
394 typedef typename F::value_t value_t;
395 typedef typename F::dict_t dict_t;
399 const dict_t & getDict()
const {
425 Flags2(
const std::initializer_list<typename dict_t::entry_t> & list) : dict(list){
434 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:389
Flags2()
Definition Flags.h:415
Flags2(const std::initializer_list< typename dict_t::entry_t > &list)
Constructor for relatively short dictionaries.
Definition Flags.h:425
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:317
void unset(const storage_t &x)
Unset some bit(s).
Definition Flags.h:277
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:300
virtual void assign(const std::string &s) override
Split a string to separate keys and/or values and set them.
Definition Flags.h:332
virtual bool isSet(const storage_t &x) const override
Return true, all the bits of argument x are set.
Definition Flags.h:265
bool isAnySet(const storage_t &x) const
Return true, all the bits of argument x are set.
Definition Flags.h:271
void set(const V &... args)
Set bits, accepting numeric values or keys.
Definition Flags.h:291
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:308
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
Default implementation.
Definition Type.h:541