NANDRAD Data Model Library  Version 2.0
NANDRAD
NANDRAD::KeywordList Class Reference

Detailed Description

The class KeywordList provides conversion functionality between keyword strings and their respective enumeration values.

Keyword strings are used in the NANDRAD project files as identifier. In the code we use the enumeration values. You can obtain a keyword for a given enumeration value with the static function Keyword(). The corresponding enumeration value can be obtained with Enumeration(), as shown in the example below.

// to get the keyword string use
string kw = KeywordList::Keyword("Assignment::type_t", Assignment::ST_MATERIAL);
// and to get the enumeration value
Assignment::type_t t = KeywordList::Enumeration("Assignment::type_t}", kw);
// the string "Assignment::type_t" is the full enumeration type and formed from the class
// name and the enumeration type name

Remember to pass the correct and full enumeration type as first argument to Keyword.

Note
Instead of overloading the Keyword() function for different types in the current implementation we use a generic form in order to avoid adding compilation dependencies for all CPP files in the project that include the keyword list.

Definition at line 53 of file NANDRAD_KeywordList.h.

#include <NANDRAD_KeywordList.h>

Static Public Member Functions

static const char * Keyword (const char *const enumtype, int t)
 Returns a keyword for an enum value t of type enumtype. More...
 
static const char * Description (const char *const enumtype, int t, bool *no_description=nullptr)
 Returns a description for an enum value t of type enumtype. More...
 
static const char * Unit (const char *const enumtype, int t)
 Returns a default unit for an enum value t of type enumtype. More...
 
static const char * Color (const char *const enumtype, int t)
 Returns a color string for an enum value t of type enumtype. More...
 
static double DefaultValue (const char *const enumtype, int t)
 Returns a default value for an enum value t of type enumtype. More...
 
static int Enumeration (const char *const enumtype, const std::string &kw, bool *deprecated=nullptr)
 Returns an enumeration value for a given keyword kw of type enumtype. More...
 
static int MaxIndex (const char *const enumtype)
 Returns the maximum index for entries of a category in the keyword list. More...
 
static unsigned int Count (const char *const enumtype)
 Returns the number of keywords in this category. More...
 
static bool KeywordExists (const char *const enumtype, const std::string &kw)
 Checks whether a keyword exists in the enumeration of type enumtype. More...
 
static bool CategoryExists (const char *const enumtype)
 Checks whether a category of type enumtype exists. More...
 
static void setParameter (IBK::Parameter para[], const char *const enumtype, int n, const double &val)
 Convenience function to set an IBK::Parameter inside a static C-array of IBK::Parameters with correct name, value and unit. More...
 
static void setIntPara (IBK::IntPara para[], const char *const enumtype, int n, const int &val)
 As setParameter(), but for IBK::IntPara. More...
 

Member Function Documentation

◆ Keyword()

static const char* NANDRAD::KeywordList::Keyword ( const char *const  enumtype,
int  t 
)
static

Returns a keyword for an enum value t of type enumtype.

◆ Description()

static const char* NANDRAD::KeywordList::Description ( const char *const  enumtype,
int  t,
bool *  no_description = nullptr 
)
static

Returns a description for an enum value t of type enumtype.

This function throws an exception if the enumeration type is invalid or unknown. If no descrption is given, the keyword itself is returned.

Parameters
enumtypeThe full enumeration type including the class name.
tThe enumeration type cast in an int.
no_descriptionThe optional argument is set to true, if there was no description for this keyword, otherwise to false.

◆ Unit()

static const char* NANDRAD::KeywordList::Unit ( const char *const  enumtype,
int  t 
)
static

Returns a default unit for an enum value t of type enumtype.

This function throws an exception if the enumeration type is invalid or unknown. Returns an empty string if no default unit was specified.

Parameters
enumtypeThe full enumeration type including the class name.
tThe enumeration type cast in an int.

◆ Color()

static const char* NANDRAD::KeywordList::Color ( const char *const  enumtype,
int  t 
)
static

Returns a color string for an enum value t of type enumtype.

This function throws an exception if the enumeration type is invalid or unknown. Returns the color code for 'white' if no color value was specified.

Parameters
enumtypeThe full enumeration type including the class name.
tThe enumeration type cast in an int.

◆ DefaultValue()

static double NANDRAD::KeywordList::DefaultValue ( const char *const  enumtype,
int  t 
)
static

Returns a default value for an enum value t of type enumtype.

This function throws an exception if the enumeration type is invalid or unknown. Returns an nan if no default value was specified.

Parameters
enumtypeThe full enumeration type including the class name.
tThe enumeration type cast in an int.

◆ Enumeration()

static int NANDRAD::KeywordList::Enumeration ( const char *const  enumtype,
const std::string &  kw,
bool *  deprecated = nullptr 
)
static

Returns an enumeration value for a given keyword kw of type enumtype.

This function throws an exception if the keyword or the enumeration type is invalid or unknown.

Parameters
enumtypeThe full enumeration type including the class name.
kwThe keyword string.
deprecatedThe optional argument is set the true if the keyword kw is deprecated.

◆ MaxIndex()

static int NANDRAD::KeywordList::MaxIndex ( const char *const  enumtype)
static

Returns the maximum index for entries of a category in the keyword list.

This function throws an exception if the enumeration type is invalid or unknown.

Parameters
enumtypeThe full enumeration type including the class name.

◆ Count()

static unsigned int NANDRAD::KeywordList::Count ( const char *const  enumtype)
static

Returns the number of keywords in this category.

This function throws an exception if the enumeration type is invalid or unknown.

Parameters
enumtypeThe full enumeration type including the class name.

◆ KeywordExists()

static bool NANDRAD::KeywordList::KeywordExists ( const char *const  enumtype,
const std::string &  kw 
)
static

Checks whether a keyword exists in the enumeration of type enumtype.

Returns
Returns true if the keyword is valid, otherwise false.

◆ CategoryExists()

static bool NANDRAD::KeywordList::CategoryExists ( const char *const  enumtype)
static

Checks whether a category of type enumtype exists.

Returns
Returns true if the category/enum type exists, otherwise false.

◆ setParameter()

static void NANDRAD::KeywordList::setParameter ( IBK::Parameter  para[],
const char *const  enumtype,
int  n,
const double &  val 
)
static

Convenience function to set an IBK::Parameter inside a static C-array of IBK::Parameters with correct name, value and unit.

// Example: in declaration of class 'MyClass'
enum MyParameters {
MP_Temperature, // Keyword: Temperature [C] 'Some temperatures'
MP_Mass, // Keyword: Mass [kg] 'Some mass'
NUM_MP
};
// static array with parameter values
IBK::Parameter m_para[NUM_MP];
// setting the parameter in code
NANDRAD::setParameter(m_para, "MyClass::MyParameters", MP_Temperature, 23.5);
NANDRAD::setParameter(m_para, "MyClass::MyParameters", MP_Mass, 1500);
Parameters
paraPointer to begin of array with IBK::Parameters
enumtypeThe enumeration type (class::enumtypename)
nEnumeration value (which parameter to set)
valThe value (given in the unit specified for the parameter; requires a unit to be given)

◆ setIntPara()

static void NANDRAD::KeywordList::setIntPara ( IBK::IntPara  para[],
const char *const  enumtype,
int  n,
const int &  val 
)
static

As setParameter(), but for IBK::IntPara.


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