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 SingleFlagger(
const SingleFlagger &) =
default;
121 bool isSet(
const storage_t & x)
const override {
122 return (this->value == x);
127 void set(
const key_t & key){
135 void set(
const value_t & value){
141 this->value = flagger.value;
148 SingleFlagger<E> & operator=(
const T & v){
155 const key_t &
str()
const override {
168 void assign(
const std::string & key)
override {
172 if ((key.find(
',')!= std::string::npos)||(key.find(
'|')!= std::string::npos)){
173 Logger mout(__FILE__, __FUNCTION__);
177 if (this->
getDict().hasKey(key)){
181 Logger mout(__FILE__, __FUNCTION__);
182 value_t v =
static_cast<value_t
>(atoi(key.c_str()));
184 mout.
suspicious(
"value: ", v,
" corresponds to no value in dict:", this->
getDict());
201std::ostream & operator<<(std::ostream & ostr,
const SingleFlagger<E> & flagger) {
202 ostr << flagger.str();
206DRAIN_TYPENAME_T(SingleFlagger,E);
216template <
typename E,
typename T=
size_t>
227 typedef typename dict_t::key_t key_t;
234 template <
typename ... V>
253 MultiFlagger(
const MultiFlagger &) =
default;
267 bool isSet(
const storage_t & x)
const override {
268 return ((this->value & x) == x);
274 return ((this->value & x) != 0);
280 this->value = (this->value & ~x);
291 template <
typename ... V>
293 void set(
const V &... args) {
300 template <
typename V,
typename ...VV>
302 void add(
const V & arg,
const VV &... args) {
310 const key_t &
str()
const override {
334 void assign(
const std::string & s)
override {
344 void addOne(
const key_t & key){
351 void addOne(
const storage_t & value){
352 this->value |= value;
355 template <
typename T2>
357 void addOne(
const T2 & value){
360 this->value |=
static_cast<value_t
>(value);
364 std::string currentStr;
371template <
typename E,
typename T>
377DRAIN_TYPENAME_T(MultiFlagger,E);
397 typedef typename F::value_t value_t;
398 typedef typename F::dict_t dict_t;
402 const dict_t & getDict()
const {
428 Flags2(
const std::initializer_list<typename dict_t::entry_t> & list) : dict(list){
437 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:392
Flags2()
Definition Flags.h:418
Flags2(const std::initializer_list< typename dict_t::entry_t > &list)
Constructor for relatively short dictionaries.
Definition Flags.h:428
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & error(const TT &... args)
Echoes.
Definition Log.h:426
Logger & suspicious(const TT &... args)
A weak warning about something going possibly wrong.
Definition Log.h:510
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:521
virtual std::string & str()
For importing values. After assignment, update() should be called. Experimental.
Definition Flags.h:319
void unset(const storage_t &x)
Unset some bit(s).
Definition Flags.h:279
MultiFlagger(const dict_t &dict, storage_t &target, char sep=',')
Definition Flags.h:244
void add(const V &arg, const VV &... args)
Add bit values.
Definition Flags.h:302
virtual void assign(const std::string &s) override
Split a string to separate keys and/or values and set them.
Definition Flags.h:334
virtual bool isSet(const storage_t &x) const override
Return true, all the bits of argument x are set.
Definition Flags.h:267
bool isAnySet(const storage_t &x) const
Return true, all the bits of argument x are set.
Definition Flags.h:273
void set(const V &... args)
Set bits, accepting numeric values or keys.
Definition Flags.h:293
virtual const dict_t & getDict() const override
Returns the static dictionary created for this value_t .
Definition Flags.h:257
virtual const key_t & str() const override
For exporting values.
Definition Flags.h:310
virtual void set(const value_t &value)
Set a single flag.
Definition Flags.h:135
virtual bool isSet(const storage_t &x) const override
Return true, if value is exactly x .
Definition Flags.h:121
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:155
virtual void assign(const std::string &key) override
Assign key. Expects a single key, not a combination of keys.
Definition Flags.h:168
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
Default implementation.
Definition TypeName.h:54
static const std::string & str()
Default implementation: name returned by std::type_info::name()
Definition TypeName.h:68