Commit 21547b33 authored by Steffen Schotthöfer's avatar Steffen Schotthöfer
Browse files

commented optionstructure

parent 2c1d051d
Pipeline #119890 canceled with stages
......@@ -130,12 +130,10 @@ class Config
/*--- all_options is a map containing all of the options. This is used during config file parsing
to track the options which have not been set (so the default values can be used). Without this map
there would be no list of all the config file options. ---*/
std::map<std::string, bool> _allOptions;
/*--- brief param is a map from the option name (config file string) to its decoder (the specific child
class of COptionBase that turns the string into a value) ---*/
class of OptionBase that turns the string into a value) ---*/
std::map<std::string, OptionBase*> _optionMap;
// ---- Option Types ----
......
/*!
* \file OptionStructure.h
* \brief Classes for different Options in rtsn
* \author S. Schotthoefer
* \file optionstructure.h
* \brief Classes for different Options in KiT-RT
* \author S. Schotthöfer
*
* Disclaimer: This class structure was copied and modifed with open source permission from SU2 v7.0.3 https://su2code.github.io/
*
* Info: This is the backend for the option framework. Ideally, you should not change anything here.
* The only exception is, if you want to add a new option, i.e. an option of a new datatype.
* Orient yourself on the structure of similar option types, i.e. int option is similar to double option.
*/
#ifndef OPTION_STRUCTURE_H
......@@ -19,30 +23,30 @@ class OptionBase
{
private:
std::vector<std::string> _value;
std::vector<std::string> _value; /*! @brief: String name of the option */
public:
OptionBase(){};
virtual ~OptionBase() = 0;
virtual std::string SetValue( std::vector<std::string> value );
std::vector<std::string> GetValue();
virtual void SetDefault() = 0;
virtual std::string SetValue( std::vector<std::string> value ); /*! @brief: Set string name of the option */
std::string optionCheckMultipleValues( std::vector<std::string>& option_value, std::string type_id, std::string option_name );
std::vector<std::string> GetValue(); /*! @brief: Get string name of the option */
std::string badValue( std::vector<std::string>& option_value, std::string type_id, std::string option_name );
virtual void SetDefault() = 0; /*! @brief: Set default name for the option */
/*! @brief: Check if an option is defined multiple times in a config file, if yes, return a string stating this. */
std::string OptionCheckMultipleValues( std::vector<std::string>& option_value, std::string type_id, std::string option_name );
/*! @brief: If a bad value for an option is detected, this function creates the corresponding output string. */
std::string BadValue( std::vector<std::string>& option_value, std::string type_id, std::string option_name );
};
template <class Tenum> class OptionEnum : public OptionBase
{
std::map<std::string, Tenum> _map;
Tenum& _field; // Reference to the fieldname
Tenum _def; // Default value
std::string _name; // identifier for the option
std::map<std::string, Tenum> _map; /*! @brief: Map <String name of the option in cfg file, enum field name of cpp framework> */
Tenum& _field; /*! @brief: Reference to the enum fieldname */
Tenum _def; /*! @brief: Default value */
std::string _name; /*! @brief: string identifier for the option */
public:
OptionEnum( std::string option_field_name, const std::map<std::string, Tenum> m, Tenum& option_field, Tenum default_value )
......@@ -57,7 +61,7 @@ template <class Tenum> class OptionEnum : public OptionBase
std::string SetValue( std::vector<std::string> option_value ) override {
OptionBase::SetValue( option_value );
// Check if there is more than one string
std::string out = optionCheckMultipleValues( option_value, "enum", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "enum", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -81,9 +85,9 @@ template <class Tenum> class OptionEnum : public OptionBase
class OptionDouble : public OptionBase
{
double& _field; // Reference to the fieldname
double _def; // Default value
std::string _name; // identifier for the option
double& _field; /*! @brief: Reference to the double field value */
double _def; /*! @brief: Default value */
std::string _name; /*! @brief: String identifier for the option */
public:
OptionDouble( std::string option_field_name, double& option_field, double default_value );
......@@ -97,9 +101,9 @@ class OptionDouble : public OptionBase
class OptionString : public OptionBase
{
std::string& _field; // Reference to the fieldname
std::string _def; // Default value
std::string _name; // identifier for the option
std::string& _field; /*! @brief: Reference to the int field value */
std::string _def; /*! @brief: Default value */
std::string _name; /*! @brief: string identifier for the option */
public:
OptionString( std::string option_field_name, std::string& option_field, std::string default_value );
......@@ -113,9 +117,9 @@ class OptionString : public OptionBase
class OptionInt : public OptionBase
{
int& _field; // Reference to the feildname
int _def; // Default value
std::string _name; // identifier for the option
int& _field; /*! @brief: Reference to the int field value */
int _def; /*! @brief: Default value */
std::string _name; /*! @brief: string identifier for the option */
public:
OptionInt( std::string option_field_name, int& option_field, int default_value );
......@@ -129,9 +133,9 @@ class OptionInt : public OptionBase
class OptionULong : public OptionBase
{
unsigned long& _field; // Reference to the feildname
unsigned long _def; // Default value
std::string _name; // identifier for the option
unsigned long& _field; /*! @brief: Reference to the unsigned long field value */
unsigned long _def; /*! @brief: Default value */
std::string _name; /*! @brief: string identifier for the option */
public:
OptionULong( std::string option_field_name, unsigned long& option_field, unsigned long default_value );
......@@ -145,9 +149,9 @@ class OptionULong : public OptionBase
class OptionUShort : public OptionBase
{
unsigned short& _field; // Reference to the feildname
unsigned short _def; // Default value
std::string _name; // identifier for the option
unsigned short& _field; /*! @brief: Reference to the unsigned short field value */
unsigned short _def; /*! @brief: Default value */
std::string _name; /*! @brief: string identifier for the option */
public:
OptionUShort( std::string option_field_name, unsigned short& option_field, unsigned short default_value );
......@@ -161,9 +165,9 @@ class OptionUShort : public OptionBase
class OptionLong : public OptionBase
{
long& _field; // Reference to the feildname
long _def; // Default value
std::string _name; // identifier for the option
long& _field; /*! @brief: Reference to the long field value */
long _def; /*! @brief: Default value */
std::string _name; /*! @brief: string identifier for the option */
public:
OptionLong( std::string option_field_name, long& option_field, long default_value );
......@@ -177,9 +181,9 @@ class OptionLong : public OptionBase
class OptionBool : public OptionBase
{
bool& _field; // Reference to the feildname
bool _def; // Default value
std::string _name; // identifier for the option
bool& _field; /*! @brief: Reference to the bool field value */
bool _def; /*! @brief: Default value */
std::string _name; /*! @brief: string identifier for the option */
public:
OptionBool( std::string option_field_name, bool& option_field, bool default_value );
......@@ -193,9 +197,9 @@ class OptionBool : public OptionBase
class OptionStringList : public OptionBase
{
std::vector<std::string>& _field; // Reference to the fieldname
std::string _name; // identifier for the option
unsigned short& _size;
std::vector<std::string>& _field; /*! @brief: Reference to the string list field value. no default value */
std::string _name; /*! @brief: string identifier for the option */
unsigned short& _size; /*! @brief: Size of string list */
public:
OptionStringList( std::string option_field_name, unsigned short& list_size, std::vector<std::string>& option_field );
......
......@@ -19,7 +19,7 @@ std::string OptionBase::SetValue( std::vector<std::string> value ) {
return "";
}
std::string OptionBase::optionCheckMultipleValues( std::vector<std::string>& option_value, std::string type_id, std::string option_name ) {
std::string OptionBase::OptionCheckMultipleValues( std::vector<std::string>& option_value, std::string type_id, std::string option_name ) {
if( option_value.size() != 1 ) {
std::string newString;
newString.append( option_name );
......@@ -30,7 +30,7 @@ std::string OptionBase::optionCheckMultipleValues( std::vector<std::string>& opt
return "";
}
std::string OptionBase::badValue( std::vector<std::string>& option_value, std::string type_id, std::string option_name ) {
std::string OptionBase::BadValue( std::vector<std::string>& option_value, std::string type_id, std::string option_name ) {
std::string newString;
newString.append( option_name );
newString.append( ": improper option value for type " );
......@@ -48,7 +48,7 @@ OptionDouble::OptionDouble( std::string option_field_name, double& option_field,
std::string OptionDouble::SetValue( std::vector<std::string> option_value ) {
OptionBase::SetValue( option_value );
// check if there is more than one value
std::string out = optionCheckMultipleValues( option_value, "double", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "double", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -58,7 +58,7 @@ std::string OptionDouble::SetValue( std::vector<std::string> option_value ) {
this->_field = val;
return "";
}
return badValue( option_value, "double", this->_name );
return BadValue( option_value, "double", this->_name );
}
void OptionDouble::SetDefault() { this->_field = this->_def; }
......@@ -73,7 +73,7 @@ OptionString::OptionString( std::string option_field_name, std::string& option_f
std::string OptionString::SetValue( std::vector<std::string> option_value ) {
OptionBase::SetValue( option_value );
// check if there is more than one value
std::string out = optionCheckMultipleValues( option_value, "double", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "double", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -92,7 +92,7 @@ OptionInt::OptionInt( std::string option_field_name, int& option_field, int defa
std::string OptionInt::SetValue( std::vector<std::string> option_value ) {
OptionBase::SetValue( option_value );
std::string out = optionCheckMultipleValues( option_value, "int", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "int", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -102,7 +102,7 @@ std::string OptionInt::SetValue( std::vector<std::string> option_value ) {
this->_field = val;
return "";
}
return badValue( option_value, "int", this->_name );
return BadValue( option_value, "int", this->_name );
}
void OptionInt::SetDefault() { this->_field = this->_def; }
......@@ -115,7 +115,7 @@ OptionULong::OptionULong( std::string option_field_name, unsigned long& option_f
std::string OptionULong::SetValue( std::vector<std::string> option_value ) {
OptionBase::SetValue( option_value );
std::string out = optionCheckMultipleValues( option_value, "unsigned long", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "unsigned long", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -125,7 +125,7 @@ std::string OptionULong::SetValue( std::vector<std::string> option_value ) {
this->_field = val;
return "";
}
return badValue( option_value, "unsigned long", this->_name );
return BadValue( option_value, "unsigned long", this->_name );
}
void OptionULong::SetDefault() { this->_field = this->_def; }
......@@ -139,7 +139,7 @@ OptionUShort::OptionUShort( std::string option_field_name, unsigned short& optio
std::string OptionUShort::SetValue( std::vector<std::string> option_value ) {
OptionBase::SetValue( option_value );
std::string out = optionCheckMultipleValues( option_value, "unsigned short", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "unsigned short", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -149,7 +149,7 @@ std::string OptionUShort::SetValue( std::vector<std::string> option_value ) {
this->_field = val;
return "";
}
return badValue( option_value, "unsigned short", this->_name );
return BadValue( option_value, "unsigned short", this->_name );
}
void OptionUShort::SetDefault() { this->_field = this->_def; }
......@@ -163,7 +163,7 @@ OptionLong::OptionLong( std::string option_field_name, long& option_field, long
std::string OptionLong::SetValue( std::vector<std::string> option_value ) {
OptionBase::SetValue( option_value );
std::string out = optionCheckMultipleValues( option_value, "long", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "long", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -173,7 +173,7 @@ std::string OptionLong::SetValue( std::vector<std::string> option_value ) {
this->_field = val;
return "";
}
return badValue( option_value, "long", this->_name );
return BadValue( option_value, "long", this->_name );
}
void OptionLong::SetDefault() { this->_field = this->_def; }
......@@ -188,7 +188,7 @@ OptionBool::OptionBool( std::string option_field_name, bool& option_field, bool
std::string OptionBool::SetValue( std::vector<std::string> option_value ) {
OptionBase::SetValue( option_value );
// check if there is more than one value
std::string out = optionCheckMultipleValues( option_value, "bool", this->_name );
std::string out = OptionCheckMultipleValues( option_value, "bool", this->_name );
if( out.compare( "" ) != 0 ) {
return out;
}
......@@ -200,7 +200,7 @@ std::string OptionBool::SetValue( std::vector<std::string> option_value ) {
this->_field = false;
return "";
}
return badValue( option_value, "bool", this->_name );
return BadValue( option_value, "bool", this->_name );
}
void OptionBool::SetDefault() { this->_field = this->_def; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment