ConfigFile Class Reference

#include <NuFCConfig.h>

List of all members.

Public Member Functions

 ConfigFile (std::string filename)
std::string GetString (std::string key, std::string section="", std::string defaultval="")
int GetInt (std::string key, std::string section="", int defaultval=0)
double GetFloat (std::string key, std::string section="", double defaultval=0.0)
bool GetBool (std::string key, std::string section="", bool defaultval=false)
bool Has_Section (std::string section)
 Asks if a specific section exists in the file.
bool Has_Key (std::string key, std::string section="")
 Asks if a specific key exists in the file.

Private Member Functions

std::string Decomment (const std::string &source)
 Strips the comments from a line.
std::string Trim (const std::string &source)
 Trims the whitespace off of the beginning and end of a string.
void ReadFile (std::ifstream &cfgfile)
 Controls the file reading.
bool IsSectionChange (const std::string &line)
 Tests for a section change in a line.
std::string Section (const std::string &line)
 Reads the section string out of a line.
bool ReadKeyPair (const std::string &section, const std::string &line)
 Reads a key-pair out of a line.

Private Attributes

std::map< std::string,
std::map< std::string,
std::string > > 
fStore
 The storage for the group/key-value from the file.

Detailed Description

Definition at line 83 of file NuFCConfig.h.


Constructor & Destructor Documentation

ConfigFile::ConfigFile ( std::string  filename  ) 

Member Function Documentation

std::string ConfigFile::Decomment ( const std::string &  source  )  [private]

Strips the comments from a line.

Referenced by ReadFile().

bool ConfigFile::GetBool ( std::string  key,
std::string  section = "",
bool  defaultval = false 
)
double ConfigFile::GetFloat ( std::string  key,
std::string  section = "",
double  defaultval = 0.0 
)
int ConfigFile::GetInt ( std::string  key,
std::string  section = "",
int  defaultval = 0 
)
std::string ConfigFile::GetString ( std::string  key,
std::string  section = "",
std::string  defaultval = "" 
)
bool ConfigFile::Has_Key ( std::string  key,
std::string  section = "" 
)

Asks if a specific key exists in the file.

bool ConfigFile::Has_Section ( std::string  section  ) 

Asks if a specific section exists in the file.

Referenced by NuFCRunner::BuildFromConfig().

bool ConfigFile::IsSectionChange ( const std::string &  line  )  [private]

Tests for a section change in a line.

Referenced by ReadFile().

void ConfigFile::ReadFile ( std::ifstream &  cfgfile  )  [private]

Controls the file reading.

Definition at line 256 of file NuFCConfig.cxx.

References Decomment(), IsSectionChange(), Msg::kWarning, MSG, ReadKeyPair(), Section(), and Trim().

00257 {
00258   int lineNo = 0;
00259   string line, section = "";
00260   
00261   // Loop over all lines in the file
00262   while(std::getline(file, line))
00263   {
00264     ++lineNo;
00265     
00266     // Clean up the line
00267     line = Decomment(line);
00268     line = Trim(line);
00269     
00270     // Ignore blank lines
00271     if (line.size() == 0) continue;
00272     
00273     // Several paths here: Section header, Key-Value pair or invalid.
00274     // First test for section header
00275     if (IsSectionChange(line))
00276     {
00277       section = Section(line);
00278       continue;
00279     }
00280     
00281     // Must be a key pair, or invalid
00282     if (!ReadKeyPair(section, line))
00283     {
00284       MSG("ConfigFile",Msg::kWarning) << "Invalid line " << lineNo << ": \"" << line << "\"" << endl; 
00285     }
00286     
00287   } // Go to next line
00288 }

bool ConfigFile::ReadKeyPair ( const std::string &  section,
const std::string &  line 
) [private]

Reads a key-pair out of a line.

Referenced by ReadFile().

std::string ConfigFile::Section ( const std::string &  line  )  [private]

Reads the section string out of a line.

Referenced by ReadFile().

std::string ConfigFile::Trim ( const std::string &  source  )  [private]

Trims the whitespace off of the beginning and end of a string.

Referenced by ReadFile().


Member Data Documentation

std::map<std::string, std::map<std::string, std::string> > ConfigFile::fStore [private]

The storage for the group/key-value from the file.

Definition at line 99 of file NuFCConfig.h.


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

Generated on 25 Apr 2018 for loon by  doxygen 1.6.1