ArnLib
4.0.x
Active Registry Network
|
Class Enum text. More...
#include <MQFlags.hpp>
Classes | |
struct | IncludeMode |
Public Member Functions | |
EnumTxt (const QMetaObject *metaObj, bool isFlag, const _InitEnumTxt *initTxt, const _InitSubEnum *initSubEnum, const char *name) | |
EnumTxt (bool isFlag=false, const QString &name=QString()) | |
Create a dynamic runtime handled EnumTxt. More... | |
~EnumTxt () | |
void | setTxtRef (const char *txt, int enumVal, quint16 nameSpace) |
void | setTxt (const char *txt, int enumVal, quint16 nameSpace) |
Set an additional text for an enum val in a namespace. More... | |
const char * | getTxt (int enumVal, quint16 nameSpace=0, bool *isFound=arnNullptr) const |
Returns the text for a enum value in a namespace. More... | |
void | setTxtString (const QString &txt, int enumVal, quint16 nameSpace) |
Set an additional text for an enum val in a namespace. More... | |
QString | getTxtString (int enumVal, quint16 nameSpace=0, bool *isFound=arnNullptr) const |
Returns the text for a enum value in a namespace. More... | |
int | getEnumVal (const char *txt, int defaultVal=0, quint16 nameSpace=0, bool *isFound=arnNullptr) const |
Returns the enum value for a text in a namespace. More... | |
int | getEnumVal (const QString &txt, int defaultVal=0, quint16 nameSpace=0, bool *isFound=arnNullptr) const |
Returns the enum value for a text in a namespace. More... | |
bool | getSubEnumVal (const char *txt, int &subEnumVal, uint &bitMask, quint16 nameSpace=0) const |
Returns the shifted enum value and the mask for a subEnum text in a namespace. More... | |
bool | getSubEnumVal (const QString &txt, int &subEnumVal, uint &bitMask, quint16 nameSpace=0) const |
Returns the shifted enum value and the mask for a subEnum text in a namespace. More... | |
void | addFlagsTo (Arn::XStringMap &xsm, const IncludeMode &incMode, quint16 nameSpace=0, bool neverHumanize=false) const |
Adds enum flags to a XStringMap. More... | |
void | addSubEnumTo (Arn::XStringMap &xsm, quint16 nameSpace=0, bool neverHumanize=false) const |
Adds sub enum flags to a XStringMap. More... | |
void | addBitSetTo (Arn::XStringMap &xsm, quint16 nameSpace=0, bool neverHumanize=false) const |
Adds bit set for enum flags to a XStringMap. More... | |
void | addBitSet (Arn::XStringMap &xsm, quint16 nameSpace=0, bool neverHumanize=false) const |
QString | getBitSet (quint16 nameSpace=0, bool neverHumanize=false) const |
returns the bit set string for enum flags More... | |
void | addSubEnumPlainTo (Arn::XStringMap &xsm, quint16 nameSpace=0, bool neverHumanize=false) const |
Adds all sub enum plain and shifted to a XStringMap. More... | |
QString | flagsToString (int val, quint16 nameSpace=0) const |
returns text string for enum flags More... | |
QStringList | flagsToStringList (int val, quint16 nameSpace=0) const |
returns string list for enum flags More... | |
int | flagsFromString (const QString &flagString, quint16 nameSpace=0) |
returns enum flags from string More... | |
int | flagsFromStringList (const QStringList &flagStrings, quint16 nameSpace=0) |
returns enum flags from string list More... | |
void | addEnumSetTo (Arn::XStringMap &xsm, quint16 nameSpace=0, bool neverHumanize=false) const |
Adds enum set to a XStringMap. More... | |
void | addEnumSet (Arn::XStringMap &xsm, quint16 nameSpace=0, bool neverHumanize=false) const |
QString | getEnumSet (quint16 nameSpace=0, bool neverHumanize=false) const |
returns the enum set string More... | |
QStringList | getBasicTextList (quint16 nameSpace=0, bool neverHumanize=false) const |
returns a string list containing the most basic texts More... | |
void | addSubEnum (const EnumTxt &subEnum, uint bitMask, uint factor) |
Adds an other EnumTxt as a subEnum to this flag EnumTxt. More... | |
const char * | name () const |
returns the name of the enum (class) More... | |
int | enumCount () const |
returns number of enumerators in the enum (class) More... | |
void | setMissingTxt (quint16 toNameSpace, quint16 fromNameSpace=0, bool neverHumanize=false) |
Copies missing enum texts from one namespace to another. More... | |
bool | isFlag () const |
Returns true if this is a flag usage. More... | |
void | clear () |
Clear this dynamic instance to its starting state. More... | |
bool | loadEnumSet (const Arn::XStringMap &xsm, const QString &name=QString()) |
Loads the instance by an enum set XStringMap. More... | |
bool | loadEnumSet (const QString &xstr, const QString &name=QString()) |
Loads the instance by an enum set XString. More... | |
bool | loadBitSet (const Arn::XStringMap &xsm, const QString &name=QString()) |
Loads the instance by an bit set (flags) XStringMap. More... | |
bool | loadBitSet (const QString &xstr, const QString &name=QString()) |
Loads the instance by an bit set (flags) XString. More... | |
int | subEnumCount () const |
Returns number of subEnums in this bitSet (class) More... | |
QString | subEnumNameAt (int idx, quint16 nameSpace=0) const |
Returns the name of a SubEnum. More... | |
bool | subEnumPropAt (int idx, uint &bitMask, uchar &bitPos) const |
Returns the properties of a SubEnum. More... | |
const EnumTxt * | subEnumAt (int idx) const |
Returns a pointer to a SubEnum. More... | |
Static Public Member Functions | |
static QString | humanize (const QString &txt) |
returns the humanized text More... | |
static QByteArray | numToStr (uint num) |
static uint | strToNum (const QByteArray &str, bool *isOk=arnNullptr) |
static uchar | strToBitpos (const QByteArray &str, bool *isOk=arnNullptr) |
Class Enum text.
Example usage
Definition at line 212 of file MQFlags.hpp.
Arn::EnumTxt::EnumTxt | ( | const QMetaObject * | metaObj, |
bool | isFlag, | ||
const _InitEnumTxt * | initTxt, | ||
const _InitSubEnum * | initSubEnum, | ||
const char * | name | ||
) |
Definition at line 63 of file MQFlags.cpp.
|
explicit |
Create a dynamic runtime handled EnumTxt.
This is used for handling general Enums that is not statically assigned via QMetaObject. Example usage
[in] | isFlag | is true when using Flags (bitSet), otherwise use plain Enums. |
[in] | name | is the name of these Enums / Flags. |
Definition at line 77 of file MQFlags.cpp.
Arn::EnumTxt::~EnumTxt | ( | ) |
Definition at line 87 of file MQFlags.cpp.
|
inline |
Definition at line 399 of file MQFlags.hpp.
void Arn::EnumTxt::addBitSetTo | ( | Arn::XStringMap & | xsm, |
quint16 | nameSpace = 0 , |
||
bool | neverHumanize = false |
||
) | const |
Adds bit set for enum flags to a XStringMap.
Example
wiil give xsm containing: T=Test B0=Read B3=Create B4=Delete 0=None 0xff=All SE6:B1=AllowLev E0=Low E1=Mid E2=High
[out] | xsm | is the XStringMap to be added to. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 262 of file MQFlags.cpp.
|
inline |
Definition at line 503 of file MQFlags.hpp.
void Arn::EnumTxt::addEnumSetTo | ( | Arn::XStringMap & | xsm, |
quint16 | nameSpace = 0 , |
||
bool | neverHumanize = false |
||
) | const |
Adds enum set to a XStringMap.
Example
wiil give xsm containing: T=Test 0=Init 1=Connected 2=Error 3=Disconnected 4=Tried all
[out] | xsm | is the XStringMap to be added to. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 406 of file MQFlags.cpp.
void Arn::EnumTxt::addFlagsTo | ( | Arn::XStringMap & | xsm, |
const IncludeMode & | incMode, | ||
quint16 | nameSpace = 0 , |
||
bool | neverHumanize = false |
||
) | const |
Adds enum flags to a XStringMap.
Example
wiil give xsm containing: T=Test B0=Read B3=Create B4=Delete
[out] | xsm | is the XStringMap to be added to. |
[in] | incMode | specifies what to include (SingleBits / MultiBits / SubEnumBits / "Any"). |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 193 of file MQFlags.cpp.
void Arn::EnumTxt::addSubEnum | ( | const EnumTxt & | subEnum, |
uint | bitMask, | ||
uint | factor | ||
) |
Adds an other EnumTxt as a subEnum to this flag EnumTxt.
Example
[in] | subEnum | is the other EnumTxt to be included as a subEnum. |
[in] | bitMask | is used for selecting the subEnum among the flags. |
[in] | factor | is multiplying the base enum before it is masked in as subEnum to flags. |
Definition at line 451 of file MQFlags.cpp.
void Arn::EnumTxt::addSubEnumPlainTo | ( | Arn::XStringMap & | xsm, |
quint16 | nameSpace = 0 , |
||
bool | neverHumanize = false |
||
) | const |
Adds all sub enum plain and shifted to a XStringMap.
Also adds bitmask and name of the sub enum All enums must have unique names Example
wiil give xsm containing: T=Test 6=AllowLev 0=Low 2=Mid 4=High
[out] | xsm | is the XStringMap to be added to. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 281 of file MQFlags.cpp.
void Arn::EnumTxt::addSubEnumTo | ( | Arn::XStringMap & | xsm, |
quint16 | nameSpace = 0 , |
||
bool | neverHumanize = false |
||
) | const |
Adds sub enum flags to a XStringMap.
Example
wiil give xsm containing: T=Test SE6:B1=AllowLev E0=Low E1=Mid E2=High
[out] | xsm | is the XStringMap to be added to. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 236 of file MQFlags.cpp.
void Arn::EnumTxt::clear | ( | ) |
Clear this dynamic instance to its starting state.
Clear will do nothing if this instance was created staticly with a QMetaObject.
Definition at line 574 of file MQFlags.cpp.
int Arn::EnumTxt::enumCount | ( | ) | const |
returns number of enumerators in the enum (class)
Example
qDebug() << ConnectStatT::txt().enumCount();
wiil print: 5
Definition at line 736 of file MQFlags.cpp.
int Arn::EnumTxt::flagsFromString | ( | const QString & | flagString, |
quint16 | nameSpace = 0 |
||
) |
returns enum flags from string
Example
wiil give val: 0x18 (0x08 + 0x10 + 0x00)
[in] | flagString | is the flags text. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
Definition at line 354 of file MQFlags.cpp.
int Arn::EnumTxt::flagsFromStringList | ( | const QStringList & | flagStrings, |
quint16 | nameSpace = 0 |
||
) |
returns enum flags from string list
Example
wiil give val: 0x1c (0x08 + 0x10 + 0x04)
[in] | flagStrings | is the flags text list. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
Definition at line 362 of file MQFlags.cpp.
QString Arn::EnumTxt::flagsToString | ( | int | val, |
quint16 | nameSpace = 0 |
||
) | const |
returns text string for enum flags
Example
wiil print: "Create | Delete | Mid"
[in] | val | is the flags enum value. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
Definition at line 305 of file MQFlags.cpp.
QStringList Arn::EnumTxt::flagsToStringList | ( | int | val, |
quint16 | nameSpace = 0 |
||
) | const |
returns string list for enum flags
Example
wiil give allowList containing: "Create", "Delete", "Low"
[in] | val | is the flags enum value. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
Definition at line 313 of file MQFlags.cpp.
QStringList Arn::EnumTxt::getBasicTextList | ( | quint16 | nameSpace = 0 , |
bool | neverHumanize = false |
||
) | const |
returns a string list containing the most basic texts
For a EnumSet this is the complete text list. For a BitSet this is the texts for all the single 1-bits except those used for SubEnums. Example
qDebug() << AllowClassT::txt().getBasicTextList( 0, true);
wiil print: "Read" "Create" "Delete"
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 437 of file MQFlags.cpp.
QString Arn::EnumTxt::getBitSet | ( | quint16 | nameSpace = 0 , |
bool | neverHumanize = false |
||
) | const |
returns the bit set string for enum flags
Example
qDebug() << AllowClassT::txt().getBitSet();
wiil print: "B0=Read B3=Create B4=Delete 0=None 0xff=All SE6:B1=AllowLev E0=Low E1=Mid E2=High"
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 271 of file MQFlags.cpp.
QString Arn::EnumTxt::getEnumSet | ( | quint16 | nameSpace = 0 , |
bool | neverHumanize = false |
||
) | const |
returns the enum set string
Example
qDebug() << ConnectStatT::txt().getEnumSet();
wiil print: "0=Init 1=Connected 2=Error 3=Disconnected 4=Tried_all"
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 429 of file MQFlags.cpp.
int Arn::EnumTxt::getEnumVal | ( | const char * | txt, |
int | defaultVal = 0 , |
||
quint16 | nameSpace = 0 , |
||
bool * | isFound = arnNullptr |
||
) | const |
Returns the enum value for a text in a namespace.
[in] | txt | is the enum text. |
[in] | defaultVal | is the returned value when txt is not found. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[out] | isFound | returns status when pointer is none null. |
Definition at line 142 of file MQFlags.cpp.
int Arn::EnumTxt::getEnumVal | ( | const QString & | txt, |
int | defaultVal = 0 , |
||
quint16 | nameSpace = 0 , |
||
bool * | isFound = arnNullptr |
||
) | const |
Returns the enum value for a text in a namespace.
[in] | txt | is the enum text. |
[in] | defaultVal | is the returned value when txt is not found. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[out] | isFound | returns status when pointer is none null. |
Definition at line 163 of file MQFlags.cpp.
bool Arn::EnumTxt::getSubEnumVal | ( | const char * | txt, |
int & | subEnumVal, | ||
uint & | bitMask, | ||
quint16 | nameSpace = 0 |
||
) | const |
Returns the shifted enum value and the mask for a subEnum text in a namespace.
The enum value returned is shifted (with factor) to directly fit the flags enum. Example usage
wiil print: 2 and 6
[in] | txt | is the subEnum text. |
[out] | subEnumVal | is the returned shifted value when txt is found as a subEnum. |
[out] | bitMask | is the returned value when txt is found as a subEnum. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
is | true when txt is found as a subEnum. |
Definition at line 169 of file MQFlags.cpp.
bool Arn::EnumTxt::getSubEnumVal | ( | const QString & | txt, |
int & | subEnumVal, | ||
uint & | bitMask, | ||
quint16 | nameSpace = 0 |
||
) | const |
Returns the shifted enum value and the mask for a subEnum text in a namespace.
The enum value returned is shifted (with factor) to directly fit the flags enum. Example usage
wiil print: 4 and 6
[in] | txt | is the subEnum text. |
[out] | subEnumVal | is the returned shifted value when txt is found as a subEnum. |
[out] | bitMask | is the returned value when txt is found as a subEnum. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
is | true when txt is found as a subEnum. |
Definition at line 187 of file MQFlags.cpp.
const char * Arn::EnumTxt::getTxt | ( | int | enumVal, |
quint16 | nameSpace = 0 , |
||
bool * | isFound = arnNullptr |
||
) | const |
Returns the text for a enum value in a namespace.
[in] | enumVal | is the referenced value. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[out] | isFound | returns status when pointer is none null. |
Definition at line 121 of file MQFlags.cpp.
QString Arn::EnumTxt::getTxtString | ( | int | enumVal, |
quint16 | nameSpace = 0 , |
||
bool * | isFound = arnNullptr |
||
) | const |
Returns the text for a enum value in a namespace.
[in] | enumVal | is the referenced value. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
[out] | isFound | returns status when pointer is none null. |
Definition at line 136 of file MQFlags.cpp.
|
static |
returns the humanized text
The input text can be Chamel-case or '_' word separeted. First output char will always be upper case and the following chars will always be lower case.
Example output
[in] | txt | is the text to be humanized. |
Definition at line 497 of file MQFlags.cpp.
bool Arn::EnumTxt::isFlag | ( | ) | const |
Returns true if this is a flag usage.
is | true when this is a flag, false when plain enum. |
Definition at line 568 of file MQFlags.cpp.
bool Arn::EnumTxt::loadBitSet | ( | const Arn::XStringMap & | xsm, |
const QString & | name = QString() |
||
) |
Loads the instance by an bit set (flags) XStringMap.
Example output
[in] | xsm | is the XStringMap containing the flags representation. |
[in] | name | is the name of this flag collection. |
returns | true if successful. |
Definition at line 625 of file MQFlags.cpp.
bool Arn::EnumTxt::loadBitSet | ( | const QString & | xstr, |
const QString & | name = QString() |
||
) |
Loads the instance by an bit set (flags) XString.
Example output
[in] | xstr | is the XString containing the flags representation. |
[in] | name | is the name of this flag collection. |
returns | true if successful. |
Definition at line 689 of file MQFlags.cpp.
bool Arn::EnumTxt::loadEnumSet | ( | const Arn::XStringMap & | xsm, |
const QString & | name = QString() |
||
) |
Loads the instance by an enum set XStringMap.
Example output
[in] | xsm | is the XStringMap containing the enum representation. |
[in] | name | is the name of this enum collection. |
returns | true if successful. |
Definition at line 599 of file MQFlags.cpp.
bool Arn::EnumTxt::loadEnumSet | ( | const QString & | xstr, |
const QString & | name = QString() |
||
) |
Loads the instance by an enum set XString.
Example output
[in] | xstr | is the XString containing the enum representation. |
[in] | name | is the name of this enum collection. |
returns | true if successful. |
Definition at line 619 of file MQFlags.cpp.
const char * Arn::EnumTxt::name | ( | ) | const |
returns the name of the enum (class)
Example
qDebug() << ConnectStatT::txt().name();
wiil print: "ConnectStatT"
Definition at line 730 of file MQFlags.cpp.
|
static |
Definition at line 745 of file MQFlags.cpp.
void Arn::EnumTxt::setMissingTxt | ( | quint16 | toNameSpace, |
quint16 | fromNameSpace = 0 , |
||
bool | neverHumanize = false |
||
) |
Copies missing enum texts from one namespace to another.
The standard 0 namespace contains all enum texts as defined and can not be altered. All the other wanted namespaces can have customized enum texts, but then there can be enum values without a text in such namespace. This function can be used to fill in those missing texts from another namespace, which typically is 0 as it contains all texts.
[in] | toNameSpace | is the altered one. Can not be 0. |
[in] | fromNameSpace | is the one to copy from. |
[in] | neverHumanize | if true never applies the enum text humanize algorithm. |
Definition at line 469 of file MQFlags.cpp.
void Arn::EnumTxt::setTxt | ( | const char * | txt, |
int | enumVal, | ||
quint16 | nameSpace | ||
) |
Set an additional text for an enum val in a namespace.
The namespace with index 0 is the standard namespace that automatically gets its texts from the definition of the enum.
Example usage
wiil print: "Create" and "Test - Create"
[in] | txt | is the new enum text. |
[in] | enumVal | is the referenced value. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
Definition at line 107 of file MQFlags.cpp.
void Arn::EnumTxt::setTxtRef | ( | const char * | txt, |
int | enumVal, | ||
quint16 | nameSpace | ||
) |
Definition at line 100 of file MQFlags.cpp.
void Arn::EnumTxt::setTxtString | ( | const QString & | txt, |
int | enumVal, | ||
quint16 | nameSpace | ||
) |
Set an additional text for an enum val in a namespace.
[in] | txt | is the new enum text. |
[in] | enumVal | is the referenced value. |
[in] | nameSpace | is the usage set for this enum, e.g human readable. |
Definition at line 130 of file MQFlags.cpp.
|
static |
Definition at line 765 of file MQFlags.cpp.
|
static |
Definition at line 754 of file MQFlags.cpp.
const EnumTxt * Arn::EnumTxt::subEnumAt | ( | int | idx | ) | const |
Returns a pointer to a SubEnum.
Example output
wiil print: "0=Low 1=Mid 2=High"
[in] | idx | is the index of the SubEnum. |
returns | a pointer to SubEnum for inbound idx, otherwise arnNullPtr. |
Definition at line 722 of file MQFlags.cpp.
int Arn::EnumTxt::subEnumCount | ( | ) | const |
Returns number of subEnums in this bitSet (class)
Example
qDebug() << AllowClassT::txt().subEnumCount();
wiil print: 1
Definition at line 695 of file MQFlags.cpp.
QString Arn::EnumTxt::subEnumNameAt | ( | int | idx, |
quint16 | nameSpace = 0 |
||
) | const |
Returns the name of a SubEnum.
Name is taken by the registered bitmask of the SubEnum. When using static creation of this instance, there must be a declared enum for the bitmask of the SubEnum. E.g. in AllowClassT this enum is AllowLev. When using dynamic creation of flags, loading a BitSet, the name of the SubEnum is set in the process. This is also true when using addSubEnum(). Example
qDebug() << AllowClassT::txt().subEnumNameAt( 0);
wiil print: "AllowLev"
[in] | idx | is the index of the SubEnum. |
[in] | nameSpace | is the nameSpace for the registered name (by bitMask). |
returns | the SubEnum name for inbound idx, otherwise QString(). |
Definition at line 702 of file MQFlags.cpp.
bool Arn::EnumTxt::subEnumPropAt | ( | int | idx, |
uint & | bitMask, | ||
uchar & | bitPos | ||
) | const |
Returns the properties of a SubEnum.
Example
uint bitMask; uchar bitPos; qDebug() << AllowClassT::txt().subEnumNameAt( 0, bitMask, bitPos) << bitMask << bitPos;
wiil print: true 6 1
[in] | idx | is the index of the SubEnum. |
[out] | bitMask | is the bitmask for the SubEnum. |
[out] | bitPos | is the position for the starting bit of the SubEnum. |
returns | true for inbound idx, otherwise false. |
Definition at line 711 of file MQFlags.cpp.