Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Configurator Class Reference

A class to provide standard parameter entry facilities. More...

#include <Configurator.h>

Public Member Functions

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)
 

Protected Member Functions

bool ParseCfgLine (std::string a_line)
 
bool SetCfgGatekeeper (const std::string a_method, const std::string a_key, CfgSecureLevel a_level)
 
void ShowIdType (unsigned int a_i)
 
std::string ExtractString (std::string a_line) const
 
bool ParseCommentLine (std::string a_line)
 Reads each line and parses it. More...
 
void DumpSymbols (const char *a_dumpfile, CfgSecureLevel a_level)
 

Protected Attributes

std::map< std::string, unsigned int > CfgI
 
std::vector< std::shared_ptr< CfgBase > > CfgVals
 
unsigned int m_lineno
 

Detailed Description

A class to provide standard parameter entry facilities.

Constructor & Destructor Documentation

◆ Configurator()

Configurator::Configurator ( void  )
287 {
288  m_lineno = 0;
289 }

References m_lineno.

◆ ~Configurator()

Configurator::~Configurator ( void  )
294 {
295  ;
296 }

Member Function Documentation

◆ 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

1274  {
1278  if (b_cfgval->gettype()!=a_cfgval->gettype()){
1279  g_msg->Warn( WARN_FILE, "Configurator::CheckBounds() "
1280  "Mismatched config variable types",
1281  "NA" );
1282  return false;
1283  }
1284  switch (b_cfgval->gettype()) {
1285  case CFG_INT:{
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())){
1288  g_msg->Warn( WARN_FILE, "Configurator::CheckBounds()\n Check failed "
1289  +std::dynamic_pointer_cast<CfgInt>(a_cfgval)->getkey()+" Not within the bounds, setting default",
1290  "NA" );
1291 #ifdef __CFG_RUNNING_DEFAULTS
1292  std::dynamic_pointer_cast<CfgInt>(a_cfgval)->set(dynamic_cast<CfgInt*>(b_cfgval)->value());
1293 #endif
1294  }else{
1295  dynamic_cast<CfgInt*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgInt>(a_cfgval)->value());
1296  // g_msg->Warn( WARN_FILE, "Configurator::CheckBounds()\nCheck passed "
1297  // +std::dynamic_pointer_cast<CfgInt>(a_cfgval)->getkey()+": Using config file value "
1298  // " Line: ", "NA");
1299  }
1300 
1301  };
1302  break;
1303  case CFG_FLOAT: {
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())) {
1308  g_msg->Warn(WARN_FILE, "Configurator::CheckBounds()\n Check failed"
1309  + std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->getkey() +
1310  "Not within the bounds, setting default", "NA"
1311  );
1312 #ifdef __CFG_RUNNING_DEFAULTS
1313  std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->set(dynamic_cast<CfgFloat*>(b_cfgval)->value());
1314 #endif
1315  } else {
1316  dynamic_cast<CfgFloat *>(b_cfgval)->set(std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->value());
1317  // g_msg->Warn(WARN_FILE, "Configurator::CheckBounds()\nCheck passed "
1318  // + std::dynamic_pointer_cast<CfgFloat>(a_cfgval)->getkey() +
1319  // ": Using config file value "
1320  // "Line: ", "NA");
1321  }
1322  }
1323  break;
1324  case CFG_BOOL:{
1325  dynamic_cast<CfgBool*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgBool>(a_cfgval)->value());
1326  // g_msg->Warn( WARN_FILE, "Configurator::CheckBounds()\nCheck passed "
1327  // +std::dynamic_pointer_cast<CfgBool>(a_cfgval)->getkey()+": Using config file value "
1328  // "Line: ", "NA");
1329  }
1330  break;
1331  case CFG_STRING:{
1332  dynamic_cast<CfgStr*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgStr>(a_cfgval)->value());
1333  // g_msg->Warn( WARN_FILE, "Configurator::CheckBounds()\nCheck passed "
1334  // +std::dynamic_pointer_cast<CfgStr>(a_cfgval)->getkey()+": Using config file value "
1335  // "Line: ", "NA");
1336  }
1337  break;
1338  case CFG_ARRAY_INT:{
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 "
1343  "Line: ", "NA");
1344  return false;
1345  }
1346  else{
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 "
1349  "Line: ", "NA");
1350 #ifdef __CFG_RUNNING_DEFAULTS
1351  std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->set(dynamic_cast<CfgArray_Int*>(b_cfgval)->value());
1352 #endif
1353  }
1354  else{
1355  dynamic_cast<CfgArray_Int*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->value());
1356  // g_msg->Warn( WARN_FILE, "Configurator::CheckBounds()\nCheck passed "
1357  // +std::dynamic_pointer_cast<CfgArray_Int>(a_cfgval)->getkey()+": Using config file value "
1358  // "Line: ", "NA");
1359  }
1360  }
1361  break;
1362  case CFG_ARRAY_DOUBLE:{
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 "
1367  "Line: ", "NA");
1368  return false;
1369  }
1370  else{
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 "
1373  "Line: ", "NA");
1374 #ifdef __CFG_RUNNING_DEFAULTS
1375  std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->set(dynamic_cast<CfgArray_Double*>(b_cfgval)->value());
1376 #endif
1377  }
1378  else{
1379  dynamic_cast<CfgArray_Double*>(b_cfgval)->set(std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->value());
1380  // g_msg->Warn( WARN_FILE, "Configurator::CheckBounds()\nCheck passed "
1381  // +std::dynamic_pointer_cast<CfgArray_Double>(a_cfgval)->getkey()+": Using config file value "
1382  // "Line: ", "NA");
1383  }
1384  }
1385  break;
1386 
1387 }
1388 return true;
1389 }

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)
1008 {
1009  DumpSymbols( a_dumpfile, CFG_PRIVATE );
1010  exit(1);
1011 }

References CFG_PRIVATE, and DumpSymbols().

◆ DumpPublicSymbols()

void Configurator::DumpPublicSymbols ( const char *  a_dumpfile,
CfgSecureLevel  a_level 
)
998 {
999  if ( a_level > CFG_PUBLIC ) {
1000  a_level = CFG_PUBLIC;
1001  }
1002  DumpSymbols( a_dumpfile, a_level );
1003 }

References CFG_PUBLIC, and DumpSymbols().

◆ DumpSymbols()

void Configurator::DumpSymbols ( const char *  a_dumpfile,
CfgSecureLevel  a_level 
)
protected
1016 {
1017  FILE *l_dumpfile;
1018  char l_oprefix[ CFG_MAX_LINE_LENGTH ] = {""};
1019  char l_nprefix[ CFG_MAX_LINE_LENGTH ];
1020  std::string l_id;
1021  l_dumpfile=fopen( a_dumpfile, "w" );
1022  if (!l_dumpfile) {
1023  g_msg->Warn( WARN_FILE, "Configurator::DumpSymbols() "
1024  "Unable to open file for writing:",
1025  a_dumpfile );
1026  exit(1);
1027  }
1028 
1029  typedef std::map<std::string,unsigned int>::const_iterator MI;
1030 
1031  for ( MI ii = CfgI.begin(); ii != CfgI.end(); ii++ ) {
1032  unsigned int i = ii->second;
1033 
1034  // Skip 'secret' variables.
1035  if ( (CfgVals[ i ].get())->getlevel() > a_level ) {
1036  continue;
1037  }
1038 
1039  // Weird hack to separate different groups of
1040  // configuration names.
1041  std::string rubbish=(CfgVals[ i ].get())->getkey();
1042  l_id=rubbish.c_str();
1043  //l_id = (CfgVals[ i ].get())->getkey().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 );
1048  }
1049 
1050  fprintf( l_dumpfile, "%s (%s) = ",
1051  l_id.c_str(),
1052  CfgTypeStrings[ (CfgVals[ i ].get())->gettype() ].c_str()
1053  );
1054 
1055  switch( (CfgVals[ i ].get())->gettype() ) {
1056  case CFG_INT:
1057  {
1058  CfgInt* l_p = dynamic_cast<CfgInt*>((CfgVals[ i ].get()));
1059  fprintf( l_dumpfile, "%d", l_p->value() );
1060  break;
1061  }
1062  case CFG_FLOAT:
1063  {
1064  CfgFloat* l_p = dynamic_cast<CfgFloat*>((CfgVals[ i ].get()));
1065  fprintf( l_dumpfile, "%f", l_p->value() );
1066  break;
1067  }
1068  case CFG_BOOL:
1069  {
1070  CfgBool* l_p = dynamic_cast<CfgBool*>((CfgVals[ i ].get()));
1071  if ( l_p->value() ) {
1072  fprintf( l_dumpfile, "true" );
1073  } else {
1074  fprintf( l_dumpfile, "false" );
1075  }
1076  break;
1077  }
1078  case CFG_STRING:
1079  {
1080  CfgStr* l_p = dynamic_cast<CfgStr*>((CfgVals[ i ].get()));
1081  fprintf( l_dumpfile, "\"%s\"", l_p->value() );
1082  break;
1083  }
1084  case CFG_ARRAY_INT:
1085  {
1086  CfgArray_Int *l_p = dynamic_cast<CfgArray_Int *>((CfgVals[i].get()));
1087  std::ostringstream oss;
1088  auto mystring= l_p->value();
1089  if (!mystring.empty())
1090  {
1091  // Convert all but the last element to avoid a trailing " "
1092  std::copy(mystring.begin(), mystring.end()-1,
1093  std::ostream_iterator<int>(oss, " "));
1094 
1095  // Now add the last element with no delimiter
1096  oss << mystring.back();
1097  const char* stringtodump=oss.str().c_str();
1098  fprintf(l_dumpfile, "%s", stringtodump);
1099  }
1100 
1101  break;
1102  }
1103  case CFG_ARRAY_DOUBLE:
1104  {
1105  CfgArray_Double *l_p = dynamic_cast<CfgArray_Double *>((CfgVals[i].get()));
1106  std::ostringstream oss;
1107  auto mystring= l_p->value();
1108  if (!mystring.empty())
1109  {
1110  // Convert all but the last element to avoid a trailing " "
1111  std::copy(mystring.begin(), mystring.end()-1,
1112  std::ostream_iterator<double>(oss, " "));
1113 
1114  // Now add the last element with no delimiter
1115  oss << mystring.back();
1116  const char* stringtodump=oss.str().c_str();
1117  fprintf(l_dumpfile, "%s", stringtodump);
1118  }
1119 
1120  break;
1121  }
1122  default:
1123  {
1124  char l_errno[20];
1125  sprintf( l_errno, "%d", (CfgVals[ i ].get())->gettype() );
1126  g_msg->Warn( WARN_FILE, "Configurator::DumpSymbols() "
1127  "Unknown symbol type read:",
1128  l_errno );
1129  exit(1);
1130  }
1131  }
1132  fprintf( l_dumpfile, " # %s\n",
1133  CfgSecureStrings[ (CfgVals[ i ].get())->getlevel() ].c_str()
1134  );
1135  }
1136 
1137 }

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
396 {
397  char lineno[ 20 ];
398 
399  // scan for the first double quote or end of line.
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)){
403  sprintf( lineno, "%d", m_lineno );
404  g_msg->Warn( WARN_FILE, "Configurator::ExtractString()\n"
405  " String not enclosed in double quotes at "
406  "config line ", lineno );
407  exit(1);
408  }
409  // we can get over all this by just using regex
410  try{
411  std::regex regexp_between_quotes(R"("[^"\\]*(\\.[^"\\]*)*")");
412 
413  std::smatch smatch;
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); // return the first matching string
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);
422  }
423 
424  }
425  else {
426  sprintf(lineno, "%d", m_lineno);
427  g_msg->Warn(WARN_FILE, "Configurator::ExtractString()\n"
428  " String not enclosed in double quotes at "
429  "config line ", lineno);
430  exit(1);
431  }
432 
433  }
434  if ((!therest_str.empty())&&(therest_str.at(0)!='#')){
435  sprintf( lineno, "%d", m_lineno );
436 
437  g_msg->Warn( WARN_FILE, "Configurator::ExtractString() "
438  "Illegal comment at "
439  "config line ", lineno );
440  exit(1);
441  }
442  /*
443  * We will strip the quotes (first and last symbol and return it)
444  * */
445  return extracted_str.substr(1, extracted_str.size() - 2);
446  }
447  catch (const std::regex_error& e) {
448  sprintf(lineno, "%d", m_lineno);
449  std::cout << "regex_error caught: " << e.what() << '\n';
450  g_msg->Warn(WARN_FILE, "Configurator::ExtractString()\n"
451  " Regex error ", lineno);
452  }
453 
454  return ""; // Compiler happiness
455 
456 
457 }

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)
1402  {
1403 
1404  std::stringstream iss( a_stringtoparse );
1405 
1406  double number;
1407  std::vector<double> myNumbers;
1408  while ( iss >> number )
1409  myNumbers.push_back( number );
1410  return myNumbers;
1411 }

Referenced by StoreFromConfig().

◆ ParseArrayInt()

std::vector< int > Configurator::ParseArrayInt ( const std::string &  a_stringtoparse)
1392  {
1393 
1394  std::stringstream iss( a_stringtoparse );
1395 
1396  int number;
1397  std::vector<int> myNumbers;
1398  while ( iss >> number )
1399  myNumbers.push_back( number );
1400  return myNumbers;
1401 }

Referenced by StoreFromConfig().

◆ ParseCfgLine()

bool Configurator::ParseCfgLine ( std::string  a_line)
protected
477 {
478  std::string l_id ;
479  std::string l_type;
480  std::string l_sep ;
481  std::string l_val ;
482  std::string l_comm;
483  char lineno[ 20 ];
484  if (a_line.empty()){return false;}// Empty string
485  if (a_line.at(0) == '#') { return false; }// Comment line: starts from #
486  if ((a_line.at(0) == '/') && (a_line.at(1) == '*'))
487  {
488  return true;
489  }// Comment block: starts from /*
490 
491  //if (a_line.find_first_not_of(" \t\n\v\f\r") != std::string::npos){return;}// Empty line
492  if ( std::all_of(a_line.begin(),a_line.end(),isspace)){return false;}// Empty line
493  if (a_line.back() == '\r'){a_line.pop_back();} //If there is /r in the end (reading Win file in Unix)
494  // consisting only of white spaces or tabs.
495 
496 
497  //int l_conv = sscanf( a_line, "%[A-Z_] (%[a-z]) %s", l_id, sizeof(l_id),l_type,sizeof(l_type), l_sep,sizeof(l_sep) );
498  std::regex regexp_parsing(R"(^([a-zA-Z_]\w*)\s*(\(.*\))\s*=\s*(.*?)\s*([\#].+\w*?)*$)");
499  // This may look complicated for the person who never saw regex but we basically extract 4 groups:
500  // (1) alphanumeric variable name
501  // (2) in brackets (type)
502  // =
503  // (3) value can be values or numbers or whatever, (since we allow strings)
504  // (4: optional) "#comment" (always after #)
505 
506  std::smatch smatch;
507  std::string name_str;
508  std::string type_str;
509  std::string value_str;
510  std::string comment_str;
511  sprintf( lineno, "%d", m_lineno );
512  if (std::regex_search(a_line, smatch, regexp_parsing)) {
513 
514  if (smatch.size() > 2) { // comment is optional so there are 3 or 4 groups: zeros element is all matches
515  name_str= smatch.str(1);
516  type_str = smatch.str(2);
517  type_str = type_str.substr(1, type_str.size() - 2); // will remove brackets from around type
518  value_str = smatch.str(3);
519  comment_str = smatch.str(4);
520 
521  }
522  else{
523  sprintf( lineno, "%d", m_lineno );
524  g_msg->Warn( WARN_FILE, "Configurator::ParseCfgLine() "
525  " Unsuccessful parsing: Syntax error at",
526  lineno );
527  }
528  }
529 //int l_conv = sscanf( a_line, "%[A-Z_] (%[a-z]) %s", l_id, l_type, l_sep );
530 
531 
532 
533 
534 
535  if ( CfgI.find( name_str ) == CfgI.end() ) {
536  // Key doesn't exists among the preloaded global configuration
537  // variables. Previously we ignored this quietly. Now we will store it nonetheless
538  // in the datastructures
539 #ifndef _cfgWarningOff
540 
541  g_msg->WarnAddInfo( WARN_UNDEF, "Configurator::ParseCfgLine() "
542  " Warning: not statically initialised key ("+name_str+") was found in CFG: line ",
543  lineno );
544 #endif
545  this->StoreFromConfig(name_str, type_str, value_str);
546 
547  return false;
548  }
549 
550  if ( type_str.compare("string")== 0 ) {
551  // We are not yet ready to do the assignment.
552  // If we really have a string enclosed in non-escaped
553  // double quotes at the end of the line, then we need to
554  // extract it first from our input.
555  SetCfgStr( name_str, ExtractString( value_str+comment_str )); // we send just the 3rd and 4th groups,
556  // but this also will do
557  return false;
558  }
559 
560  // Not a string, so extract data value and possible comment.
561 // l_conv = sscanf( a_line, "%*[A-Z_] (%*[a-z]) %*s %s %s",
562 // l_val, l_comm );
563 //
564 // if ( l_conv == 2 && l_comm[0] != '#' ) {
565 // // Illegal comment at end of line.
566 // sprintf( lineno, "%d", m_lineno );
567 // g_msg->Warn( WARN_FILE, "Configurator::ParseCfgLine() "
568 // "Syntax error at end of config line ",
569 // lineno );
570 // exit(1);
571 //}
572  if ( type_str.compare("double")== 0 ){
573  SetCfgFloat( name_str, value_str );
574  return false;
575  }
576  if ( type_str.compare("float")== 0 ){
577  SetCfgFloat( name_str, value_str );
578  return false;
579  }
580  if ( type_str.compare("bool")== 0 ){
581  SetCfgBool( name_str, value_str );
582  return false;
583  }
584  if ( type_str.compare("int")== 0 ){
585  SetCfgInt( name_str, value_str );
586  return false;
587  }
588 
589  if ( type_str.compare("array int")== 0 ){
590  SetCfgArrayInt( name_str, value_str );
591  return false;
592  }
593  if ( type_str.compare("array double")== 0 ){
594  SetCfgArrayDouble( name_str, value_str );
595  return false;
596  }
597 
598  if ( type_str.compare("array double csv")== 0 ){
599  SetCfgArrayDoubleCsv( name_str, value_str );
600  return false;
601  }
602 
603  if ( type_str.compare("array int csv")== 0 ){
604  SetCfgArrayIntCsv( name_str, value_str );
605  return false;
606  }
607  if ( type_str.compare("function")== 0 ){
608  SetCfgFunction( name_str, value_str );
609  return false;
610  }
611  sprintf( lineno, "%d", m_lineno );
612  g_msg->Warn( WARN_FILE, "Configurator::ParseCfgLine() "
613  "Unknown type specifier at config line ",
614  lineno );
615  exit(1);
616 }

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
a_lineis the line read
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
a_lineis the line read
Returns
true if the line ends with a long block comment end characters ' *''/'
470 {
471  if (a_line.find("*/") != std::string::npos) {
472  return true;
473  } // NB even if this string is in the middle of a line the rest is ignored, best to use a line only for this
474  return false;
475 }

Referenced by ReadSymbols().

◆ ReadSymbols()

bool Configurator::ReadSymbols ( const char *  a_cfgfile)
365  {
366  std::ifstream cf_file;
367  //char cfgline[ CFG_MAX_LINE_LENGTH ]; //maybe we'll change it to std::string later
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 );
372  exit(1);
373  }
374  while ( !cf_file.eof()) {
375  // for (unsigned i=0; i< CFG_MAX_LINE_LENGTH; i++) cfgline[i]=' '; // Done to get rid of the rubbish that otherwise messes up the parse
376  std::getline(cf_file,cfgline);
377  if (ParseCfgLine( cfgline ))
378  {
379  do
380  {
381  m_lineno++;
382  std::getline(cf_file, cfgline);
383  } while (!ParseCommentLine(cfgline));
384  }
385  m_lineno++;
386  }
387  cf_file.close();
388  return true;
389 }

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 
)
300 {
301  const std::string& l_key = a_key;
302  char lineno[ 20 ];
303 
304  if ( CfgI.find( l_key ) != CfgI.end() ) {
305  // Couldn't register, already exists.
306  // will check if it was defined in cfg file
307  // if so envoke checking the value method
308  // and after correction return true
309 
310  if (CfgVals[CfgI.find(l_key)->second]->get_definedinconfig()) {
311  sprintf(lineno, "%d", m_lineno);
312  /*
313  g_msg->Warn( WARN_FILE, "Configurator::Register()\n"
314  +a_key+": Registering non-static variable which value was first defined in "
315  "config file. Line: ", "NA");
316  */
317  a_cfgval->set_definedinconfig(true);
318  return CheckBounds(CfgVals[CfgI.find(l_key)->second], a_cfgval);
319 
320 
321  }else{
322  // otherwise
323  return false;
324  }
325 
326 
327  }
328 
329  unsigned int i = (int) CfgVals.size();
330  CfgI[ l_key ] = i;
331  CfgVals.resize( i+1 );
332  // we will define an empty destructor for statically initiated shared pointer
333 
334  CfgVals[ i ] = std::shared_ptr<CfgBase>{std::shared_ptr<CfgBase*>{},a_cfgval};
335 
336 
337 
338  return true;
339 }

References CfgI, CfgVals, CheckBounds(), m_lineno, and CfgBase::set_definedinconfig().

Referenced by StoreFromConfig().

◆ 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

341 {
345  const std::string& l_key = a_key;
346 
347  if ( CfgI.find( l_key ) != CfgI.end() ) {
348  // Couldn't register, already exists.
349  return false;
350  }
351 
352  unsigned int i = (int) CfgVals.size();
353  CfgI[ l_key ] = i;
354  CfgVals.resize( i+1 );
355  // we will define an empty destructor for statically initiated shared pointer
356 
357  CfgVals[i ] = a_cfgval;
358 
359 
360 
361  return true;
362 }

References CfgI, and CfgVals.

◆ SetCfgArrayDouble()

void Configurator::SetCfgArrayDouble ( std::string  a_key,
std::string  a_val 
)
808 {
809  //int l_val;
810  char lineno[20];
811  std::string l_key = a_key;
812 
813  std::istringstream iss( a_val );
814 
815  double number;
816  std::vector<double> array_double;
817  while ( iss >> number )
818  array_double.push_back( number );
819  // for now we will leave the gatekeeper
820  // Check access security.
821  unsigned int i = CfgI[ l_key ];
822  if ( SetCfgGatekeeper( "Configurator::SetCfgInt() "
823  "Attempting to set public config variable in line",
824  a_key,
825  (CfgVals[ i ].get())->getlevel()
826  )) {
827  return;
828  }
829 
830  if ( (CfgVals[ i ].get())->gettype() != CFG_ARRAY_DOUBLE ) {
831  sprintf( lineno, "%d", m_lineno );
832  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
833  "Non-double-array identifier specified at config line",
834  lineno );
835  ShowIdType( i );
836  exit(1);
837  }
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);
840  }
841  else{
842  sprintf( lineno, "%d", m_lineno );
843  g_msg->Warn( WARN_FILE, "Configurator::SetCfgArrayDouble() "
844  "Wrong array length at config line",
845  lineno );
846  }
847 }

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 
)
772 {
773  //int l_val;
774  char lineno[20];
775  std::string l_key = a_key;
776 
777  std::istringstream iss( a_val );
778 
779  int number;
780  std::vector<int> array_int;
781  while ( iss >> number )
782  array_int.push_back( number );
783  // for now we will leave the gatekeeper
784  // Check access security.
785  unsigned int i = CfgI[ l_key ];
786  if ( SetCfgGatekeeper( "Configurator::SetCfgInt() "
787  "Attempting to set public config variable in line",
788  a_key,
789  (CfgVals[ i ].get())->getlevel()
790  )) {
791  return;
792  }
793 
794  if ( (CfgVals[ i ].get())->gettype() != CFG_ARRAY_DOUBLE ) {
795  sprintf( lineno, "%d", m_lineno );
796  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
797  "Non-array-double identifier specified at config line",
798  lineno );
799  ShowIdType( i );
800  exit(1);
801  }
802 
803  dynamic_cast<CfgArray_Int*>((CfgVals[ i ].get()))->set( array_int );
804 }

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 
)
696 {
697  //int l_val;
698  char lineno[20];
699  std::string l_key = a_key;
700 
701  std::istringstream iss( a_val );
702 
703  int number;
704  std::vector<int> array_int;
705  while ( iss >> number )
706  array_int.push_back( number );
707  // for now we will leave the gatekeeper
708  // Check access security.
709  unsigned int i = CfgI[ l_key ];
710  if ( SetCfgGatekeeper( "Configurator::SetCfgInt() "
711  "Attempting to set public config variable in line",
712  a_key,
713  (CfgVals[ i ].get())->getlevel()
714  )) {
715  return;
716  }
717 
718  if ( (CfgVals[ i ].get())->gettype() != CFG_ARRAY_INT ) {
719  sprintf( lineno, "%d", m_lineno );
720  g_msg->Warn( WARN_FILE, "Configurator::SetCfgArrayInt() "
721  "Non-array-integer identifier specified at config line",
722  lineno );
723  ShowIdType( i );
724  exit(1);
725  }
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 );
728  }else{
729  sprintf( lineno, "%d", m_lineno );
730  g_msg->Warn( WARN_FILE, "Configurator::SetCfgArrayInt() "
731  "Wrong array length at config line",
732  lineno );
733  }
734 
735 }

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 
)
737 {
738  //int l_val;
739  char lineno[20];
740  std::string l_key = a_key;
741 
742  std::istringstream iss( a_val );
743 
744  int number;
745  std::vector<int> array_int;
746  while ( iss >> number )
747  array_int.push_back( number );
748  // for now we will leave the gatekeeper
749  // Check access security.
750  unsigned int i = CfgI[ l_key ];
751  if ( SetCfgGatekeeper( "Configurator::SetCfgInt() "
752  "Attempting to set public config variable in line",
753  a_key,
754  (CfgVals[ i ].get())->getlevel()
755  )) {
756  return;
757  }
758 
759  if ( (CfgVals[ i ].get())->gettype() != CFG_ARRAY_INT ) {
760  sprintf( lineno, "%d", m_lineno );
761  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
762  "Non-array-int identifier specified at config line",
763  lineno );
764  ShowIdType( i );
765  exit(1);
766  }
767 
768  dynamic_cast<CfgArray_Int*>((CfgVals[ i ].get()))->set( array_int );
769 }

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 
)
885 {
886  char lineno[20];
887  std::string l_key = a_key;
888  bool l_val = false;
889 
890  if ( a_val.compare( "false" ) == 0 ) {
891  ; // l_val defaults to false.
892  } else if ( a_val.compare( "true" ) == 0 ) {
893  l_val = true;
894  } else {
895  sprintf( lineno, "%d", m_lineno );
896  g_msg->Warn( WARN_FILE, "Configurator::SetCfgBool() "
897  "Not a boolean data value at config line",
898  lineno );
899  exit(1);
900  }
901 
902  // Check access security.
903  unsigned int i = CfgI[ l_key ];
904  if ( SetCfgGatekeeper( "Configurator::SetCfgBool() "
905  "Attempting to set public config variable in line",
906  a_key,
907  (CfgVals[ i ].get())->getlevel()
908  )) {
909  return;
910  }
911 
912  if ( (CfgVals[ i ].get())->gettype() != CFG_BOOL ) {
913  sprintf( lineno, "%d", m_lineno );
914  g_msg->Warn( WARN_FILE, "Configurator::SetCfgBool() "
915  "Non-boolean identifier specified at config line",
916  lineno );
917  ShowIdType( i );
918  exit(1);
919  }
920 
921  dynamic_cast<CfgBool*>((CfgVals[ i ].get()))->set( l_val );
922 }

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 
)
927 {
928  double l_val;
929  double f;
930  char lineno[20];
931  std::string l_key = a_key;
932 
933  if ( sscanf( a_val.c_str(), "%lf", &f) != 1 ) {
934  sprintf( lineno, "%d", m_lineno );
935  g_msg->Warn( WARN_FILE, "Configurator::SetCfgFloat() "
936  "Not a floating point data value at config line",
937  lineno );
938  exit(1);
939  }
940  //FloatToDouble(l_val,f);
941  l_val = f;
942 
943  // Check access security.
944  unsigned int i = CfgI[ l_key ];
945  if ( SetCfgGatekeeper( "Configurator::SetCfgFloat() "
946  "Attempting to set public config variable in line",
947  a_key,
948  (CfgVals[ i ].get())->getlevel()
949  )) {
950  return;
951  }
952 
953  if ( (CfgVals[ i ].get())->gettype() != CFG_FLOAT ) {
954 sprintf( lineno, "%d", m_lineno );
955  g_msg->Warn( WARN_FILE, "Configurator::SetCfgFloat() "
956  "Non-floating point identifier specified at config line",
957  lineno );
958  ShowIdType( i );
959  exit(1);
960  }
961 
962  dynamic_cast<CfgFloat*>((CfgVals[ i ].get()))->set( l_val );
963 }

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 
)
850 {
851  //int l_val;
852  char lineno[20];
853  std::string l_key = a_key;
854 
855  std::istringstream iss( a_val );
856 
857  int number;
858  std::vector<double> array_double;
859  while ( iss >> number )
860  array_double.push_back( number );
861  // for now we will leave the gatekeeper
862  // Check access security.
863  unsigned int i = CfgI[ l_key ];
864  if ( SetCfgGatekeeper( "Configurator::SetCfgInt() "
865  "Attempting to set public config variable in line",
866  a_key,
867  (CfgVals[ i ].get())->getlevel()
868  )) {
869  return;
870  }
871 
872  if ( (CfgVals[ i ].get())->gettype() != CFG_INT ) {
873  sprintf( lineno, "%d", m_lineno );
874  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
875  "Non-integer identifier specified at config line",
876  lineno );
877  ShowIdType( i );
878  exit(1);
879  }
880 
881  dynamic_cast<CfgArray_Double*>((CfgVals[ i ].get()))->set( array_double );
882 }

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
635 {
636  if ( a_level == CFG_PRIVATE ) {
637  // Attempting to set private config variable. Ignore quietly.
638  return true;
639  }
640 
641  if ( a_level == CFG_PUBLIC &&
643  // Attempting to set public config variable. Warn and
644  // possibly exit if this is configured.
645  char lineno[20];
646  sprintf( lineno, "%d", m_lineno );
647  g_msg->Warn( WARN_FILE, a_method, lineno );
648 
650  exit(1);
651  }
652  return true;
653  }
654  return false;
655 }

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 
)
660 {
661  int l_val;
662  char lineno[20];
663  std::string l_key = a_key;
664 
665  if ( sscanf( a_val.c_str(), "%d", &l_val ) != 1 ) {
666  sprintf( lineno, "%d", m_lineno );
667  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
668  "Not an integer data value at config line",
669  lineno );
670  exit(1);
671  }
672  // for now we will leave the gatekeeper
673  // Check access security.
674  unsigned int i = CfgI[ l_key ];
675  if ( SetCfgGatekeeper( "Configurator::SetCfgInt() "
676  "Attempting to set public config variable in line",
677  a_key,
678  (CfgVals[ i ].get())->getlevel()
679  )) {
680  return;
681  }
682 
683  if ( (CfgVals[ i ].get())->gettype() != CFG_INT ) {
684  sprintf( lineno, "%d", m_lineno );
685  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
686  "Non-integer identifier specified at config line",
687  lineno );
688  ShowIdType( i );
689  exit(1);
690  }
691 
692  dynamic_cast<CfgInt*>(CfgVals[ i ].get())->set( l_val );
693 }

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 
)
968 {
969  char lineno[20];
970  std::string l_key = a_key;
971 
972  // Check access security.
973  unsigned int i = CfgI[ l_key ];
974  if ( SetCfgGatekeeper( "Configurator::SetCfgStr() "
975  "Attempting to set public config variable in line",
976  a_key,
977  (CfgVals[ i ].get())->getlevel()
978  )) {
979  return;
980  }
981 
982  if ( (CfgVals[ i ].get())->gettype() != CFG_STRING ) {
983  sprintf( lineno, "%d", m_lineno );
984  g_msg->Warn( WARN_FILE, "Configurator::SetCfgStr() "
985  "Non-string identifier specified at config line",
986  lineno );
987  ShowIdType( i );
988  exit(1);
989  }
990 
991  dynamic_cast<CfgStr*>((CfgVals[ i ].get()))->set( a_val );
992 }

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
621 {
623  "Type for identifier ",
624  (CfgVals[ a_i ].get())->getkey().c_str() );
625  g_msg->WarnAddInfo( WARN_FILE, " is (",
626  CfgTypeStrings[ (CfgVals[ a_i ].get())->gettype() ] );
627  g_msg->WarnAddInfo( WARN_FILE, ")\n", "" );
628 }

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 
)
1143  {
1144  char lineno[20];
1145  if (type.compare("int") == 0){
1146  int l_val;
1147  if ( sscanf( value.c_str(), "%d", &l_val ) != 1 ) {
1148  sprintf(lineno, "%d", m_lineno);
1149  g_msg->Warn(WARN_FILE, "Configurator::StoreFromConfig() "
1150  "Not an integer data value at config line",
1151  lineno);
1152  exit(1);
1153  }
1154 
1155  //will create first an object of CfgInt (will allocate memory for it)
1156  auto new_object (std::make_shared<CfgInt>( CfgInt ( name,CFG_CUSTOM,l_val, true)));
1157  // register it in "database" : for dynamically allocated data this function "moves" the ownership of the object
1158  this->Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1159 
1160 
1161  } else if (type.compare("bool") == 0){
1162  bool l_val{false};
1163  if ( value.compare( "false" ) == 0 ) {
1164  ; // l_val defaults to false.
1165  } else if ( value.compare( "true" ) == 0 ) {
1166  l_val = true;
1167  } else {
1168  sprintf( lineno, "%d", m_lineno );
1169  g_msg->Warn( WARN_FILE, "Configurator::SetCfgBool() "
1170  "Not a boolean data value at config line",
1171  lineno );
1172  exit(1);
1173  }
1174 
1175  //will create first an object of CfgInt
1176  auto new_object (std::make_shared<CfgBool>( CfgBool ( name,CFG_CUSTOM,l_val, true)));
1177 
1178  // register it in "database"
1179  this->Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1180 
1181 
1182  } else if ((type.compare("double") == 0)||(type.compare("float") == 0)){
1183  double l_val;
1184  if ( sscanf( value.c_str(), "%lf", &l_val ) != 1 ) {
1185  sprintf(lineno, "%d", m_lineno);
1186  g_msg->Warn(WARN_FILE, "Configurator::StoreFromConfig() "
1187  "Not an double data value at config line",
1188  lineno);
1189  exit(1);
1190  }
1191 
1192  //will create first an object of CfgFloat
1193  auto new_object (std::make_shared<CfgFloat>( CfgFloat ( name,CFG_CUSTOM,l_val, true)));
1194 
1195  // "register" it in "database"
1196  this->Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1197 
1198 
1199  }
1200  else if (type.compare("string") == 0) {
1201 
1202 
1203  //will create first an object of CfgInt
1204  auto new_object (std::make_shared<CfgStr>(CfgStr (name, CFG_CUSTOM, ExtractString(value), true)));
1205  // register it in "database"
1206  this->Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1207 
1208  }
1209  else if (type.compare("array int") == 0) {
1210  try {
1211  std::regex int_regex("(\s*(-*[0-9]+\s+)+\s*)");
1212 
1213 
1214  std::smatch smatch;
1215  std::string therest_str{};
1216  std::string extracted_str;
1217  if (std::regex_search(value, smatch, int_regex)) {
1218  if (smatch.size() < 1) {
1219  sprintf(lineno, "%d", m_lineno);
1220  g_msg->Warn(WARN_FILE, "Configurator::StoreFromConfig() "
1221  + name + " Unsuccessful parsing: Syntax error at",
1222  lineno);
1223  }
1224  }
1225  }
1226  catch (const std::regex_error& e) {
1227  sprintf(lineno, "%d", m_lineno);
1228  std::cout << "regex_error caught: " << e.what() << '\n';
1229  g_msg->Warn(WARN_FILE, "Configurator::StoreFromConfig()\n"
1230  " Regex error ", lineno);
1231  }
1232  std::vector<int> array_vec=ParseArrayInt(value);
1233  int a_numvals = int(array_vec.size());
1234 
1235  //will create first an object of CfgInt
1236  auto new_object (std::make_shared<CfgArray_Int>(CfgArray_Int (name, CFG_CUSTOM, a_numvals, array_vec, true)));
1237  // register it in "database"
1238  this->Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1239 
1240  }
1241  else if (type.compare("array double") == 0) {
1242  try {
1243  std::regex int_regex("(\s*(-*[0-9.]+\s+)+\s*)");
1244 
1245 
1246  std::smatch smatch;
1247  std::string therest_str{};
1248  std::string extracted_str;
1249  if (std::regex_search(value, smatch, int_regex)) {
1250  if (smatch.size() < 1) {
1251  sprintf(lineno, "%d", m_lineno);
1252  g_msg->Warn(WARN_FILE, "Configurator::StoreFromConfig() "
1253  + name + " Unsuccessful parsing: Syntax error at",
1254  lineno);
1255  }
1256  }
1257  }
1258  catch (const std::regex_error& e) {
1259  sprintf(lineno, "%d", m_lineno);
1260  std::cout << "regex_error caught: " << e.what() << '\n';
1261  g_msg->Warn(WARN_FILE, "Configurator::StoreFromConfig()\n"
1262  " Regex error ", lineno);
1263  }
1264  std::vector<double> array_vec=ParseArrayDouble(value);
1265  int a_numvals = int(array_vec.size());
1266 
1267  //will create first an object of CfgInt
1268  auto new_object (std::make_shared<CfgArray_Double>(CfgArray_Double (name, CFG_CUSTOM, a_numvals, array_vec, true)));
1269  // register it in "database"
1270  this->Register(std::move(std::static_pointer_cast<CfgBase>(new_object)) , name );
1271 
1272  }
1273 }

References CFG_CUSTOM, ExtractString(), g_msg, m_lineno, ParseArrayDouble(), ParseArrayInt(), Register(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ParseCfgLine().

Member Data Documentation

◆ CfgI

◆ CfgVals

◆ m_lineno


The documentation for this class was generated from the following files:
CFG_ARRAY_INT
Definition: Configurator.h:64
Configurator::SetCfgArrayDouble
void SetCfgArrayDouble(std::string a_key, std::string a_val)
Definition: Configurator.cpp:807
Configurator::SetCfgBool
void SetCfgBool(std::string a_key, std::string a_val)
Definition: Configurator.cpp:884
CfgTypeStrings
static const std::string CfgTypeStrings[]
Definition: Configurator.cpp:71
WARN_FILE
Definition: MapErrorMsg.h:37
CFG_INT
Definition: Configurator.h:60
CFG_ARRAY_DOUBLE
Definition: Configurator.h:65
CFG_MAX_LINE_LENGTH
#define CFG_MAX_LINE_LENGTH
Definition: Configurator.h:52
CfgStr::value
char * value() const
Definition: Configurator.h:182
MapErrorMsg::WarnAddInfo
void WarnAddInfo(MapErrorState a_level, std::string a_add1, std::string a_add2)
Definition: MapErrorMsg.cpp:160
CFG_PUBLIC
Definition: Configurator.h:71
CfgStr
String configurator entry class.
Definition: Configurator.h:173
Configurator::SetCfgStr
void SetCfgStr(std::string a_key, std::string a_val)
Definition: Configurator.cpp:967
Configurator::SetCfgFunction
void SetCfgFunction(std::string a_key, std::string a_val)
Definition: Configurator.cpp:849
CfgFloat::value
double value() const
Definition: Configurator.h:142
CfgBase::get_rangetest
bool get_rangetest() const
Definition: Configurator.h:96
CFG_STRING
Definition: Configurator.h:63
CFG_BOOL
Definition: Configurator.h:62
Configurator::SetCfgInt
void SetCfgInt(std::string a_key, std::string a_val)
Definition: Configurator.cpp:659
Configurator::ExtractString
std::string ExtractString(std::string a_line) const
Definition: Configurator.cpp:395
l_cfg_public_warn_on_set
static CfgBool l_cfg_public_warn_on_set("CFG_PUBLIC_WARN_ON_SET", CFG_CUSTOM, true)
CfgBool::value
bool value() const
Definition: Configurator.h:164
Configurator::ShowIdType
void ShowIdType(unsigned int a_i)
Definition: Configurator.cpp:620
Configurator::ParseCfgLine
bool ParseCfgLine(std::string a_line)
Definition: Configurator.cpp:476
Configurator::SetCfgGatekeeper
bool SetCfgGatekeeper(const std::string a_method, const std::string a_key, CfgSecureLevel a_level)
Definition: Configurator.cpp:632
Configurator::CfgVals
std::vector< std::shared_ptr< CfgBase > > CfgVals
Definition: Configurator.h:255
Configurator::CfgI
std::map< std::string, unsigned int > CfgI
Definition: Configurator.h:254
Configurator::SetCfgArrayDoubleCsv
void SetCfgArrayDoubleCsv(std::string a_key, std::string a_val)
Definition: Configurator.cpp:771
CfgBool
Bool configurator entry class.
Definition: Configurator.h:155
WARN_UNDEF
Definition: MapErrorMsg.h:36
CfgBase::gettype
virtual CfgType gettype()
Definition: Configurator.h:92
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
CfgArray_Double
Definition: Configurator.h:208
CFG_FLOAT
Definition: Configurator.h:61
Configurator::Register
bool Register(CfgBase *a_cfgval, const std::string &a_key)
Definition: Configurator.cpp:299
CfgInt::value
int value() const
Definition: Configurator.h:116
CfgArray_Double::value
std::vector< double > value() const
Definition: Configurator.h:219
Configurator::CheckBounds
bool CheckBounds(std::shared_ptr< CfgBase > a_cfgval, CfgBase *b_cfgval)
Definition: Configurator.cpp:1274
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
CfgInt
Integer configurator entry class.
Definition: Configurator.h:102
l_cfg_public_exit_on_set
static CfgBool l_cfg_public_exit_on_set("CFG_PUBLIC_EXIT_ON_SET", CFG_CUSTOM, true)
CfgFloat
Double configurator entry class.
Definition: Configurator.h:126
CfgArray_Int::value
std::vector< int > value() const
Definition: Configurator.h:201
Configurator::DumpSymbols
void DumpSymbols(const char *a_dumpfile, CfgSecureLevel a_level)
Definition: Configurator.cpp:1014
Configurator::SetCfgFloat
void SetCfgFloat(std::string a_key, std::string a_val)
Definition: Configurator.cpp:926
CFG_CUSTOM
Definition: Configurator.h:70
Configurator::SetCfgArrayIntCsv
void SetCfgArrayIntCsv(std::string a_key, std::string a_val)
Definition: Configurator.cpp:736
Configurator::ParseArrayDouble
std::vector< double > ParseArrayDouble(const std::string &a_stringtoparse)
Definition: Configurator.cpp:1402
Configurator::StoreFromConfig
void StoreFromConfig(const std::string &name, std::string type, std::string value)
Definition: Configurator.cpp:1143
CfgSecureStrings
static const std::string CfgSecureStrings[]
Definition: Configurator.cpp:64
Configurator::ParseCommentLine
bool ParseCommentLine(std::string a_line)
Reads each line and parses it.
Definition: Configurator.cpp:464
Configurator::m_lineno
unsigned int m_lineno
Definition: Configurator.h:258
CfgArray_Int
Array_Int configurator entry class.
Definition: Configurator.h:189
CfgBase::set_definedinconfig
void set_definedinconfig(bool flag)
Definition: Configurator.h:94
CFG_PRIVATE
Definition: Configurator.h:72
Configurator::ParseArrayInt
std::vector< int > ParseArrayInt(const std::string &a_stringtoparse)
Definition: Configurator.cpp:1392
Configurator::SetCfgArrayInt
void SetCfgArrayInt(std::string a_key, std::string a_val)
Definition: Configurator.cpp:695