NLMISC::CConfigFile::CVar Struct Reference

#include <config_file.h>


Detailed Description

CVar class. Used by CConfigFile. A CVar is return when you want to have a variable.

Example: see the CConfigFile example

Author:
Vianney Lecroart

Nevrax France

Date:
2000

Definition at line 132 of file config_file.h.

Internal use

enum  TVarType { T_UNKNOWN, T_INT, T_STRING, T_REAL }
void(* Callback )(CVar &var)
bool Comp
std::vector< int > IntValues
std::string Name
std::vector< double > RealValues
bool Root
int SaveWrap
std::vector< std::string > StrValues
TVarType Type
char * TypeName [] = { "Integer", "String", "Float" }

Public Types


Public Member Functions

void add (const CVar &var)
 CVar ()
bool operator!= (const CVar &var) const
bool operator== (const CVar &var) const
int size () const
Access to the variable content.
double asDouble (int index=0) const
 Get the content of the variable as a double.

float asFloat (int index=0) const
 Get the content of the variable as a float.

int asInt (int index=0) const
 Get the content of the variable as an integer.

std::string asString (int index=0) const
 Get the content of the variable as a STL string.

Set the variable content.
If the index is the size of the array, the value will be append at the end.

void setAsDouble (std::vector< double > vals)
 Set the content of the aray variable as a double.

void setAsDouble (double val, int index=0)
 Set the content of the variable as a double.

void setAsFloat (std::vector< float > vals)
 Set the content of the aray variable as a float.

void setAsFloat (float val, int index=0)
 Set the content of the variable as a float.

void setAsInt (std::vector< int > vals)
 Set the content of the aray variable as an integer.

void setAsInt (int val, int index=0)
 Set the content of the variable as an integer.

void setAsString (std::vector< std::string > vals)
 Set the content of the aray variable as a string.

void setAsString (std::string val, int index=0)
 Set the content of the variable as a STL string.


Member Enumeration Documentation

enum NLMISC::CConfigFile::CVar::TVarType
 

Enumeration values:
T_UNKNOWN 
T_INT 
T_STRING 
T_REAL 

Definition at line 186 of file config_file.h.


Constructor & Destructor Documentation

NLMISC::CConfigFile::CVar::CVar  )  [inline]
 

Definition at line 136 of file config_file.h.

References SaveWrap, and T_UNKNOWN.

00136 : Type(T_UNKNOWN), Root(false), SaveWrap(6) {}


Member Function Documentation

void NLMISC::CConfigFile::CVar::add const CVar var  ) 
 

Definition at line 202 of file config_file.cpp.

References IntValues, RealValues, StrValues, T_INT, T_REAL, T_STRING, and Type.

00203 {
00204         if (Type == var.Type)
00205         {
00206                 switch (Type)
00207                 {
00208                 case T_INT: IntValues.insert (IntValues.end(), var.IntValues.begin(), var.IntValues.end()); break;
00209                 case T_REAL: RealValues.insert (RealValues.end(), var.RealValues.begin(), var.RealValues.end()); break;
00210                 case T_STRING: StrValues.insert (StrValues.end(), var.StrValues.begin(), var.StrValues.end()); break;
00211                 default: break;
00212                 }
00213         }
00214 }

double NLMISC::CConfigFile::CVar::asDouble int  index = 0  )  const
 

Get the content of the variable as a double.

Definition at line 75 of file config_file.cpp.

References CheckType, index, IntValues, RealValues, StrValues, T_INT, T_REAL, and T_STRING.

Referenced by asFloat().

00076 {
00077         if (CheckType && Type != T_REAL) throw EBadType (Name, Type, T_REAL);
00078         switch (Type)
00079         {
00080         case T_INT:
00081                 if (index >= (int)IntValues.size () || index < 0) throw EBadSize (Name, IntValues.size (), index);
00082                 return (double)IntValues[index];
00083         case T_STRING:
00084                 if (index >= (int)StrValues.size () || index < 0) throw EBadSize (Name, StrValues.size (), index);
00085                 return atof(StrValues[index].c_str());
00086         default:
00087                 if (index >= (int)RealValues.size () || index < 0) throw EBadSize (Name, RealValues.size (), index);
00088                 return RealValues[index];
00089         }
00090 }

float NLMISC::CConfigFile::CVar::asFloat int  index = 0  )  const
 

Get the content of the variable as a float.

Definition at line 92 of file config_file.cpp.

References asDouble(), and index.

Referenced by NLLIGO::CLigoConfig::read().

00093 {
00094         return (float) asDouble (index);
00095 }

int NLMISC::CConfigFile::CVar::asInt int  index = 0  )  const
 

Get the content of the variable as an integer.

Definition at line 58 of file config_file.cpp.

References CheckType, index, IntValues, RealValues, StrValues, T_INT, T_REAL, and T_STRING.

Referenced by NLNET::cbSimVar(), NLNET::cfcbAcceptInvalidCookie(), NLNET::cfcbTimeBeforeEraseCookie(), NLNET::IService::main(), and NLLIGO::CLigoConfig::read().

00059 {
00060         if (CheckType && Type != T_INT) throw EBadType (Name, Type, T_INT);
00061         switch (Type)
00062         {
00063         case T_STRING:
00064                 if (index >= (int)StrValues.size () || index < 0) throw EBadSize (Name, StrValues.size (), index);
00065                 return atoi(StrValues[index].c_str());
00066         case T_REAL:
00067                 if (index >= (int)RealValues.size () || index < 0) throw EBadSize (Name, RealValues.size (), index);
00068                 return (int)RealValues[index];
00069         default:
00070                 if (index >= (int)IntValues.size () || index < 0) throw EBadSize (Name, IntValues.size (), index);
00071                 return IntValues[index];
00072         }
00073 }

std::string NLMISC::CConfigFile::CVar::asString int  index = 0  )  const
 

Get the content of the variable as a STL string.

Definition at line 97 of file config_file.cpp.

References CheckType, index, IntValues, RealValues, StrValues, T_INT, T_REAL, T_STRING, and NLMISC::toString().

Referenced by NLNET::cbExecuteCommands(), NLNET::cbLogFilter(), NLMISC::cbVarChanged(), NLNET::cfcbDefaultUserPriv(), NLNET::cfcbListenAddress(), NLMISC::IVariable::init(), NLNET::IService::main(), NLLIGO::CLigoConfig::read(), and NLMISC::CConfigFile::reparse().

00098 {
00099         if (CheckType && Type != T_STRING) throw EBadType (Name, Type, T_STRING);
00100         switch (Type)
00101         {
00102         case T_INT:
00103                 if (index >= (int)IntValues.size () || index < 0) throw EBadSize (Name, IntValues.size (), index);
00104                 return toString(IntValues[index]);
00105         case T_REAL:
00106                 if (index >= (int)RealValues.size () || index < 0) throw EBadSize (Name, RealValues.size (), index);
00107                 return toString(RealValues[index]);
00108         default:
00109                 if (index >= (int)StrValues.size () || index < 0) throw EBadSize (Name, StrValues.size (), index);
00110                 return StrValues[index];
00111         }
00112 }

bool NLMISC::CConfigFile::CVar::operator!= const CVar var  )  const
 

Definition at line 197 of file config_file.cpp.

00198 {
00199         return !(*this==var);
00200 }

bool NLMISC::CConfigFile::CVar::operator== const CVar var  )  const
 

Definition at line 182 of file config_file.cpp.

References IntValues, RealValues, StrValues, T_INT, T_REAL, T_STRING, and Type.

00183 {
00184         if (Type == var.Type)
00185         {
00186                 switch (Type)
00187                 {
00188                 case T_INT: return IntValues == var.IntValues; break;
00189                 case T_REAL: return RealValues == var.RealValues; break;
00190                 case T_STRING: return StrValues == var.StrValues; break;
00191                 default: break;
00192                 }
00193         }
00194         return false;
00195 }

void NLMISC::CConfigFile::CVar::setAsDouble std::vector< double >  vals  ) 
 

Set the content of the aray variable as a double.

Definition at line 155 of file config_file.cpp.

References RealValues, and T_REAL.

00156 {
00157         if (Type != T_REAL) throw EBadType (Name, Type, T_REAL);
00158         else RealValues = vals;
00159         Root = false;
00160 }

void NLMISC::CConfigFile::CVar::setAsDouble double  val,
int  index = 0
 

Set the content of the variable as a double.

Definition at line 125 of file config_file.cpp.

References index, RealValues, and T_REAL.

Referenced by setAsFloat().

00126 {
00127         if (Type != T_REAL) throw EBadType (Name, Type, T_REAL);
00128         else if (index > (int)RealValues.size () || index < 0) throw EBadSize (Name, RealValues.size (), index);
00129         else if (index == (int)RealValues.size ()) RealValues.push_back(val);
00130         else RealValues[index] = val;
00131         Root = false;
00132 }

void NLMISC::CConfigFile::CVar::setAsFloat std::vector< float >  vals  ) 
 

Set the content of the aray variable as a float.

Definition at line 162 of file config_file.cpp.

References RealValues, T_REAL, and uint.

00163 {
00164         if (Type != T_REAL) throw EBadType (Name, Type, T_REAL);
00165         else
00166         {
00167                 RealValues.clear ();
00168                 RealValues.resize (vals.size ());
00169                 for (uint i = 0; i < vals.size (); i++)
00170                         RealValues[i] = (double)vals[i];
00171         }
00172         Root = false;
00173 }

void NLMISC::CConfigFile::CVar::setAsFloat float  val,
int  index = 0
 

Set the content of the variable as a float.

Definition at line 134 of file config_file.cpp.

References index, and setAsDouble().

00135 {
00136         setAsDouble (val, index);
00137 }

void NLMISC::CConfigFile::CVar::setAsInt std::vector< int >  vals  ) 
 

Set the content of the aray variable as an integer.

Definition at line 148 of file config_file.cpp.

References IntValues, and T_INT.

00149 {
00150         if (Type != T_INT) throw EBadType (Name, Type, T_INT);
00151         else IntValues = vals;
00152         Root = false;
00153 }

void NLMISC::CConfigFile::CVar::setAsInt int  val,
int  index = 0
 

Set the content of the variable as an integer.

Definition at line 116 of file config_file.cpp.

References index, IntValues, and T_INT.

00117 {
00118         if (Type != T_INT) throw EBadType (Name, Type, T_INT);
00119         else if (index > (int)IntValues.size () || index < 0) throw EBadSize (Name, IntValues.size (), index);
00120         else if (index == (int)IntValues.size ()) IntValues.push_back(val);
00121         else IntValues[index] = val;
00122         Root = false;
00123 }

void NLMISC::CConfigFile::CVar::setAsString std::vector< std::string >  vals  ) 
 

Set the content of the aray variable as a string.

Definition at line 175 of file config_file.cpp.

References StrValues, and T_STRING.

00176 {
00177         if (Type != T_STRING) throw EBadType (Name, Type, T_STRING);
00178         else StrValues = vals;
00179         Root = false;
00180 }

void NLMISC::CConfigFile::CVar::setAsString std::string  val,
int  index = 0
 

Set the content of the variable as a STL string.

Definition at line 139 of file config_file.cpp.

References index, StrValues, and T_STRING.

00140 {
00141         if (Type != T_STRING) throw EBadType (Name, Type, T_STRING);
00142         else if (index > (int)StrValues.size () || index < 0) throw EBadSize (Name, StrValues.size (), index);
00143         else if (index == (int)StrValues.size ()) StrValues.push_back(val);
00144         else StrValues[index] = val;
00145         Root = false;
00146 }

int NLMISC::CConfigFile::CVar::size  )  const
 

Definition at line 216 of file config_file.cpp.

References IntValues, RealValues, StrValues, T_INT, T_REAL, and T_STRING.

Referenced by NLNET::cbExecuteCommands(), NLNET::cbLogFilter(), and NLNET::IService::main().

00217 {
00218         switch (Type)
00219         {
00220         case T_INT: return IntValues.size ();
00221         case T_REAL: return RealValues.size ();
00222         case T_STRING: return StrValues.size ();
00223         default: return 0;
00224         }
00225 }


Field Documentation

void(* NLMISC::CConfigFile::CVar::Callback)(CVar &var)
 

Referenced by NLMISC::CConfigFile::setCallback().

bool NLMISC::CConfigFile::CVar::Comp
 

Definition at line 191 of file config_file.h.

Referenced by NLMISC::CConfigFile::setCallback().

std::vector<int> NLMISC::CConfigFile::CVar::IntValues
 

Definition at line 192 of file config_file.h.

Referenced by add(), asDouble(), asInt(), asString(), operator==(), setAsInt(), and size().

std::string NLMISC::CConfigFile::CVar::Name
 

Definition at line 188 of file config_file.h.

Referenced by NLNET::cbLogFilter(), NLNET::cbSimVar(), NLMISC::cbVarChanged(), NLMISC::CConfigFile::insertVar(), and NLMISC::CConfigFile::setCallback().

std::vector<double> NLMISC::CConfigFile::CVar::RealValues
 

Definition at line 193 of file config_file.h.

Referenced by add(), asDouble(), asInt(), asString(), operator==(), setAsDouble(), setAsFloat(), and size().

bool NLMISC::CConfigFile::CVar::Root
 

Definition at line 190 of file config_file.h.

Referenced by NLMISC::CConfigFile::insertVar().

int NLMISC::CConfigFile::CVar::SaveWrap
 

Definition at line 196 of file config_file.h.

Referenced by CVar().

std::vector<std::string> NLMISC::CConfigFile::CVar::StrValues
 

Definition at line 194 of file config_file.h.

Referenced by add(), asDouble(), asInt(), asString(), operator==(), setAsString(), and size().

TVarType NLMISC::CConfigFile::CVar::Type
 

Definition at line 189 of file config_file.h.

Referenced by add(), operator==(), and NLMISC::CConfigFile::setCallback().

char * NLMISC::CConfigFile::CVar::TypeName = { "Integer", "String", "Float" } [static]
 

Definition at line 56 of file config_file.cpp.


The documentation for this struct was generated from the following files:
Generated on Tue Mar 16 13:06:59 2004 for NeL by doxygen 1.3.6