A class containing a set of integer values with names. More...
Public Member Functions | |
QtlNamedIntSet (QtlLogger *log=0) | |
Constructor. More... | |
QtlNamedIntSet (const QtlNamedIntSet &other) | |
Copy constructor. More... | |
bool | addDefinition (const QString &definition) |
Add a definition of the form "value = name". More... | |
bool | addDefinitions (const QStringList &definitions) |
Add a list of definitions of the form "value = name". More... | |
void | addValue (quint32 value, const QString &name) |
Add a value. More... | |
int | defaultBase () const |
Get the default base for name(). More... | |
quint32 | defaultValue () const |
Get the default value for value(). More... | |
int | defaultWidth () const |
Get the default width for name(). More... | |
bool | hasName (quint32 value) const |
Check if an integer has a name. More... | |
bool | loadDefinitions (const QString &fileName) |
Load a list of definitions of the form "value = name" from a file. More... | |
QString | name (quint32 value, int defaultBase=-1, bool addBasePrefix=true, int width=-1) const |
Get the name of an integer. More... | |
QStringList | names () const |
Get a list of all names. More... | |
const QtlNamedIntSet & | operator= (const QtlNamedIntSet &other) |
Assignment. More... | |
void | setDefaultBase (int defaultBase) |
Set the default base for name(). More... | |
void | setDefaultValue (const quint32 &defaultValue) |
Set the default value for value(). More... | |
void | setDefaultWidth (int defaultWidth) |
Set the default width for name(). More... | |
quint32 | value (const QString &name) const |
Get a value from a name. More... | |
quint32 | value (const QString &name, quint32 defaultValue) const |
Get a value from a name. More... | |
Private Types | |
typedef QMap< QString, quint32 > | MapByName |
Translate names to values. More... | |
Private Attributes | |
int | _defaultBase |
Default base for name(). More... | |
quint32 | _defaultValue |
Default value for value(). More... | |
int | _defaultWidth |
Default width for name(). More... | |
QtlLogger * | _log |
Where to log errors. More... | |
MapByName | _mapByName |
Translate names to values. More... | |
A class containing a set of integer values with names.
The values are 32-bit unsigned integers (quint32).
|
private |
Translate names to values.
|
explicit |
Constructor.
[in] | log | Where to log errors. Ignored if zero. |
QtlNamedIntSet::QtlNamedIntSet | ( | const QtlNamedIntSet & | other | ) |
Copy constructor.
[in] | other | Other instance to copy. |
const QtlNamedIntSet & QtlNamedIntSet::operator= | ( | const QtlNamedIntSet & | other | ) |
Assignment.
[in] | other | Other instance to copy. |
void QtlNamedIntSet::addValue | ( | quint32 | value, |
const QString & | name | ||
) |
Add a value.
If a value with the same name already exists, replace it.
[in] | value | Integer value to add. |
[in] | name | Name of the value. |
bool QtlNamedIntSet::addDefinition | ( | const QString & | definition | ) |
Add a definition of the form "value = name".
Empty lines or lines starting with '#' are ignored. If a value with the same name already exists, replace it. Errors are logged if a logger was specified.
[in] | definition | A string of the form "value = name". Base prefix like "0x" or "0" are recognized in the value. |
bool QtlNamedIntSet::addDefinitions | ( | const QStringList & | definitions | ) |
Add a list of definitions of the form "value = name".
Empty lines or lines starting with '#' are ignored. If a value with the same name already exists, replace it. Errors are logged if a logger was specified.
[in] | definitions | A list of strings of the form "value = name". Base prefix like "0x" or "0" are recognized in the value. |
bool QtlNamedIntSet::loadDefinitions | ( | const QString & | fileName | ) |
Load a list of definitions of the form "value = name" from a file.
Empty lines or lines starting with '#' are ignored. If a value with the same name already exists, replace it. Errors are logged if a logger was specified.
[in] | fileName | A text file containing lines of the form "value = name". Base prefix like "0x" or "0" are recognized in the value. |
QStringList QtlNamedIntSet::names | ( | ) | const |
Get a list of all names.
|
inline |
Get a value from a name.
[in] | name | Name of the value or a string representation of an integer. |
quint32 QtlNamedIntSet::value | ( | const QString & | name, |
quint32 | defaultValue | ||
) | const |
Get a value from a name.
[in] | name | Name of the value or a string representation of an integer. |
[in] | defaultValue | Default value to return if name is unknown. |
QString QtlNamedIntSet::name | ( | quint32 | value, |
int | defaultBase = -1 , |
||
bool | addBasePrefix = true , |
||
int | width = -1 |
||
) | const |
Get the name of an integer.
If several names have the same value, return one of these names. If no name exists, a string representation of the value is returned.
[in] | value | The value to get the name of. |
[in] | defaultBase | If value has no name, base of the string representation. Valid values are 10, 16 and 8. If a negative value is specified, use defaultBase(). For any other value, return an empty string. |
[in] | addBasePrefix | If defaultBase is 16 or 8, add the standard prefix "0x" or "0". |
[in] | width | If value has no name, gives the width of the value representation, not including the prefix. If a negative value is specified, use defaultWidth(). If zero is specified, do not justify. |
|
inline |
Check if an integer has a name.
[in] | value | The value to check the name of. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
Where to log errors.
|
private |
Translate names to values.
|
private |
Default value for value().
|
private |
Default base for name().
|
private |
Default width for name().