Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
FlagResolver Class Reference

Referencing a dictionary of binary values: {"A",1: "B":2, "C": 4, "D": 8, ...} resolves two-way mappings "A,C" <=> 5 . More...

#include <Flags.h>

Inheritance diagram for FlagResolver:
Inheritance graph
[legend]

Public Types

typedef std::string key_t
 
typedef unsigned long int ivalue_t
 
typedef drain::Dictionary< key_t, ivalue_t > dict_t
 "Recommended" dictionary type. All the methods are templates, however.
 

Public Member Functions

template<typename T >
FlagResolver::ivalue_t addEntry (drain::Dictionary< key_t, T > &dict, const typename dict_t::key_t &key, ivalue_t i)
 

Static Public Member Functions

template<typename T >
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. More...
 
template<typename T >
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. More...
 
template<typename T >
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. More...
 
template<typename T , typename V >
static void valuesToList (ivalue_t value, const drain::Dictionary< key_t, T > &dict, std::list< V > &container)
 Given a bit vector (integer value), extracts separate flag values to a list. More...
 
template<typename T >
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. More...
 
template<typename T >
static ivalue_t getFreeBit (const drain::Dictionary< key_t, T > &dict)
 Return an interger (bit vector) with a new, previously unused value. More...
 

Static Public Attributes

static const ivalue_t ALL = ~FlagResolver::ivalue_t(0)
 

Detailed Description

Referencing a dictionary of binary values: {"A",1: "B":2, "C": 4, "D": 8, ...} resolves two-way mappings "A,C" <=> 5 .

Static utilities.

Member Function Documentation

◆ addEntry()

static ivalue_t addEntry ( drain::Dictionary< key_t, T > &  dict,
const key_t &  key,
ivalue_t  i = 0 
)
static

Add a new entry in the dictionary.

Parameters
i- if zero, call getFreeBit() to reserve a new, unused bit.

◆ getFreeBit()

FlagResolver::ivalue_t getFreeBit ( const drain::Dictionary< key_t, T > &  dict)
static

Return an interger (bit vector) with a new, previously unused value.

Traverses the values in dict, and determines a new bit corresponding to a new value.

◆ getKeys()

std::string getKeys ( const drain::Dictionary< key_t, T > &  dict,
ivalue_t  v,
char  separator = ',' 
)
static

Given an integer, retrieves dictionary keys corresponding to each index of set bits.

List keys in their numeric order.

◆ getValue()

FlagResolver::ivalue_t getValue ( const drain::Dictionary< key_t, T > &  dict,
const std::string &  key,
char  separator = ',' 
)
static

Computes bitwise OR function on the numeric or alphabetic value(s) presented by a string.

Parameters
key– A string containing keys ("note,error") or values ("4,8,32") or a mixture of them.
separator– if given, splits string to several keys
Returns
– A numeric value

◆ keysToStream()

std::ostream & keysToStream ( const drain::Dictionary< key_t, T > &  dict,
ivalue_t  value,
std::ostream &  ostr,
char  separator = ',' 
)
static

Write keys in a stream, in numeric order.

List keys in their numeric order.

◆ valuesToList()

void valuesToList ( ivalue_t  value,
const drain::Dictionary< key_t, T > &  dict,
std::list< V > &  container 
)
static

Given a bit vector (integer value), extracts separate flag values to a list.

Traverses the dictionary and appends matching values in the list. The extracted values are of original type (integer or enum).


The documentation for this class was generated from the following files: