#include <CfgHandler.h>
Public Member Functions | |
| Handler (const string &aFile="") | |
| virtual | ~Handler (void) |
| unsigned long | GetSize (void) const |
| the amoun of element in the cfg file. | |
| const string & | GetFilename (void) const |
| the filename of the cf file. | |
| const string & | GetPath (void) const |
| the path of the cf file. | |
| void | SetData (const string &aData) |
| Assigns a data pool of the format of a cfg file for fast retrieval. | |
| void | Flush (const string &aFilename="") |
| Writes the cfg file if altered otherwise does nothing. | |
| int | GetCfgInt (const string &aSection, const string &aId, const int aDefaultValue=0) |
| int | GetCfgHex (const string &aSection, const string &aId, const int aDefaultValue=0) |
| double | GetCfgDbl (const string &aSection, const string &aId, const double aDefaultValue=0.0) |
| vector< double > & | GetCfgDbl (const string &aSection, const string &aId, vector< double > &ans) |
| string | GetCfgString (const string &aSection, const string &aId, const string &aDefaultValue="") |
| string | GetCfgFile (const string &aSection, const string &aId, const string &aDefaultValue="") |
| Ars::RGBColor | GetCfgColorHex (const string &aSection, const string &aId, const Ars::RGBColor c) |
| void | SetCfgInt (const string &aSection, const string &aId, const int aValue) |
| void | SetCfgHex (const string &aSection, const string &aId, const int aValue) |
| void | SetCfgDbl (const string &aSection, const string &aId, const double aValue) |
| void | SetCfgString (const string &aSection, const string &aId, const string &aValue) |
| void | SetCfgFile (const string &aSection, const string &aId, const string &aValue) |
| void | SetCfgColorHex (const string &aSection, const string &aId, const Ars::RGBColor c) |
| const bool | IsTheFile (const char *aFile) const |
| const bool | operator== (const Handler &h) const |
Protected Member Functions | |
| string | GetCdr (const icstring &aSection, const string &aId) |
| map< icstring, vector< string > >::iterator | AddLine (map< icstring, vector< string > >::iterator pos, const string &aline) |
Private Attributes | |
| string | CfgFile |
| string | cfgPath |
| file name and path name of the cfg file. | |
| map< icstring, vector< string > > | vList |
| for each section maps the key value | |
| bool | dirty |
| set to true when an element has been altered | |
| unsigned long | cnt |
|
|
Definition at line 59 of file CfgHandler.cpp. References AddLine(), CfgFile, cfgPath, icstring, and vList.
00060 : CfgFile( aFile ) , dirty( false ) , cnt( 0 ) 00061 { 00062 string::size_type n = CfgFile.rfind( '\\' ); 00063 if( n == string::npos ) 00064 n = CfgFile.rfind( '/' ); 00065 if( n == string::npos ) 00066 cfgPath = "./"; 00067 else 00068 cfgPath = CfgFile.substr( 0 , n + 1 ); 00069 00070 ifstream ifd( CfgFile.c_str() ); 00071 00072 vector<string> e; 00073 vList.insert( make_pair( icstring( "" ) , e ) ); 00074 map<icstring, vector<string> >::iterator pos = vList.find( "" ); 00075 00076 while( !ifd.fail() ) 00077 { 00078 char buffer[4096] = ""; 00079 ifd.getline( buffer , sizeof buffer ); 00080 pos = AddLine( pos , buffer ); 00081 if( ifd.eof() ) 00082 break; 00083 00084 } 00085 } |
|
|
Definition at line 87 of file CfgHandler.cpp. References vList.
|
|
||||||||||||
|
Definition at line 94 of file CfgHandler.cpp. References cnt, icstring, Ars::strip(), and vList. Referenced by Handler(), SetCfgColorHex(), SetCfgDbl(), SetCfgFile(), SetCfgHex(), SetCfgInt(), SetCfgString(), and SetData().
00095 {
00096 // If this is a section... [...]
00097 // Creates a new section or returns the section iterator.
00098 if( aline[0] == '[' )
00099 {
00100 string::size_type at = aline.find( ']' );
00101 if( at != string::npos )
00102 {
00103 icstring ics = aline.substr( 1 , at - 1 ).c_str();
00104 map<icstring, vector<string> >::iterator pos2 = vList.find( ics );
00105 if( pos2 == vList.end() )
00106 {
00107 vector<string> e;
00108 icstring ics = aline.substr( 1 , at - 1 ).c_str();
00109 return vList.insert( make_pair( ics , e ) ).first;
00110 }
00111 return pos2;
00112 }
00113 }
00114
00115 // We have to add a pair car = crd - otherwise this is considered as a comment...
00116 if( aline.find( "=" ) != string::npos && aline[0] != '#' && aline.substr( 0 , 2 ) != "//" )
00117 {
00118 icstring tmp = aline.substr( 0 , aline.find( '=' ) ).c_str();
00119 icstring s = Ars::strip( tmp );
00120 for( vector<string>::iterator at = pos->second.begin() ; at != pos->second.end() ; ++at )
00121 {
00122 tmp = at->substr( 0 , at->find( '=' ) ).c_str();
00123 icstring ics = Ars::strip( tmp );
00124 if( s == ics )
00125 {
00126 *at = aline;
00127 return pos;
00128 }
00129 }
00130 cnt += 1;
00131 }
00132
00133 pos->second.push_back( aline );
00134 return pos;
00135 }
|
|
|
Writes the cfg file if altered otherwise does nothing.
Definition at line 156 of file CfgHandler.cpp. References CfgFile, dirty, and vList. Referenced by Ars::ArsApplication::GenDefaultCfg(), Borqueror::GenDefaultCfg(), and Parameters::MainLoop().
00157 {
00158 if( !aFilename.empty() || dirty )
00159 {
00160 ofstream of( (aFilename.empty() ? CfgFile.c_str() : aFilename.c_str()) , ios::out );
00161 for( map<icstring,vector<string> >::iterator it = vList.begin() ; it != vList.end() ; ++it )
00162 {
00163 if( !it->first.empty() )
00164 of << "[" << it->first.c_str() << "]" << endl;
00165 copy( it->second.begin() , it->second.end() , ostream_iterator<string>( of , "\n" ) );
00166 }
00167 }
00168 dirty = false;
00169 }
|
|
||||||||||||
|
Definition at line 171 of file CfgHandler.cpp. References icstring, Ars::strip(), and vList. Referenced by GetCfgDbl(), GetCfgFile(), GetCfgHex(), GetCfgInt(), and GetCfgString().
00172 {
00173 map<icstring, vector<string> >::iterator pos = vList.find( aSection );
00174 if( pos != vList.end() )
00175 {
00176 for( vector<string>::iterator at = pos->second.begin() ; at != pos->second.end() ; ++at )
00177 {
00178 string::size_type n;
00179 if( (n = at->find( '=' )) != string::npos )
00180 {
00181 icstring tmp = at->substr( 0 , n ).c_str();
00182 icstring ics = Ars::strip( tmp );
00183 if( ics == icstring( aId.c_str() ) )
00184 return at->substr( at->find_first_not_of( ' ' , n + 1 ) );
00185
00186 }
00187 }
00188 }
00189 return string( "" );
00190 }
|
|
||||||||||||||||
|
Definition at line 216 of file CfgHandler.cpp. References Ars::RGBColor::alpha, Ars::RGBColor::blue, GetCfgInt(), Ars::RGBColor::green, and Ars::RGBColor::red. Referenced by Ars::ArsApplication::Init(), and Ars::Thing::Thing().
00217 {
00218 unsigned long int c = GetCfgInt( aSection , aId , (col.red << 16) + (col.green << 8) + col.blue + (col.alpha << 24) );
00219 return Ars::RGBColor( (unsigned char)( (c >> 16) & 0xff ) , (unsigned char)( (c >> 8) & 0xff ) , (unsigned char)( c & 0xff ) , (unsigned char)( c & 0xff000000 ? (c >> 24) & 0xff : 0xff ) );
00220 }
|
|
||||||||||||||||
|
Definition at line 233 of file CfgHandler.cpp. References GetCdr(), and icstring.
00234 {
00235 string s = GetCdr( icstring( aSection.c_str() ) , aId );
00236
00237 while( !s.empty() )
00238 {
00239 double val = 0.0;
00240 sscanf( s.c_str() , "%lf" , &val );
00241 ans.push_back( val );
00242 size_t n = s.find_first_of( " \t\n" );
00243 if( n != string::npos )
00244 if( (n = s.find_first_not_of( " \t\n" , n )) != string::npos )
00245 s = s.substr( n );
00246 else
00247 break;
00248 else
00249 break;
00250 }
00251 return ans;
00252 }
|
|
||||||||||||||||
|
Definition at line 222 of file CfgHandler.cpp. References GetCdr(), and icstring.
|
|
||||||||||||||||
|
Definition at line 261 of file CfgHandler.cpp. References cfgPath, GetCdr(), and icstring. Referenced by Cfg::GetCfg(), Ars::ArsApplication::Init(), Ars::Painter::Init(), Ars::Sounds::Load(), Ars::Graf::LoadImg(), MainGame::PlayIntro(), Cfg::Push(), Ars::XScrollBar::SetupWindow(), and Ars::XMPEG::SetupWindow().
|
|
||||||||||||||||
|
Definition at line 205 of file CfgHandler.cpp. References GetCdr(), and icstring.
|
|
||||||||||||||||
|
Definition at line 192 of file CfgHandler.cpp. References GetCdr(), and icstring. Referenced by Parameters::CreateGalaxy(), GetCfgColorHex(), Ars::ExprIntParser::Init(), Ars::ExprParser::Context::Init(), Borqueror::Init(), Parameters::InitDialog(), Galaxy::Load(), InitGalaxyScreen::Run(), GalaxyScreen::SetupWindow(), and Ars::View::View().
00193 {
00194 string s = GetCdr( icstring( aSection.c_str() ) , aId );
00195
00196 int val = aDefaultValue;
00197 if( s.substr( 0 , 2 ) == "0x" || s.substr( 0 , 2 ) == "0X" )
00198 sscanf( s.substr( 2 ).c_str() , "%x" , &val );
00199 else if( !s.empty() )
00200 sscanf( s.c_str() , "%d" , &val );
00201
00202 return val;
00203 }
|
|
||||||||||||||||
|
Definition at line 254 of file CfgHandler.cpp. References GetCdr(), and icstring. Referenced by Parameters::CreateGalaxy(), MainGame::EnableWindow(), Galaxy::evMessage(), Ars::ArsApplication::Init(), Borqueror::Init(), Ars::Painter::Init(), Parameters::MainLoop(), and HallOfFame::SetupWindow().
|
|
|
the filename of the cf file.
Definition at line 33 of file CfgHandler.h. References CfgFile. Referenced by MainGame::EnableWindow(), and Cfg::Pop().
00033 { return CfgFile; }
|
|
|
the path of the cf file.
Definition at line 36 of file CfgHandler.h. References cfgPath. Referenced by Ars::Preload().
00036 { return cfgPath; }
|
|
|
the amoun of element in the cfg file.
Definition at line 30 of file CfgHandler.h. References cnt.
00030 { return cnt; }
|
|
|
Definition at line 59 of file CfgHandler.h. References CfgFile. Referenced by operator==().
00059 { return CfgFile == aFile; }
|
|
|
Definition at line 60 of file CfgHandler.h. References CfgFile, and IsTheFile().
00060 { return h.IsTheFile( CfgFile.c_str() ); }
|
|
||||||||||||||||
|
Definition at line 308 of file CfgHandler.cpp. References AddLine(), Ars::RGBColor::alpha, Ars::RGBColor::blue, dirty, Ars::RGBColor::green, Ars::RGBColor::red, and vList. Referenced by Ars::ArsApplication::GenDefaultCfg(), and Borqueror::GenDefaultCfg().
|
|
||||||||||||||||
|
Definition at line 284 of file CfgHandler.cpp. References AddLine(), dirty, and vList.
|
|
||||||||||||||||
|
Definition at line 298 of file CfgHandler.cpp. References AddLine(), cfgPath, dirty, and vList. Referenced by Ars::ArsApplication::GenDefaultCfg(), and Borqueror::GenDefaultCfg().
|
|
||||||||||||||||
|
Definition at line 276 of file CfgHandler.cpp. References AddLine(), dirty, and vList.
|
|
||||||||||||||||
|
Definition at line 268 of file CfgHandler.cpp. References AddLine(), dirty, and vList. Referenced by Borqueror::GenDefaultCfg(), and Parameters::MainLoop().
|
|
||||||||||||||||
|
Definition at line 292 of file CfgHandler.cpp. References AddLine(), dirty, and vList. Referenced by Borqueror::GenDefaultCfg(), and Parameters::MainLoop().
|
|
|
Assigns a data pool of the format of a cfg file for fast retrieval.
Definition at line 137 of file CfgHandler.cpp. References AddLine(), cnt, dirty, icstring, and vList.
00138 {
00139 dirty = false;
00140 vList.clear();
00141 string::size_type n0 = 0 , n1 = aData.find( "\n" , n0 );
00142 cnt = 0;
00143
00144 vector<string> e;
00145 vList.insert( make_pair( icstring( "" ) , e ) );
00146 map<icstring, vector<string> >::iterator pos = vList.find( "" );
00147
00148 while( n1 != string::npos )
00149 {
00150 pos = AddLine( pos , string( aData.substr( n0 , n1 - n0 ) ) );
00151 n0 = n1 + 1;
00152 n1 = aData.find( "\n" , n0 );
00153 }
00154 }
|
|
|
Definition at line 11 of file CfgHandler.h. Referenced by Flush(), GetFilename(), Handler(), IsTheFile(), and operator==(). |
|
|
file name and path name of the cfg file.
Definition at line 11 of file CfgHandler.h. Referenced by GetCfgFile(), GetPath(), Handler(), and SetCfgFile(). |
|
|
Definition at line 16 of file CfgHandler.h. |
|
|
set to true when an element has been altered
Definition at line 15 of file CfgHandler.h. Referenced by Flush(), SetCfgColorHex(), SetCfgDbl(), SetCfgFile(), SetCfgHex(), SetCfgInt(), SetCfgString(), and SetData(). |
|
|
for each section maps the key value
Definition at line 13 of file CfgHandler.h. Referenced by AddLine(), Flush(), GetCdr(), Handler(), SetCfgColorHex(), SetCfgDbl(), SetCfgFile(), SetCfgHex(), SetCfgInt(), SetCfgString(), SetData(), and ~Handler(). |
1.3.3