32 #ifndef DRAIN_FLAGS_OLD_H_
33 #define DRAIN_FLAGS_OLD_H_
68 separator(separator?separator:dict.separator){
72 Flagger(ivalue_t & value,
const dict_t & dict,
char separator = 0) :
76 separator(separator?separator:dict.separator){
81 ownValue(flags.value),
83 dictionary(flags.dictionary),
84 separator(flags.separator){
87 mout.
error(
"Flagger inits value &= flags.value", flags);
99 template <
typename T,
typename ... TT>
117 Flagger & deepSet(ivalue_t x){
118 this->value = (this->value | x);
141 value = (value & ~x);
164 return (value & x) != 0;
168 bool isSet(
const key_t & key)
const {
175 Flagger & operator=(
const Flagger &x){
213 void assign(
const std::string & params);
217 operator ivalue_t()
const {
222 operator bool()
const {
227 operator std::string()
const {
228 std::stringstream sstr;
242 ivalue_t
getValue(
const std::string & key,
char separator=0)
const {
250 std::string
getKeys(ivalue_t value,
char separator=0)
const {
261 const dict_t::keylist_t & keys()
const;
265 mutable dict_t::keylist_t keyList;
279 std::ostream &
keysToStream(std::ostream & ostr=std::cout,
char separator=0)
const {
288 void exportStatus(std::map<std::string, T> & statusMap)
const {
289 for (dict_t::const_iterator it = dictionary.begin(); it != dictionary.end(); ++it){
290 if ((it->second > 0) && ((it->second & value) == it->second)){
291 statusMap[it->first] = 1;
294 statusMap[it->first] = 0;
308 std::ostream & operator<<(std::ostream & ostr,
const drain::Flagger & flags) {
323 const dict_t & getDict()
const{
324 return ownDictionary;
330 return ownDictionary;
334 Flags(
char separator =
',') :
Flagger(ownDictionary, separator){
339 Flags(
const Flags & flags) :
Flagger(ownValue = flags.ownValue, ownDictionary, flags.separator){
347 Flags(std::initializer_list<dict_t::entry_t> d,
char separator =
',') :
Flagger(ownValue, ownDictionary, separator) {
348 for (
const dict_t::entry_t & entry: d){
349 addEntry(entry.first, entry.second);
368 ivalue_t
addEntry(
const dict_t::key_t & key, ivalue_t i=0){
const V & getValue(const K &key) const
Given a key, return the first value associated with it.
Definition: Dictionary.h:149
Referencing a dictionary of binary values: {"A",1: "B":2, "C": 4, "D": 8, ...} resolves two-way mappi...
Definition: Flags.h:56
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: Flags.h:274
static ivalue_t getValue(const drain::Dictionary< key_t, T > &dict, const std::string &key, char separator=',')
Computes bitwise OR function on the numeric or alphabetic value(s) presented by a string.
Definition: Flags.h:198
static ivalue_t addEntry(drain::Dictionary< key_t, T > &dict, const key_t &key, ivalue_t i=0)
Add a new entry in the dictionary.
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: Flags.h:262
A bit vector with external Dictionary mapping from strings to bits and vice versa.
Definition: FlagsOld.h:45
std::ostream & keysToStream(std::ostream &ostr=std::cout, char separator=0) const
Display current value as key values of which the value is composed with OR function.
Definition: FlagsOld.h:279
std::string getKeys(ivalue_t value, char separator=0) const
Given an integer, retrieves dictionary keys corresponding to each index of set bits.
Definition: FlagsOld.h:250
Flagger & unset(const key_t &key)
Unset desired flags. Does not set any flag.
Definition: FlagsOld.h:147
Flagger & set(const T &arg, const TT &... args)
Set desired flags. Does not reset any flag (zero value has no effect).
Definition: FlagsOld.h:101
bool isSet(ivalue_t x) const
Checks if a given bit, or any of given bits, is set.
Definition: FlagsOld.h:163
void assign(ivalue_t x)
Sets value, ie. set or unsets all the flags.
Definition: FlagsOld.h:196
Flagger & unset(ivalue_t x)
Unset desired flags. Does not set any flag.
Definition: FlagsOld.h:140
Flagger & deepSet(const key_t &key)
Set desired flags. Does not reset any flag.
Definition: FlagsOld.h:128
Flagger & operator=(const T &x)
Sets value, ie. set or unsets all the flags.
Definition: FlagsOld.h:186
void assign(const Flagger &flags)
Copies flags as an integer value. Same dictionary not checked.
Definition: FlagsOld.h:205
std::string getKeys(char separator=0) const
Given an integer, retrieves dictionary keys corresponding to each index of set bits.
Definition: FlagsOld.h:256
ivalue_t getValue(const std::string &key, char separator=0) const
Computes bitwise OR function on the numeric or alphabetic value(s) presented by a string.
Definition: FlagsOld.h:242
Flagger & reset()
Reset all the flags.
Definition: FlagsOld.h:156
Self-contained Flagger – with an own dictionary and value.
Definition: FlagsOld.h:314
Flags(std::initializer_list< dict_t::entry_t > d, char separator=',')
Initialize with {{"first", 123}, {"second", 456}}.
Definition: FlagsOld.h:347
ivalue_t addEntry(const dict_t::key_t &key, ivalue_t i=0)
Add a new entry in the dictionary.
Definition: FlagsOld.h:368
Flags & operator=(const T &x)
Sets value, ie. set or unsets all the flags.
Definition: FlagsOld.h:358
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Definition: DataSelector.cpp:1277
Definition: Sprinter.h:137