Loading [MathJax]/extensions/ams.js
 |
ALMaSS
1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
|
A class to provide standard parameter entry facilities.
More...
#include <Configurator.h>
|
void | SetCfgInt (std::string a_key, std::string a_val) |
|
void | SetCfgFloat (std::string a_key, std::string a_val) |
|
void | SetCfgBool (std::string a_key, std::string a_val) |
|
void | SetCfgStr (std::string a_key, std::string a_val) |
|
void | SetCfgArrayInt (std::string a_key, std::string a_val) |
|
void | SetCfgArrayDouble (std::string a_key, std::string a_val) |
|
void | SetCfgArrayIntCsv (std::string a_key, std::string a_val) |
|
void | SetCfgArrayDoubleCsv (std::string a_key, std::string a_val) |
|
void | SetCfgFunction (std::string a_key, std::string a_val) |
|
void | DumpPublicSymbols (const char *a_dumpfile, CfgSecureLevel a_level) |
|
void | DumpAllSymbolsAndExit (const char *a_dumpfile) |
|
bool | ReadSymbols (const char *a_cfgfile) |
|
| Configurator (void) |
|
| ~Configurator (void) |
|
bool | Register (CfgBase *a_cfgval, const std::string &a_key) |
|
bool | Register (std::shared_ptr< CfgBase > a_cfgval, const std::string &a_key) |
|
void | StoreFromConfig (const std::string &name, std::string type, std::string value) |
|
bool | CheckBounds (std::shared_ptr< CfgBase > a_cfgval, CfgBase *b_cfgval) |
|
std::vector< int > | ParseArrayInt (const std::string &a_stringtoparse) |
|
std::vector< double > | ParseArrayDouble (const std::string &a_stringtoparse) |
|
A class to provide standard parameter entry facilities.
◆ Configurator()
Configurator::Configurator |
( |
void |
| ) |
|
◆ ~Configurator()
Configurator::~Configurator |
( |
void |
| ) |
|
◆ CheckBounds()
bool Configurator::CheckBounds |
( |
std::shared_ptr< CfgBase > |
a_cfgval, |
|
|
CfgBase * |
b_cfgval |
|
) |
| |
Function checks that values in the configfile a_cfgval and in the var b_cfgval are in line
1278 if (b_cfgval->
gettype()!=a_cfgval->gettype()){
1280 "Mismatched config variable types",
1284 switch (b_cfgval->
gettype()) {
1286 if ((b_cfgval->
get_rangetest())&&(std::dynamic_pointer_cast<CfgInt>(a_cfgval)->value()>dynamic_cast<CfgInt*>(b_cfgval)->getmax()
1287 ||std::dynamic_pointer_cast<CfgInt>(a_cfgval)->value()<dynamic_cast<CfgInt*>(b_cfgval)->getmin())){
1289 +std::dynamic_pointer_cast<CfgInt>(a_cfgval)->getkey()+
" Not within the bounds, setting default",
1291 #ifdef __CFG_RUNNING_DEFAULTS
1292 std::dynamic_pointer_cast<CfgInt>(a_cfgval)->set(dynamic_cast<CfgInt*>(b_cfgval)->value());
1295 dynamic_cast<CfgInt*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgInt>(a_cfgval)->value());
1304 if ((b_cfgval->
get_rangetest())&&(std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->value() >
1305 dynamic_cast<CfgFloat *>(b_cfgval)->getmax()
1306 || std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->value() <
1307 dynamic_cast<CfgFloat *>(b_cfgval)->getmin())) {
1309 + std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->getkey() +
1310 "Not within the bounds, setting default",
"NA"
1312 #ifdef __CFG_RUNNING_DEFAULTS
1313 std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->set(dynamic_cast<CfgFloat*>(b_cfgval)->value());
1316 dynamic_cast<CfgFloat *>(b_cfgval)->set(std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->value());
1325 dynamic_cast<CfgBool*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgBool>(a_cfgval)->value());
1332 dynamic_cast<CfgStr*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgStr>(a_cfgval)->value());
1339 if(std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->get_array_size()!=dynamic_cast<CfgArray_Int*>(b_cfgval)->get_array_size())
1340 if (dynamic_cast<CfgArray_Int*>(b_cfgval)->value().empty()){
1341 g_msg->
Warn(
WARN_FILE,
"Configurator::CheckBounds()\nCheck failed wrong vector size "
1342 +std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->getkey()+
": No in-code value "
1347 g_msg->
Warn(
WARN_FILE,
"Configurator::CheckBounds()\nCheck failed wrong vector size "
1348 +std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->getkey()+
": Using in-code value "
1350 #ifdef __CFG_RUNNING_DEFAULTS
1351 std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->set(dynamic_cast<CfgArray_Int*>(b_cfgval)->value());
1355 dynamic_cast<CfgArray_Int*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->value());
1363 if(std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->get_array_size()!=dynamic_cast<CfgArray_Double*>(b_cfgval)->get_array_size())
1364 if (dynamic_cast<CfgArray_Double*>(b_cfgval)->value().empty()){
1365 g_msg->
Warn(
WARN_FILE,
"Configurator::CheckBounds()\nCheck failed wrong vector size "
1366 +std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->getkey()+
": No in-code value "
1371 g_msg->
Warn(
WARN_FILE,
"Configurator::CheckBounds()\nCheck failed wrong vector size "
1372 +std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->getkey()+
": Using in-code value "
1374 #ifdef __CFG_RUNNING_DEFAULTS
1375 std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->set(dynamic_cast<CfgArray_Double*>(b_cfgval)->value());
1379 dynamic_cast<CfgArray_Double*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->value());
References CFG_ARRAY_DOUBLE, CFG_ARRAY_INT, CFG_BOOL, CFG_FLOAT, CFG_INT, CFG_STRING, g_msg, CfgBase::get_rangetest(), CfgBase::gettype(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by Register().
◆ DumpAllSymbolsAndExit()
void Configurator::DumpAllSymbolsAndExit |
( |
const char * |
a_dumpfile | ) |
|
◆ DumpPublicSymbols()
void Configurator::DumpPublicSymbols |
( |
const char * |
a_dumpfile, |
|
|
CfgSecureLevel |
a_level |
|
) |
| |
◆ DumpSymbols()
void Configurator::DumpSymbols |
( |
const char * |
a_dumpfile, |
|
|
CfgSecureLevel |
a_level |
|
) |
| |
|
protected |
1021 l_dumpfile=fopen( a_dumpfile,
"w" );
1024 "Unable to open file for writing:",
1029 typedef std::map<std::string,unsigned int>::const_iterator MI;
1031 for ( MI ii =
CfgI.begin(); ii !=
CfgI.end(); ii++ ) {
1032 unsigned int i = ii->second;
1035 if ( (
CfgVals[ i ].get())->getlevel() > a_level ) {
1041 std::string rubbish=(
CfgVals[ i ].get())->getkey();
1042 l_id=rubbish.c_str();
1044 sscanf( l_id.c_str(),
"%[A-Z]", l_nprefix );
1045 if ( strcmp( l_oprefix, l_nprefix ) != 0 ) {
1046 fprintf( l_dumpfile,
"\n" );
1047 strcpy( l_oprefix, l_nprefix );
1050 fprintf( l_dumpfile,
"%s (%s) = ",
1055 switch( (
CfgVals[ i ].get())->gettype() ) {
1059 fprintf( l_dumpfile,
"%d", l_p->
value() );
1065 fprintf( l_dumpfile,
"%f", l_p->
value() );
1071 if ( l_p->
value() ) {
1072 fprintf( l_dumpfile,
"true" );
1074 fprintf( l_dumpfile,
"false" );
1081 fprintf( l_dumpfile,
"\"%s\"", l_p->
value() );
1087 std::ostringstream oss;
1088 auto mystring= l_p->
value();
1089 if (!mystring.empty())
1092 std::copy(mystring.begin(), mystring.end()-1,
1093 std::ostream_iterator<int>(oss,
" "));
1096 oss << mystring.back();
1097 const char* stringtodump=oss.str().c_str();
1098 fprintf(l_dumpfile,
"%s", stringtodump);
1106 std::ostringstream oss;
1107 auto mystring= l_p->
value();
1108 if (!mystring.empty())
1111 std::copy(mystring.begin(), mystring.end()-1,
1112 std::ostream_iterator<double>(oss,
" "));
1115 oss << mystring.back();
1116 const char* stringtodump=oss.str().c_str();
1117 fprintf(l_dumpfile,
"%s", stringtodump);
1125 sprintf( l_errno,
"%d", (
CfgVals[ i ].get())->gettype() );
1127 "Unknown symbol type read:",
1132 fprintf( l_dumpfile,
" # %s\n",
References CFG_ARRAY_DOUBLE, CFG_ARRAY_INT, CFG_BOOL, CFG_FLOAT, CFG_INT, CFG_MAX_LINE_LENGTH, CFG_STRING, CfgI, CfgSecureStrings, CfgTypeStrings, CfgVals, g_msg, CfgInt::value(), CfgFloat::value(), CfgBool::value(), CfgStr::value(), CfgArray_Int::value(), CfgArray_Double::value(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by DumpAllSymbolsAndExit(), and DumpPublicSymbols().
◆ ExtractString()
std::string Configurator::ExtractString |
( |
std::string |
a_line | ) |
const |
|
protected |
400 std::size_t found_first_quote =a_line.find(
'"');
401 std::size_t found_last_quote =a_line.rfind(
'"');
402 if ((found_first_quote == std::string::npos)||(found_first_quote == found_last_quote)){
405 " String not enclosed in double quotes at "
406 "config line ", lineno );
411 std::regex regexp_between_quotes(R
"("[^"\\]*(\\.[^"\\]*)*")");
414 std::string therest_str{};
415 std::string extracted_str;
416 if (std::regex_search(a_line, smatch, regexp_between_quotes)) {
417 if (smatch.size() > 1) {
418 extracted_str= smatch.str(0);
419 int endofmatch = int(smatch.position(0)+smatch.length(0));
420 if (a_line.length()>endofmatch){
421 therest_str = a_line.erase(smatch.position(0), endofmatch);
428 " String not enclosed in double quotes at "
429 "config line ", lineno);
434 if ((!therest_str.empty())&&(therest_str.at(0)!=
'#')){
438 "Illegal comment at "
439 "config line ", lineno );
445 return extracted_str.substr(1, extracted_str.size() - 2);
447 catch (
const std::regex_error& e) {
449 std::cout <<
"regex_error caught: " << e.what() <<
'\n';
451 " Regex error ", lineno);
References g_msg, m_lineno, MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine(), and StoreFromConfig().
◆ ParseArrayDouble()
std::vector< double > Configurator::ParseArrayDouble |
( |
const std::string & |
a_stringtoparse | ) |
|
1404 std::stringstream iss( a_stringtoparse );
1407 std::vector<double> myNumbers;
1408 while ( iss >> number )
1409 myNumbers.push_back( number );
Referenced by StoreFromConfig().
◆ ParseArrayInt()
std::vector< int > Configurator::ParseArrayInt |
( |
const std::string & |
a_stringtoparse | ) |
|
1394 std::stringstream iss( a_stringtoparse );
1397 std::vector<int> myNumbers;
1398 while ( iss >> number )
1399 myNumbers.push_back( number );
Referenced by StoreFromConfig().
◆ ParseCfgLine()
bool Configurator::ParseCfgLine |
( |
std::string |
a_line | ) |
|
|
protected |
484 if (a_line.empty()){
return false;}
485 if (a_line.at(0) ==
'#') {
return false; }
486 if ((a_line.at(0) ==
'/') && (a_line.at(1) ==
'*'))
492 if ( std::all_of(a_line.begin(),a_line.end(),isspace)){
return false;}
493 if (a_line.back() ==
'\r'){a_line.pop_back();}
498 std::regex regexp_parsing(R
"(^([a-zA-Z_]\w*)\s*(\(.*\))\s*=\s*(.*?)\s*([\#].+\w*?)*$)");
507 std::string name_str;
508 std::string type_str;
509 std::string value_str;
510 std::string comment_str;
512 if (std::regex_search(a_line, smatch, regexp_parsing)) {
514 if (smatch.size() > 2) {
515 name_str= smatch.str(1);
516 type_str = smatch.str(2);
517 type_str = type_str.substr(1, type_str.size() - 2);
518 value_str = smatch.str(3);
519 comment_str = smatch.str(4);
525 " Unsuccessful parsing: Syntax error at",
535 if (
CfgI.find( name_str ) ==
CfgI.end() ) {
539 #ifndef _cfgWarningOff
542 " Warning: not statically initialised key ("+name_str+
") was found in CFG: line ",
550 if ( type_str.compare(
"string")== 0 ) {
572 if ( type_str.compare(
"double")== 0 ){
576 if ( type_str.compare(
"float")== 0 ){
580 if ( type_str.compare(
"bool")== 0 ){
584 if ( type_str.compare(
"int")== 0 ){
589 if ( type_str.compare(
"array int")== 0 ){
593 if ( type_str.compare(
"array double")== 0 ){
598 if ( type_str.compare(
"array double csv")== 0 ){
603 if ( type_str.compare(
"array int csv")== 0 ){
607 if ( type_str.compare(
"function")== 0 ){
613 "Unknown type specifier at config line ",
References CfgI, ExtractString(), g_msg, m_lineno, SetCfgArrayDouble(), SetCfgArrayDoubleCsv(), SetCfgArrayInt(), SetCfgArrayIntCsv(), SetCfgBool(), SetCfgFloat(), SetCfgFunction(), SetCfgInt(), SetCfgStr(), StoreFromConfig(), MapErrorMsg::Warn(), WARN_FILE, WARN_UNDEF, and MapErrorMsg::WarnAddInfo().
Referenced by ReadSymbols().
◆ ParseCommentLine()
bool Configurator::ParseCommentLine |
( |
std::string |
a_line | ) |
|
|
protected |
Reads each line and parses it.
- Parameters
-
- Returns
- true if the line starts with a long block comment '/*'
Reads each line and checks if it is the end of the comment
- Parameters
-
- Returns
- true if the line ends with a long block comment end characters ' *''/'
471 if (a_line.find(
"*/") != std::string::npos) {
Referenced by ReadSymbols().
◆ ReadSymbols()
bool Configurator::ReadSymbols |
( |
const char * |
a_cfgfile | ) |
|
366 std::ifstream cf_file;
368 std::string cfgline{};
369 cf_file.open(a_cfgfile,std::fstream::in);
370 if ( !cf_file.is_open() ) {
371 g_msg->
Warn(
WARN_FILE,
"Configurator::ReadSymbols() Unable to open file for reading: ", a_cfgfile );
374 while ( !cf_file.eof()) {
376 std::getline(cf_file,cfgline);
382 std::getline(cf_file, cfgline);
References g_msg, m_lineno, ParseCfgLine(), ParseCommentLine(), MapErrorMsg::Warn(), and WARN_FILE.
◆ Register() [1/2]
bool Configurator::Register |
( |
CfgBase * |
a_cfgval, |
|
|
const std::string & |
a_key |
|
) |
| |
◆ Register() [2/2]
bool Configurator::Register |
( |
std::shared_ptr< CfgBase > |
a_cfgval, |
|
|
const std::string & |
a_key |
|
) |
| |
An overloaded version of Register for dynamically allocated configs
345 const std::string& l_key = a_key;
347 if (
CfgI.find( l_key ) !=
CfgI.end() ) {
352 unsigned int i = (int)
CfgVals.size();
References CfgI, and CfgVals.
◆ SetCfgArrayDouble()
void Configurator::SetCfgArrayDouble |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
811 std::string l_key = a_key;
813 std::istringstream iss( a_val );
816 std::vector<double> array_double;
817 while ( iss >> number )
818 array_double.push_back( number );
821 unsigned int i =
CfgI[ l_key ];
823 "Attempting to set public config variable in line",
825 (
CfgVals[ i ].get())->getlevel()
833 "Non-double-array identifier specified at config line",
838 if (array_double.size()==dynamic_cast<CfgArray_Double*>((
CfgVals[ i ].get()))->get_array_size()) {
839 dynamic_cast<CfgArray_Double *>((
CfgVals[i].get()))->set(array_double);
844 "Wrong array length at config line",
References CFG_ARRAY_DOUBLE, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgArrayDoubleCsv()
void Configurator::SetCfgArrayDoubleCsv |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
775 std::string l_key = a_key;
777 std::istringstream iss( a_val );
780 std::vector<int> array_int;
781 while ( iss >> number )
782 array_int.push_back( number );
785 unsigned int i =
CfgI[ l_key ];
787 "Attempting to set public config variable in line",
789 (
CfgVals[ i ].get())->getlevel()
797 "Non-array-double identifier specified at config line",
803 dynamic_cast<CfgArray_Int*>((
CfgVals[ i ].get()))->set( array_int );
References CFG_ARRAY_DOUBLE, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgArrayInt()
void Configurator::SetCfgArrayInt |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
699 std::string l_key = a_key;
701 std::istringstream iss( a_val );
704 std::vector<int> array_int;
705 while ( iss >> number )
706 array_int.push_back( number );
709 unsigned int i =
CfgI[ l_key ];
711 "Attempting to set public config variable in line",
713 (
CfgVals[ i ].get())->getlevel()
721 "Non-array-integer identifier specified at config line",
726 if (array_int.size()==dynamic_cast<CfgArray_Int*>((
CfgVals[ i ].get()))->get_array_size()){
727 dynamic_cast<CfgArray_Int*>((
CfgVals[ i ].get()))->set( array_int );
731 "Wrong array length at config line",
References CFG_ARRAY_INT, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgArrayIntCsv()
void Configurator::SetCfgArrayIntCsv |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
740 std::string l_key = a_key;
742 std::istringstream iss( a_val );
745 std::vector<int> array_int;
746 while ( iss >> number )
747 array_int.push_back( number );
750 unsigned int i =
CfgI[ l_key ];
752 "Attempting to set public config variable in line",
754 (
CfgVals[ i ].get())->getlevel()
762 "Non-array-int identifier specified at config line",
768 dynamic_cast<CfgArray_Int*>((
CfgVals[ i ].get()))->set( array_int );
References CFG_ARRAY_INT, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgBool()
void Configurator::SetCfgBool |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
887 std::string l_key = a_key;
890 if ( a_val.compare(
"false" ) == 0 ) {
892 }
else if ( a_val.compare(
"true" ) == 0 ) {
897 "Not a boolean data value at config line",
903 unsigned int i =
CfgI[ l_key ];
905 "Attempting to set public config variable in line",
907 (
CfgVals[ i ].get())->getlevel()
915 "Non-boolean identifier specified at config line",
921 dynamic_cast<CfgBool*>((
CfgVals[ i ].get()))->set( l_val );
References CFG_BOOL, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgFloat()
void Configurator::SetCfgFloat |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
931 std::string l_key = a_key;
933 if ( sscanf( a_val.c_str(),
"%lf", &f) != 1 ) {
936 "Not a floating point data value at config line",
944 unsigned int i =
CfgI[ l_key ];
946 "Attempting to set public config variable in line",
948 (
CfgVals[ i ].get())->getlevel()
956 "Non-floating point identifier specified at config line",
962 dynamic_cast<CfgFloat*>((
CfgVals[ i ].get()))->set( l_val );
References CFG_FLOAT, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgFunction()
void Configurator::SetCfgFunction |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
853 std::string l_key = a_key;
855 std::istringstream iss( a_val );
858 std::vector<double> array_double;
859 while ( iss >> number )
860 array_double.push_back( number );
863 unsigned int i =
CfgI[ l_key ];
865 "Attempting to set public config variable in line",
867 (
CfgVals[ i ].get())->getlevel()
875 "Non-integer identifier specified at config line",
881 dynamic_cast<CfgArray_Double*>((
CfgVals[ i ].get()))->set( array_double );
References CFG_INT, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgGatekeeper()
bool Configurator::SetCfgGatekeeper |
( |
const std::string |
a_method, |
|
|
const std::string |
a_key, |
|
|
CfgSecureLevel |
a_level |
|
) |
| |
|
protected |
References CFG_PRIVATE, CFG_PUBLIC, g_msg, l_cfg_public_exit_on_set, l_cfg_public_warn_on_set, m_lineno, CfgBool::value(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by SetCfgArrayDouble(), SetCfgArrayDoubleCsv(), SetCfgArrayInt(), SetCfgArrayIntCsv(), SetCfgBool(), SetCfgFloat(), SetCfgFunction(), SetCfgInt(), and SetCfgStr().
◆ SetCfgInt()
void Configurator::SetCfgInt |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
663 std::string l_key = a_key;
665 if ( sscanf( a_val.c_str(),
"%d", &l_val ) != 1 ) {
668 "Not an integer data value at config line",
674 unsigned int i =
CfgI[ l_key ];
676 "Attempting to set public config variable in line",
678 (
CfgVals[ i ].get())->getlevel()
686 "Non-integer identifier specified at config line",
692 dynamic_cast<CfgInt*>(
CfgVals[ i ].get())->set( l_val );
References CFG_INT, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ SetCfgStr()
void Configurator::SetCfgStr |
( |
std::string |
a_key, |
|
|
std::string |
a_val |
|
) |
| |
970 std::string l_key = a_key;
973 unsigned int i =
CfgI[ l_key ];
975 "Attempting to set public config variable in line",
977 (
CfgVals[ i ].get())->getlevel()
985 "Non-string identifier specified at config line",
991 dynamic_cast<CfgStr*>((
CfgVals[ i ].get()))->set( a_val );
References CFG_STRING, CfgI, CfgVals, g_msg, m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ ShowIdType()
void Configurator::ShowIdType |
( |
unsigned int |
a_i | ) |
|
|
protected |
623 "Type for identifier ",
624 (
CfgVals[ a_i ].get())->getkey().c_str() );
References CfgTypeStrings, CfgVals, g_msg, WARN_FILE, and MapErrorMsg::WarnAddInfo().
Referenced by SetCfgArrayDouble(), SetCfgArrayDoubleCsv(), SetCfgArrayInt(), SetCfgArrayIntCsv(), SetCfgBool(), SetCfgFloat(), SetCfgFunction(), SetCfgInt(), and SetCfgStr().
◆ StoreFromConfig()
void Configurator::StoreFromConfig |
( |
const std::string & |
name, |
|
|
std::string |
type, |
|
|
std::string |
value |
|
) |
| |
1145 if (type.compare(
"int") == 0){
1147 if ( sscanf( value.c_str(),
"%d", &l_val ) != 1 ) {
1150 "Not an integer data value at config line",
1156 auto new_object (std::make_shared<CfgInt>(
CfgInt ( name,
CFG_CUSTOM,l_val,
true)));
1158 this->
Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1161 }
else if (type.compare(
"bool") == 0){
1163 if ( value.compare(
"false" ) == 0 ) {
1165 }
else if ( value.compare(
"true" ) == 0 ) {
1170 "Not a boolean data value at config line",
1176 auto new_object (std::make_shared<CfgBool>(
CfgBool ( name,
CFG_CUSTOM,l_val,
true)));
1179 this->
Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1182 }
else if ((type.compare(
"double") == 0)||(type.compare(
"float") == 0)){
1184 if ( sscanf( value.c_str(),
"%lf", &l_val ) != 1 ) {
1187 "Not an double data value at config line",
1193 auto new_object (std::make_shared<CfgFloat>(
CfgFloat ( name,
CFG_CUSTOM,l_val,
true)));
1196 this->
Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1200 else if (type.compare(
"string") == 0) {
1206 this->
Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1209 else if (type.compare(
"array int") == 0) {
1211 std::regex int_regex(
"(\s*(-*[0-9]+\s+)+\s*)");
1215 std::string therest_str{};
1216 std::string extracted_str;
1217 if (std::regex_search(value, smatch, int_regex)) {
1218 if (smatch.size() < 1) {
1221 + name +
" Unsuccessful parsing: Syntax error at",
1226 catch (
const std::regex_error& e) {
1228 std::cout <<
"regex_error caught: " << e.what() <<
'\n';
1230 " Regex error ", lineno);
1233 int a_numvals = int(array_vec.size());
1236 auto new_object (std::make_shared<CfgArray_Int>(
CfgArray_Int (name,
CFG_CUSTOM, a_numvals, array_vec,
true)));
1238 this->
Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1241 else if (type.compare(
"array double") == 0) {
1243 std::regex int_regex(
"(\s*(-*[0-9.]+\s+)+\s*)");
1247 std::string therest_str{};
1248 std::string extracted_str;
1249 if (std::regex_search(value, smatch, int_regex)) {
1250 if (smatch.size() < 1) {
1253 + name +
" Unsuccessful parsing: Syntax error at",
1258 catch (
const std::regex_error& e) {
1260 std::cout <<
"regex_error caught: " << e.what() <<
'\n';
1262 " Regex error ", lineno);
1265 int a_numvals = int(array_vec.size());
1270 this->
Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
References CFG_CUSTOM, ExtractString(), g_msg, m_lineno, ParseArrayDouble(), ParseArrayInt(), Register(), MapErrorMsg::Warn(), and WARN_FILE.
Referenced by ParseCfgLine().
◆ CfgI
std::map<std::string, unsigned int> Configurator::CfgI |
|
protected |
Referenced by DumpSymbols(), ParseCfgLine(), Register(), SetCfgArrayDouble(), SetCfgArrayDoubleCsv(), SetCfgArrayInt(), SetCfgArrayIntCsv(), SetCfgBool(), SetCfgFloat(), SetCfgFunction(), SetCfgInt(), and SetCfgStr().
◆ CfgVals
std::vector<std::shared_ptr<CfgBase> > Configurator::CfgVals |
|
protected |
Referenced by DumpSymbols(), Register(), SetCfgArrayDouble(), SetCfgArrayDoubleCsv(), SetCfgArrayInt(), SetCfgArrayIntCsv(), SetCfgBool(), SetCfgFloat(), SetCfgFunction(), SetCfgInt(), SetCfgStr(), and ShowIdType().
◆ m_lineno
unsigned int Configurator::m_lineno |
|
protected |
Referenced by Configurator(), ExtractString(), ParseCfgLine(), ReadSymbols(), Register(), SetCfgArrayDouble(), SetCfgArrayDoubleCsv(), SetCfgArrayInt(), SetCfgArrayIntCsv(), SetCfgBool(), SetCfgFloat(), SetCfgFunction(), SetCfgGatekeeper(), SetCfgInt(), SetCfgStr(), and StoreFromConfig().
The documentation for this class was generated from the following files:
Definition: Configurator.h:64
void SetCfgArrayDouble(std::string a_key, std::string a_val)
Definition: Configurator.cpp:807
void SetCfgBool(std::string a_key, std::string a_val)
Definition: Configurator.cpp:884
static const std::string CfgTypeStrings[]
Definition: Configurator.cpp:71
Definition: MapErrorMsg.h:37
Definition: Configurator.h:60
Definition: Configurator.h:65
#define CFG_MAX_LINE_LENGTH
Definition: Configurator.h:52
char * value() const
Definition: Configurator.h:182
void WarnAddInfo(MapErrorState a_level, std::string a_add1, std::string a_add2)
Definition: MapErrorMsg.cpp:160
Definition: Configurator.h:71
String configurator entry class.
Definition: Configurator.h:173
void SetCfgStr(std::string a_key, std::string a_val)
Definition: Configurator.cpp:967
void SetCfgFunction(std::string a_key, std::string a_val)
Definition: Configurator.cpp:849
double value() const
Definition: Configurator.h:142
bool get_rangetest() const
Definition: Configurator.h:96
Definition: Configurator.h:63
Definition: Configurator.h:62
void SetCfgInt(std::string a_key, std::string a_val)
Definition: Configurator.cpp:659
std::string ExtractString(std::string a_line) const
Definition: Configurator.cpp:395
static CfgBool l_cfg_public_warn_on_set("CFG_PUBLIC_WARN_ON_SET", CFG_CUSTOM, true)
bool value() const
Definition: Configurator.h:164
void ShowIdType(unsigned int a_i)
Definition: Configurator.cpp:620
bool ParseCfgLine(std::string a_line)
Definition: Configurator.cpp:476
bool SetCfgGatekeeper(const std::string a_method, const std::string a_key, CfgSecureLevel a_level)
Definition: Configurator.cpp:632
std::vector< std::shared_ptr< CfgBase > > CfgVals
Definition: Configurator.h:255
std::map< std::string, unsigned int > CfgI
Definition: Configurator.h:254
void SetCfgArrayDoubleCsv(std::string a_key, std::string a_val)
Definition: Configurator.cpp:771
Bool configurator entry class.
Definition: Configurator.h:155
Definition: MapErrorMsg.h:36
virtual CfgType gettype()
Definition: Configurator.h:92
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Definition: Configurator.h:208
Definition: Configurator.h:61
bool Register(CfgBase *a_cfgval, const std::string &a_key)
Definition: Configurator.cpp:299
int value() const
Definition: Configurator.h:116
std::vector< double > value() const
Definition: Configurator.h:219
bool CheckBounds(std::shared_ptr< CfgBase > a_cfgval, CfgBase *b_cfgval)
Definition: Configurator.cpp:1274
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
Integer configurator entry class.
Definition: Configurator.h:102
static CfgBool l_cfg_public_exit_on_set("CFG_PUBLIC_EXIT_ON_SET", CFG_CUSTOM, true)
Double configurator entry class.
Definition: Configurator.h:126
std::vector< int > value() const
Definition: Configurator.h:201
void DumpSymbols(const char *a_dumpfile, CfgSecureLevel a_level)
Definition: Configurator.cpp:1014
void SetCfgFloat(std::string a_key, std::string a_val)
Definition: Configurator.cpp:926
Definition: Configurator.h:70
void SetCfgArrayIntCsv(std::string a_key, std::string a_val)
Definition: Configurator.cpp:736
std::vector< double > ParseArrayDouble(const std::string &a_stringtoparse)
Definition: Configurator.cpp:1402
void StoreFromConfig(const std::string &name, std::string type, std::string value)
Definition: Configurator.cpp:1143
static const std::string CfgSecureStrings[]
Definition: Configurator.cpp:64
bool ParseCommentLine(std::string a_line)
Reads each line and parses it.
Definition: Configurator.cpp:464
unsigned int m_lineno
Definition: Configurator.h:258
Array_Int configurator entry class.
Definition: Configurator.h:189
void set_definedinconfig(bool flag)
Definition: Configurator.h:94
Definition: Configurator.h:72
std::vector< int > ParseArrayInt(const std::string &a_stringtoparse)
Definition: Configurator.cpp:1392
void SetCfgArrayInt(std::string a_key, std::string a_val)
Definition: Configurator.cpp:695