TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
Enumeration of int/string pairs. More...
#include <tsEnumeration.h>
Classes | |
struct | NameValue |
A structure used in the constructor of an Enumeration. More... | |
Public Types | |
using | const_iterator = std::multimap< int_t, UString >::const_iterator |
A constant iterator type for the content of the object. | |
using | int_t = int |
Integer type used in representations of values. | |
Public Member Functions | |
Enumeration ()=default | |
Default constructor. | |
Enumeration (std::initializer_list< NameValue > values) | |
Constructor from a variable list of string/value pairs. | |
template<typename INTENUM , typename std::enable_if< std::is_integral< INTENUM >::value||std::is_enum< INTENUM >::value >::type * = nullptr> | |
void | add (const UString &name, INTENUM value) |
Add a new enumeration value. | |
const_iterator | begin () const |
Return an iterator pointing to the first element of this object. | |
UString | bitMaskNames (int_t value, const UString &separator=u", ", bool hexa=false, size_t hexDigitCount=0) const |
Get the names from a bit-mask value. | |
bool | empty () const |
Check if the enumeration is empty. | |
const_iterator | end () const |
Return an iterator pointing after the last element of this object. | |
UString | error (const UString &name, bool caseSensitive=true, bool abbreviated=true, const UString &designator=u"name", const UString &prefix=UString()) const |
Get the error message about a name failing to match a value. | |
template<class CONTAINER > | |
void | getAllNames (CONTAINER &names) const |
Get all possible names in a string container. | |
template<typename INTENUM , typename std::enable_if< std::is_integral< INTENUM >::value||std::is_enum< INTENUM >::value >::type * = nullptr> | |
bool | getValue (INTENUM &e, const UString &name, bool caseSensitive=true, bool abbreviated=true) const |
Get the enumeration value from a name. | |
template<typename INT , typename std::enable_if< std::is_integral< INT >::value||std::is_enum< INT >::value >::type * = nullptr> | |
UString | name (INT value, bool hexa=false, size_t hexDigitCount=0) const |
Get the name from an enumeration value. | |
UString | nameList (const UString &separator=u", ", const UString &inQuote=UString(), const UString &outQuote=UString()) const |
Return a comma-separated list of all possible names. | |
template<class CONTAINER > | |
UString | names (const CONTAINER &container, const UString &separator=u", ") const |
Return a comma-separated list of all names for a list of integer values. | |
template<class ITERATOR > | |
UString | names (ITERATOR begin, ITERATOR end, const UString &separator=u", ") const |
Return a comma-separated list of all names for a list of integer values. | |
bool | operator== (const Enumeration &other) const |
Equality operator. | |
size_t | size () const |
Get the number of entries in the enumeration. | |
int_t | value (const UString &name, bool caseSensitive=true, bool abbreviated=true) const |
Get the value from a name. | |
Static Public Attributes | |
static const int_t | UNKNOWN |
This value means "not found". | |
Enumeration of int/string pairs.
This class is used to manage enumeration values. Here, by enumeration, we mean an association between strings and integers. The strings are manipulated as external values (command line parameters, report output, etc.) and the integers are manipulated as internal values. This class performs the association between these internal and external values.
Some interesting features are:
using ts::Enumeration::const_iterator = std::multimap<int_t, UString>::const_iterator |
A constant iterator type for the content of the object.
An iterator points to a pair of integer and string representing an element of the enumeration or more formally to a std::pair<int_t, UString>
.
Sample usage:
ts::Enumeration::Enumeration | ( | std::initializer_list< NameValue > | values | ) |
Constructor from a variable list of string/value pairs.
[in] | values | Variable list of name/value pairs. |
|
inline |
Equality operator.
[in] | other | Another instance to compare with. |
|
inline |
Get the number of entries in the enumeration.
|
inline |
Check if the enumeration is empty.
|
inline |
Add a new enumeration value.
INTENUM | An integer or enumeration type representing the values. |
[in] | name | A string for a symbol. |
[in] | value | The corresponding integer value. |
int_t ts::Enumeration::value | ( | const UString & | name, |
bool | caseSensitive = true , |
||
bool | abbreviated = true |
||
) | const |
Get the value from a name.
[in] | name | The string to search. This string may also contain an integer value in decimal or hexadecimal representation in which case this integer value is returned. |
[in] | caseSensitive | If false, the search is not case sensitive and name may match an equivalent string with distinct letter case. If true (the default), an exact match is required. |
[in] | abbreviated | If true (the default), any non-ambiguous abbreviation is valid. If false, a full name string must be provided. |
UNKNOWN
if not found or ambiguous, unless name can be interpreted as an integer value. If multiple integer values were registered with the same name, one of them is returned but which one is returned is unspecified. bool ts::Enumeration::getValue | ( | INTENUM & | e, |
const UString & | name, | ||
bool | caseSensitive = true , |
||
bool | abbreviated = true |
||
) | const |
Get the enumeration value from a name.
INTENUM | An integer or enumeration type representing the values. |
[out] | e | The enumeration value. Unmodified if name is not valid. If multiple integer values were registered with the same name, one of them is returned but which one is returned is unspecified. |
[in] | name | The string to search. This string may also contain an integer value in decimal or hexadecimal representation in which case this integer value is returned. |
[in] | caseSensitive | If false, the search is not case sensitive and name may match an equivalent string with distinct letter case. If true (the default), an exact match is required. |
[in] | abbreviated | If true (the default), any non-ambiguous abbreviation is valid. If false, a full name string must be provided. |
UString ts::Enumeration::error | ( | const UString & | name, |
bool | caseSensitive = true , |
||
bool | abbreviated = true , |
||
const UString & | designator = u"name" , |
||
const UString & | prefix = UString() |
||
) | const |
Get the error message about a name failing to match a value.
[in] | name | The string to search. |
[in] | caseSensitive | If false, the search is not case sensitive. |
[in] | abbreviated | If true, any non-ambiguous abbreviation is valid. |
[in] | designator | How to designate the name in the message (e.g. "name", "command", "option"). |
[in] | prefix | Prefix to prepend each candidate in case of ambiguous name. |
|
inline |
Get the name from an enumeration value.
INT | An integer or enumeration type. |
[in] | value | An enumeration value to search. |
[in] | hexa | If true and no name exists for value, return the value as an hexadecimal string with "0x" prefix instead of decimal. |
[in] | hexDigitCount | When an hexadecimal value is returned, specify the minimum number of digits. |
UString ts::Enumeration::bitMaskNames | ( | int_t | value, |
const UString & | separator = u", " , |
||
bool | hexa = false , |
||
size_t | hexDigitCount = 0 |
||
) | const |
Get the names from a bit-mask value.
The method is useful only when the integer values in the enumeration are bit-masks.
[in] | value | A bit-mask, built from integer values in the Enumeration object. |
[in] | separator | The separator to be used between values, a comma by default. |
[in] | hexa | If true and no name exists for a value, insert the value as an hexadecimal string with "0x" prefix instead of decimal. |
[in] | hexDigitCount | When an hexadecimal value is returned, specify the minimum number of digits. |
|
inline |
Return a comma-separated list of all names for a list of integer values.
CONTAINER | A container class of integer values as defined by the C++ Standard Template Library (STL). |
[in] | container | A container of integer values. |
[in] | separator | The separator to be used between values, a comma by default. |
UString ts::Enumeration::names | ( | ITERATOR | begin, |
ITERATOR | end, | ||
const UString & | separator = u", " |
||
) | const |
Return a comma-separated list of all names for a list of integer values.
The values are accessed through iterators in a container.
ITERATOR | An iterator class over integer values as defined by the C++ Standard Template Library (STL). |
[in] | begin | An iterator pointing to the first value. |
[in] | end | An iterator pointing after the last value. |
[in] | separator | The separator to be used between values, a comma by default. |
void ts::Enumeration::getAllNames | ( | CONTAINER & | names | ) | const |
Get all possible names in a string container.
CONTAINER | A container class of strings as defined by the C++ Standard Template Library (STL). |
[out] | names | A container of strings. |
UString ts::Enumeration::nameList | ( | const UString & | separator = u", " , |
const UString & | inQuote = UString() , |
||
const UString & | outQuote = UString() |
||
) | const |
Return a comma-separated list of all possible names.
[in] | separator | The separator to be used between values, a comma by default. |
[in] | inQuote | Opening quote for each name. |
[in] | outQuote | Closing quote for each name. |
|
inline |
Return an iterator pointing to the first element of this object.
|
inline |
Return an iterator pointing after the last element of this object.
|
static |
This value means "not found".
It is returned by methods which search an integer value.