ALMaSS Rabbit ODdox  1.00
The rabbit model description following ODdox protocol
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Configurator Class Reference

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

#include <configurator.h>

Public Member Functions

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 char *a_key)
 

Private Member Functions

void ParseCfgLine (char *a_line)
 
void SetCfgInt (char *a_key, char *a_val)
 
void SetCfgFloat (char *a_key, char *a_val)
 
void SetCfgBool (char *a_key, char *a_val)
 
void SetCfgStr (char *a_key, char *a_val)
 
bool LastDoubleQuote (char *a_rest_of_line)
 
bool SetCfgGatekeeper (const char *a_method, const char *a_key, CfgSecureLevel a_level)
 
void ShowIdType (unsigned int a_i)
 
char * ExtractString (char *a_line)
 
void DumpSymbols (const char *a_dumpfile, CfgSecureLevel a_level)
 

Private Attributes

map< string, unsigned int > CfgI
 
vector< CfgBase * > CfgVals
 
unsigned int m_lineno
 

Detailed Description

A class to provide standard parameter entry facilities.

Definition at line 148 of file configurator.h.

Constructor & Destructor Documentation

Configurator::Configurator ( void  )

Definition at line 133 of file configurator.cpp.

References m_lineno.

Referenced by CfgBase::CfgBase().

134 {
135  m_lineno = 0;
136 }
unsigned int m_lineno
Definition: configurator.h:154
Configurator::~Configurator ( void  )

Definition at line 140 of file configurator.cpp.

141 {
142  ;
143 }

Member Function Documentation

void Configurator::DumpAllSymbolsAndExit ( const char *  a_dumpfile)

Definition at line 566 of file configurator.cpp.

References CFG_PRIVATE, and DumpSymbols().

Referenced by Landscape::DumpAllSymbolsAndExit().

567 {
568  DumpSymbols( a_dumpfile, CFG_PRIVATE );
569  exit(1);
570 }
void DumpSymbols(const char *a_dumpfile, CfgSecureLevel a_level)
void Configurator::DumpPublicSymbols ( const char *  a_dumpfile,
CfgSecureLevel  a_level 
)

Definition at line 555 of file configurator.cpp.

References CFG_PUBLIC, and DumpSymbols().

Referenced by Landscape::DumpPublicSymbols().

557 {
558  if ( a_level > CFG_PUBLIC ) {
559  a_level = CFG_PUBLIC;
560  }
561  DumpSymbols( a_dumpfile, a_level );
562 }
void DumpSymbols(const char *a_dumpfile, CfgSecureLevel a_level)
void Configurator::DumpSymbols ( const char *  a_dumpfile,
CfgSecureLevel  a_level 
)
private

Definition at line 573 of file configurator.cpp.

References CFG_BOOL, CFG_FLOAT, CFG_INT, CFG_MAX_LINE_LENGTH, CFG_STRING, CfgI, CfgSecureStrings, CfgTypeStrings, CfgVals, g_msg, CfgBase::getlevel(), CfgStr::gettype(), CfgInt::value(), CfgFloat::value(), CfgBool::value(), CfgStr::value(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by DumpAllSymbolsAndExit(), and DumpPublicSymbols().

575 {
576  FILE *l_dumpfile;
577  char l_oprefix[ CFG_MAX_LINE_LENGTH ] = {""};
578  char l_nprefix[ CFG_MAX_LINE_LENGTH ];
579  const char* l_id;
580  l_dumpfile=fopen( a_dumpfile, "w" );
581  if (!l_dumpfile) {
582  g_msg->Warn( WARN_FILE, "Configurator::DumpSymbols() "
583  "Unable to open file for writing:",
584  a_dumpfile );
585  exit(1);
586  }
587 
588  typedef map<string,unsigned int>::const_iterator MI;
589 
590  for ( MI ii = CfgI.begin(); ii != CfgI.end(); ii++ ) {
591  unsigned int i = ii->second;
592 
593  // Skip 'secret' variables.
594  if ( CfgVals[ i ]->getlevel() > a_level ) {
595  continue;
596  }
597 
598  // Weird hack to separate different groups of
599  // configuration names.
600  string rubbish=CfgVals[ i ]->getkey();
601  l_id=rubbish.c_str();
602  //l_id = CfgVals[ i ]->getkey().c_str();
603  sscanf( l_id, "%[A-Z]", l_nprefix );
604  if ( strcmp( l_oprefix, l_nprefix ) != 0 ) {
605  fprintf( l_dumpfile, "\n" );
606  strcpy( l_oprefix, l_nprefix );
607  }
608 
609  fprintf( l_dumpfile, "%s (%s) = ",
610  l_id,
611  CfgTypeStrings[ CfgVals[ i ]->gettype() ]
612  );
613 
614  switch( CfgVals[ i ]->gettype() ) {
615  case CFG_INT:
616  {
617  CfgInt* l_p = dynamic_cast<CfgInt*>(CfgVals[ i ]);
618  fprintf( l_dumpfile, "%d", l_p->value() );
619  break;
620  }
621  case CFG_FLOAT:
622  {
623  CfgFloat* l_p = dynamic_cast<CfgFloat*>(CfgVals[ i ]);
624  fprintf( l_dumpfile, "%f", l_p->value() );
625  break;
626  }
627  case CFG_BOOL:
628  {
629  CfgBool* l_p = dynamic_cast<CfgBool*>(CfgVals[ i ]);
630  if ( l_p->value() ) {
631  fprintf( l_dumpfile, "true" );
632  } else {
633  fprintf( l_dumpfile, "false" );
634  }
635  break;
636  }
637  case CFG_STRING:
638  {
639  CfgStr* l_p = dynamic_cast<CfgStr*>(CfgVals[ i ]);
640  fprintf( l_dumpfile, "\"%s\"", l_p->value() );
641  break;
642  }
643  default:
644  {
645  char l_errno[20];
646  sprintf( l_errno, "%d", CfgVals[ i ]->gettype() );
647  g_msg->Warn( WARN_FILE, "Configurator::DumpSymbols() "
648  "Unknown symbol type read:",
649  l_errno );
650  exit(1);
651  }
652  }
653  fprintf( l_dumpfile, " # %s\n",
654  CfgSecureStrings[ CfgVals[ i ]->getlevel() ]
655  );
656  }
657 
658 }
static const char * CfgTypeStrings[]
Integer configurator entry class.
Definition: configurator.h:85
double value(void)
Definition: configurator.h:107
static const char * CfgSecureStrings[]
const char * value(void)
Definition: configurator.h:139
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool value(void)
Definition: configurator.h:123
vector< CfgBase * > CfgVals
Definition: configurator.h:151
String configurator entry class.
Definition: configurator.h:132
Bool configurator entry class.
Definition: configurator.h:116
#define CFG_MAX_LINE_LENGTH
Definition: configurator.h:46
int value(void)
Definition: configurator.h:92
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
Double configurator entry class.
Definition: configurator.h:100
map< string, unsigned int > CfgI
Definition: configurator.h:150
char * Configurator::ExtractString ( char *  a_line)
private

Definition at line 188 of file configurator.cpp.

References g_msg, LastDoubleQuote(), m_lineno, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ParseCfgLine().

189 {
190  char lineno[ 20 ];
191 
192  // scan for the first double quote or end of line.
193  while ( *a_line != '"' && *a_line != '\0' ) {
194  a_line++;
195  }
196 
197  // The first char in the string had better contain a '"':
198  if ( *a_line != '"' ) {
199  sprintf( lineno, "%d", m_lineno );
200  g_msg->Warn( WARN_FILE, "Configurator::ExtractString()\n"
201  " String not enclosed in double quotes at "
202  "config line ", lineno );
203  exit(1);
204  }
205 
206  char* endline = ++a_line;
207  bool escaped = false, found = false;
208 
209  while ( *endline != '\0' ) {
210  if ( *endline == '\\' ) {
211  escaped = true;
212  endline++;
213 
214  if ( *endline == '"' &&
215  LastDoubleQuote( endline )) {
216  escaped = false;
217  } else {
218  continue;
219  }
220  }
221  if ( *endline == '"' && !escaped ) {
222  // Found end of string, terminate properly and break the loop.
223  *endline++ = '\0';
224  found = true;
225  break;
226  }
227  escaped = false;
228  endline++;
229  }
230 
231  if ( !found ) {
232  sprintf( lineno, "%d", m_lineno );
233  g_msg->Warn( WARN_FILE, "Configurator::ExtractString() "
234  "No ending double quote after string at "
235  "config line ", lineno );
236  exit(1);
237  }
238 
239 
240  // Check for comment if remainder of line isn't empty.
241  if ( sscanf( endline, "%*s" ) == 1 ) {
242  // Non-empty comment line.
243  if ( sscanf( endline, "%*[#]" ) != 1 ) {
244  // But not initiated by '#'.
245  sprintf( lineno, "%d", m_lineno );
246  g_msg->Warn( WARN_FILE, "Configurator::ExtractString() "
247  "Illegal comment at "
248  "config line ", lineno );
249  exit(1);
250  }
251  }
252 
253  return a_line;
254 }
bool LastDoubleQuote(char *a_rest_of_line)
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
bool Configurator::LastDoubleQuote ( char *  a_rest_of_line)
private

Definition at line 257 of file configurator.cpp.

Referenced by ExtractString().

258 {
259  a_rest_of_line++;
260 
261  while ( *a_rest_of_line != '\0' && *a_rest_of_line != '#' ) {
262  if ( *a_rest_of_line == '"' ) {
263  return false;
264  }
265  a_rest_of_line++;
266  }
267  return true;
268 }
void Configurator::ParseCfgLine ( char *  a_line)
private

Definition at line 272 of file configurator.cpp.

References CFG_MAX_LINE_LENGTH, CfgI, ExtractString(), g_msg, m_lineno, SetCfgBool(), SetCfgFloat(), SetCfgInt(), SetCfgStr(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ReadSymbols().

273 {
274  char l_id [ CFG_MAX_LINE_LENGTH ];
275  char l_type[ CFG_MAX_LINE_LENGTH ];
276  char l_sep [ CFG_MAX_LINE_LENGTH ];
277  char l_val [ CFG_MAX_LINE_LENGTH ];
278  char l_comm[ CFG_MAX_LINE_LENGTH ];
279  char lineno[20];
280 
281  if ( sscanf( a_line, "%[#]", l_id ) == 1 ) {
282  // Comment line.
283  return;
284  }
285 
286  if ( sscanf( a_line, "%s", l_id) == EOF ) {
287  // Empty line consisting only of white spaces.
288  return;
289  }
290 
291  //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) );
292 int l_conv = sscanf( a_line, "%[A-Z_] (%[a-z]) %s", l_id, l_type, l_sep );
293 
294  if ( l_conv < 3 ) {
295  // Syntax terror.
296  sprintf( lineno, "%d", m_lineno );
297  g_msg->Warn( WARN_FILE, "Configurator::ParseCfgLine() "
298  "Syntax error at config line ",
299  lineno );
300  exit(1);
301  }
302 
303  if ( strcmp( l_sep, "=" ) != 0 ) {
304  // Missing '=' assignment separator.
305  sprintf( lineno, "%d", m_lineno );
306  g_msg->Warn( WARN_FILE, "Configurator::ParseCfgLine() "
307  "Missing '=' assignment operator at config line ",
308  lineno );
309  exit(1);
310  }
311 
312  if ( CfgI.find( l_id ) == CfgI.end() ) {
313  // Key doesn't exists among the predefined, global configuration
314  // variables. Ignore quietly.
315  return;
316  }
317 
318  if ( strlen( l_type ) == 6 &&
319  strncmp( l_type, "string", 6 ) == 0 ) {
320  // We are not yet ready to do the assignment.
321  // If we really have a string enclosed in non-escaped
322  // double quotes at the end of the line, then we need to
323  // extract it first from our input.
324  SetCfgStr( l_id, ExtractString( a_line ));
325  return;
326  }
327 
328  // Not a string, so extract data value and possible comment.
329  l_conv = sscanf( a_line, "%*[A-Z_] (%*[a-z]) %*s %s %s",
330  l_val, l_comm );
331 
332  if ( l_conv == 2 && l_comm[0] != '#' ) {
333  // Illegal comment at end of line.
334  sprintf( lineno, "%d", m_lineno );
335  g_msg->Warn( WARN_FILE, "Configurator::ParseCfgLine() "
336  "Syntax error at end of config line ",
337  lineno );
338  exit(1);
339  }
340 
341  if ( strlen( l_type ) == 5 &&
342  strncmp( l_type, "float", 5 ) == 0 ) {
343  SetCfgFloat( l_id, l_val );
344  return;
345  }
346 
347  if ( strlen( l_type ) == 4 &&
348  strncmp( l_type, "bool", 4 ) == 0 ) {
349  SetCfgBool( l_id, l_val );
350  return;
351  }
352 
353  if ( strlen( l_type ) == 3 &&
354  strncmp( l_type, "int", 3 ) == 0 ) {
355  SetCfgInt( l_id, l_val );
356  return;
357  }
358 
359  sprintf( lineno, "%d", m_lineno );
360  g_msg->Warn( WARN_FILE, "Configurator::ParseCfgLine() "
361  "Unknown type specifier at config line ",
362  lineno );
363  exit(1);
364 }
void SetCfgInt(char *a_key, char *a_val)
void SetCfgFloat(char *a_key, char *a_val)
void SetCfgStr(char *a_key, char *a_val)
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
#define CFG_MAX_LINE_LENGTH
Definition: configurator.h:46
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
void SetCfgBool(char *a_key, char *a_val)
char * ExtractString(char *a_line)
map< string, unsigned int > CfgI
Definition: configurator.h:150
bool Configurator::ReadSymbols ( const char *  a_cfgfile)

Definition at line 166 of file configurator.cpp.

References CFG_MAX_LINE_LENGTH, g_msg, m_lineno, ParseCfgLine(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by Landscape::Landscape(), and Landscape::ReadSymbols().

166  {
167  ifstream cf_file;
168  char cfgline[ CFG_MAX_LINE_LENGTH ];
169  cf_file.open(a_cfgfile,fstream::in);
170  if ( !cf_file.is_open() ) {
171  g_msg->Warn( WARN_FILE, "Configurator::ReadSymbols() Unable to open file for reading: ", a_cfgfile );
172  exit(1);
173  }
174  while ( !cf_file.eof()) {
175  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
176  cf_file.getline(cfgline,CFG_MAX_LINE_LENGTH);
177  ParseCfgLine( cfgline );
178  m_lineno++;
179  }
180  cf_file.close();
181  return true;
182 }
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void ParseCfgLine(char *a_line)
#define CFG_MAX_LINE_LENGTH
Definition: configurator.h:46
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
bool Configurator::Register ( CfgBase a_cfgval,
const char *  a_key 
)

Definition at line 147 of file configurator.cpp.

References CfgI, and CfgVals.

Referenced by CfgBase::CfgBase().

148 {
149  string l_key = a_key;
150 
151  if ( CfgI.find( l_key ) != CfgI.end() ) {
152  // Couldn't register, already exists.
153  return false;
154  }
155 
156  unsigned int i = (int) CfgVals.size();
157  CfgI[ l_key ] = i;
158  CfgVals.resize( i+1 );
159  CfgVals[ i ] = a_cfgval;
160 
161  return true;
162 }
vector< CfgBase * > CfgVals
Definition: configurator.h:151
map< string, unsigned int > CfgI
Definition: configurator.h:150
void Configurator::SetCfgBool ( char *  a_key,
char *  a_val 
)
private

Definition at line 444 of file configurator.cpp.

References CFG_BOOL, CfgI, CfgVals, g_msg, CfgBase::getlevel(), CfgStr::gettype(), m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ParseCfgLine().

445 {
446  char lineno[20];
447  string l_key = a_key;
448  bool l_val = false;
449 
450  if ( strcmp ( a_val, "false" ) == 0 ) {
451  ; // l_val defaults to false.
452  } else if ( strcmp ( a_val, "true" ) == 0 ) {
453  l_val = true;
454  } else {
455  sprintf( lineno, "%d", m_lineno );
456  g_msg->Warn( WARN_FILE, "Configurator::SetCfgBool() "
457  "Not a boolean data value at config line",
458  lineno );
459  exit(1);
460  }
461 
462  // Check access security.
463  unsigned int i = CfgI[ l_key ];
464  if ( SetCfgGatekeeper( "Configurator::SetCfgBool() "
465  "Attempting to set public config variable in line",
466  a_key,
467  CfgVals[ i ]->getlevel()
468  )) {
469  return;
470  }
471 
472  if ( CfgVals[ i ]->gettype() != CFG_BOOL ) {
473  sprintf( lineno, "%d", m_lineno );
474  g_msg->Warn( WARN_FILE, "Configurator::SetCfgBool() "
475  "Non-boolean identifier specified at config line",
476  lineno );
477  ShowIdType( i );
478  exit(1);
479  }
480 
481  dynamic_cast<CfgBool*>(CfgVals[ i ])->set( l_val );
482 }
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool SetCfgGatekeeper(const char *a_method, const char *a_key, CfgSecureLevel a_level)
vector< CfgBase * > CfgVals
Definition: configurator.h:151
Bool configurator entry class.
Definition: configurator.h:116
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
map< string, unsigned int > CfgI
Definition: configurator.h:150
void ShowIdType(unsigned int a_i)
void Configurator::SetCfgFloat ( char *  a_key,
char *  a_val 
)
private

Definition at line 486 of file configurator.cpp.

References CFG_FLOAT, CfgI, CfgVals, FloatToDouble(), g_msg, CfgBase::getlevel(), CfgStr::gettype(), m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ParseCfgLine().

487 {
488  double l_val;
489  float f;
490  char lineno[20];
491  string l_key = a_key;
492 
493  if ( sscanf( a_val, "%f", &f) != 1 ) {
494  sprintf( lineno, "%d", m_lineno );
495  g_msg->Warn( WARN_FILE, "Configurator::SetCfgFloat() "
496  "Not a floating point data value at config line",
497  lineno );
498  exit(1);
499  }
500  FloatToDouble(l_val,f);
501 
502  // Check access security.
503  unsigned int i = CfgI[ l_key ];
504  if ( SetCfgGatekeeper( "Configurator::SetCfgFloat() "
505  "Attempting to set public config variable in line",
506  a_key,
507  CfgVals[ i ]->getlevel()
508  )) {
509  return;
510  }
511 
512  if ( CfgVals[ i ]->gettype() != CFG_FLOAT ) {
513 sprintf( lineno, "%d", m_lineno );
514  g_msg->Warn( WARN_FILE, "Configurator::SetCfgFloat() "
515  "Non-floating point identifier specified at config line",
516  lineno );
517  ShowIdType( i );
518  exit(1);
519  }
520 
521  dynamic_cast<CfgFloat*>(CfgVals[ i ])->set( l_val );
522 }
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool SetCfgGatekeeper(const char *a_method, const char *a_key, CfgSecureLevel a_level)
vector< CfgBase * > CfgVals
Definition: configurator.h:151
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
void FloatToDouble(double &, float)
Double configurator entry class.
Definition: configurator.h:100
map< string, unsigned int > CfgI
Definition: configurator.h:150
void ShowIdType(unsigned int a_i)
bool Configurator::SetCfgGatekeeper ( const char *  a_method,
const char *  a_key,
CfgSecureLevel  a_level 
)
private

Definition at line 380 of file configurator.cpp.

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 SetCfgBool(), SetCfgFloat(), SetCfgInt(), and SetCfgStr().

383 {
384  if ( a_level == CFG_PRIVATE ) {
385  // Attempting to set private config variable. Ignore quietly.
386  return true;
387  }
388 
389  if ( a_level == CFG_PUBLIC &&
391  // Attempting to set public config variable. Warn and
392  // possibly exit if this is configured.
393  char lineno[20];
394  sprintf( lineno, "%d", m_lineno );
395  g_msg->Warn( WARN_FILE, a_method, lineno );
396 
398  exit(1);
399  }
400  return true;
401  }
402  return false;
403 }
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
static CfgBool l_cfg_public_warn_on_set("CFG_PUBLIC_WARN_ON_SET", CFG_CUSTOM, true)
bool value(void)
Definition: configurator.h:123
static CfgBool l_cfg_public_exit_on_set("CFG_PUBLIC_EXIT_ON_SET", CFG_CUSTOM, true)
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
void Configurator::SetCfgInt ( char *  a_key,
char *  a_val 
)
private

Definition at line 407 of file configurator.cpp.

References CFG_INT, CfgI, CfgVals, g_msg, CfgBase::getlevel(), CfgStr::gettype(), m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ParseCfgLine().

408 {
409  int l_val;
410  char lineno[20];
411  string l_key = a_key;
412 
413  if ( sscanf( a_val, "%d", &l_val ) != 1 ) {
414  sprintf( lineno, "%d", m_lineno );
415  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
416  "Not an integer data value at config line",
417  lineno );
418  exit(1);
419  }
420 
421  // Check access security.
422  unsigned int i = CfgI[ l_key ];
423  if ( SetCfgGatekeeper( "Configurator::SetCfgInt() "
424  "Attempting to set public config variable in line",
425  a_key,
426  CfgVals[ i ]->getlevel()
427  )) {
428  return;
429  }
430 
431  if ( CfgVals[ i ]->gettype() != CFG_INT ) {
432  sprintf( lineno, "%d", m_lineno );
433  g_msg->Warn( WARN_FILE, "Configurator::SetCfgInt() "
434  "Non-integer identifier specified at config line",
435  lineno );
436  ShowIdType( i );
437  exit(1);
438  }
439 
440  dynamic_cast<CfgInt*>(CfgVals[ i ])->set( l_val );
441 }
Integer configurator entry class.
Definition: configurator.h:85
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool SetCfgGatekeeper(const char *a_method, const char *a_key, CfgSecureLevel a_level)
vector< CfgBase * > CfgVals
Definition: configurator.h:151
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
map< string, unsigned int > CfgI
Definition: configurator.h:150
void ShowIdType(unsigned int a_i)
void Configurator::SetCfgStr ( char *  a_key,
char *  a_val 
)
private

Definition at line 526 of file configurator.cpp.

References CFG_STRING, CfgI, CfgVals, g_msg, CfgBase::getlevel(), CfgStr::gettype(), m_lineno, SetCfgGatekeeper(), ShowIdType(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ParseCfgLine().

527 {
528  char lineno[20];
529  string l_key = a_key;
530 
531  // Check access security.
532  unsigned int i = CfgI[ l_key ];
533  if ( SetCfgGatekeeper( "Configurator::SetCfgStr() "
534  "Attempting to set public config variable in line",
535  a_key,
536  CfgVals[ i ]->getlevel()
537  )) {
538  return;
539  }
540 
541  if ( CfgVals[ i ]->gettype() != CFG_STRING ) {
542  sprintf( lineno, "%d", m_lineno );
543  g_msg->Warn( WARN_FILE, "Configurator::SetCfgStr() "
544  "Non-string identifier specified at config line",
545  lineno );
546  ShowIdType( i );
547  exit(1);
548  }
549 
550  dynamic_cast<CfgStr*>(CfgVals[ i ])->set( a_val );
551 }
unsigned int m_lineno
Definition: configurator.h:154
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool SetCfgGatekeeper(const char *a_method, const char *a_key, CfgSecureLevel a_level)
vector< CfgBase * > CfgVals
Definition: configurator.h:151
String configurator entry class.
Definition: configurator.h:132
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
map< string, unsigned int > CfgI
Definition: configurator.h:150
void ShowIdType(unsigned int a_i)
void Configurator::ShowIdType ( unsigned int  a_i)
private

Definition at line 368 of file configurator.cpp.

References CfgTypeStrings, CfgVals, g_msg, CfgBase::getkey(), CfgStr::gettype(), WARN_FILE, and MapErrorMsg::WarnAddInfo().

Referenced by SetCfgBool(), SetCfgFloat(), SetCfgInt(), and SetCfgStr().

369 {
371  "Type for identifier ",
372  CfgVals[ a_i ]->getkey().c_str() );
373  g_msg->WarnAddInfo( WARN_FILE, " is (",
374  CfgTypeStrings[ CfgVals[ a_i ]->gettype() ] );
375  g_msg->WarnAddInfo( WARN_FILE, ")\n", "" );
376 }
static const char * CfgTypeStrings[]
void WarnAddInfo(MapErrorState a_level, std::string a_add1, std::string a_add2)
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
vector< CfgBase * > CfgVals
Definition: configurator.h:151

Member Data Documentation

map<string,unsigned int> Configurator::CfgI
private
vector<CfgBase*> Configurator::CfgVals
private
unsigned int Configurator::m_lineno
private

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