The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPConfiguration Class Reference

#include <configuration.h>

List of all members.

Public Member Functions

int find (const char *key)
void load (const char *file)
void record (const string &key, string &addr)
void record (const string &key, double &addr)
void record (const string &key, int &addr)
void record_cstring (const char *key, const char *val)
void record_double (const string &key, const string &val)
void record_int (const string &key, const string &val)
void record_string (const string &key, const string &val)
void remove_comments (string &str)
void remove_headwhite (string &str)
void remove_tailwhite (string &str)
void remove_whites (string &str)
 ~MPConfiguration ()

Static Public Member Functions

double doubleval (const char *key)
int intval (const char *key)
void print_values (std::ostream &ostr)
string stringval (const char *key)

Private Attributes

map< string, double * > m_doublevars
ifstream m_infile
map< string, int * > m_intvars
map< string, string * > m_stringvars
map< string, stringm_vars

Static Private Attributes

map< string, string > * m_varsPtr


Constructor & Destructor Documentation

~MPConfiguration  ) 
 

Definition at line 23 of file configuration.cpp.

References m_infile.

00023                                   {
00024         if (!m_infile.is_open()) 
00025                 m_infile.close();
00026 }


Member Function Documentation

double doubleval const char *  key  )  [static]
 

Definition at line 142 of file configuration.cpp.

References m_varsPtr.

00142                                                   {
00143         return atof((*m_varsPtr)[key].c_str());
00144 }

int find const char *  key  ) 
 

Definition at line 128 of file configuration.cpp.

Referenced by load().

00128                                           {
00129         map<string, string>::const_iterator mi;
00130         mi = (*m_varsPtr).find(key);
00131         return (mi != (*m_varsPtr).end());
00132 }

int intval const char *  key  )  [static]
 

Definition at line 136 of file configuration.cpp.

References m_varsPtr.

Referenced by CommThread::CommThread(), CommThread::GetClientIP(), CommThread::Process(), and CommThread::~CommThread().

00136                                             {
00137         return(atoi((*m_varsPtr)[key].c_str()));
00138 }

void load const char *  file  ) 
 

Definition at line 78 of file configuration.cpp.

References file, find(), m_doublevars, m_infile, m_intvars, m_stringvars, remove_comments(), remove_whites(), string, and v.

Referenced by IniConfig::IniConfig().

00078                                            {
00079         m_infile.open(file);
00080         if (!m_infile.is_open()) return;
00081         while(!m_infile.eof()) {
00082                 char buf[255];
00083                 string line;
00084                 string key;
00085                 string value;
00086                 string::size_type index;
00087 
00088                 m_infile.getline(buf, 255);
00089                 if (buf[0] == '#') continue;
00090                 line = buf;
00091                 
00092                 index = line.find("=");
00093                 if (index == -1) continue;
00094 
00095                 key = line.substr(0, index);
00096                 value = line.substr(index+1);
00097 
00098                 remove_whites(key);
00099                 remove_comments(value);
00100                 remove_whites(value);
00101 
00102                 if (key == "" || value == "") continue;
00103 
00104                 if (find(key.c_str()))
00105                         (*m_varsPtr)[key] = value;
00106 
00107                 if (m_intvars.find(key) != m_intvars.end()) {
00108                         int *v = m_intvars[key];
00109                         *v = atoi(value.c_str());
00110                 }
00111                 
00112                 if (m_doublevars.find(key) != m_doublevars.end()) {
00113                         double *v = m_doublevars[key];
00114                         *v = atof(value.c_str());
00115                 }
00116 
00117                 if (m_stringvars.find(key) != m_stringvars.end()) {
00118                         string *v = m_stringvars[key];
00119                         *v = value;
00120                 }
00121         }
00122 
00123         m_infile.close();
00124 }

Here is the call graph for this function:

void print_values std::ostream &  ostr  )  [static]
 

Definition at line 154 of file configuration.cpp.

00154                                                     {
00155 
00156         for (map<string, string>::iterator it = (*m_varsPtr).begin(); 
00157                 it != (*m_varsPtr).end(); ++it)
00158                 ostr << it->first << "=" << it->second << endl;
00159 
00160 }

void record const string key,
string addr
 

Definition at line 71 of file configuration.cpp.

References m_stringvars, and record_string().

00071                                                              {
00072         record_string(key, addr);
00073         m_stringvars.insert( make_pair ( key, &addr ) );
00074 }

Here is the call graph for this function:

void record const string key,
double &  addr
 

Definition at line 60 of file configuration.cpp.

References m_doublevars, record_double(), s, and string.

00060                                                              {
00061 
00062         char buffer[50];
00063         gcvt( addr, 7, buffer );
00064         string s = buffer;
00065         record_double(key, s);
00066         m_doublevars.insert( make_pair ( key, &addr ) );
00067 }

Here is the call graph for this function:

void record const string key,
int &  addr
 

Definition at line 51 of file configuration.cpp.

References m_intvars, and record_int().

00051                                                           {
00052         char buffer[255];
00053         itoa (addr, buffer, 10);
00054         record_int(key, buffer);
00055         m_intvars.insert( make_pair ( key, &addr ) );
00056 }

Here is the call graph for this function:

void record_cstring const char *  key,
const char *  val
 

void record_double const string key,
const string val
 

Definition at line 37 of file configuration.cpp.

References m_vars, and m_varsPtr.

Referenced by record().

00037                                                                          {
00038         m_vars.insert ( make_pair ( key, val ) );
00039         m_varsPtr = &m_vars;
00040 }

void record_int const string key,
const string val
 

Definition at line 30 of file configuration.cpp.

References m_vars, and m_varsPtr.

Referenced by IniConfig::IniConfig(), and record().

00030                                                                       {
00031         m_vars.insert ( make_pair ( key, val ) );
00032         m_varsPtr = &m_vars;
00033 }

void record_string const string key,
const string val
 

Definition at line 44 of file configuration.cpp.

References m_vars, and m_varsPtr.

Referenced by IniConfig::IniConfig(), and record().

00044                                                                          {
00045         m_vars.insert( make_pair ( key, val ) );
00046         m_varsPtr = &m_vars;
00047 }

void remove_comments string str  ) 
 

Definition at line 164 of file configuration.cpp.

Referenced by load().

00164                                                   {
00165         if (str.empty()) return;
00166         int pos = str.find('#', 0);
00167         if (pos > 0)
00168                 str.erase(pos, str.length()-pos);
00169 }

void remove_headwhite string str  ) 
 

Definition at line 173 of file configuration.cpp.

References s.

Referenced by remove_whites().

00173                                                    {
00174         if (str.empty()) return;
00175         for (string::iterator s = str.begin(); s != str.end(); ++s) {
00176                 if (!isspace(*s)) break;
00177                 str = s+1;
00178         }
00179 }

void remove_tailwhite string str  ) 
 

Definition at line 183 of file configuration.cpp.

References s.

Referenced by remove_whites().

00183                                                    {
00184         if (str.empty()) return;
00185         for (string::iterator s = str.end()-1; s != str.begin(); --s) {
00186                 if (!isspace(*s)) break;
00187                 str = str.substr(0, str.length()-1);
00188         }
00189 }

void remove_whites string str  ) 
 

Definition at line 193 of file configuration.cpp.

References remove_headwhite(), and remove_tailwhite().

Referenced by load().

00193                                                 {
00194         remove_tailwhite(str);
00195         remove_headwhite(str);
00196 }

Here is the call graph for this function:

string stringval const char *  key  )  [static]
 

Definition at line 148 of file configuration.cpp.

References string.

Referenced by CommThread::GetClientIP().

00148                                                   {
00149         return (*m_varsPtr)[key];
00150 }


Member Data Documentation

map<string, double *> m_doublevars [private]
 

Definition at line 26 of file configuration.h.

Referenced by load(), and record().

ifstream m_infile [private]
 

Definition at line 23 of file configuration.h.

Referenced by load(), and ~MPConfiguration().

map<string, int *> m_intvars [private]
 

Definition at line 25 of file configuration.h.

Referenced by load(), and record().

map<string, string *> m_stringvars [private]
 

Definition at line 27 of file configuration.h.

Referenced by load(), and record().

map<string, string> m_vars [private]
 

Definition at line 24 of file configuration.h.

Referenced by record_double(), record_int(), and record_string().

map< string, string > * m_varsPtr [static, private]
 

Definition at line 19 of file configuration.cpp.

Referenced by doubleval(), intval(), record_double(), record_int(), and record_string().


The documentation for this class was generated from the following files:
Generated on Mon Nov 8 17:08:34 2004 for MPT by  doxygen 1.3.9.1