Changeset 5015 in orxonox.OLD for orxonox/trunk/src/lib/util
- Timestamp:
- Aug 14, 2005, 5:25:53 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/util/ini_parser.cc
r5014 r5015 23 23 #include "list.h" 24 24 #include "stdlibincl.h" 25 26 #include "resource_manager.h"27 25 #include "debug.h" 28 26 … … 53 51 } 54 52 53 /** 54 * removes all the sections. This is like delete, but even cooler :) 55 */ 55 56 void IniParser::deleteSections() 56 57 { … … 80 81 } 81 82 delete this->sections; 83 this->currentEntry = NULL; 84 this->currentSection = NULL; 82 85 this->sections = NULL; 83 86 } … … 88 91 * @return true on success false otherwise; 89 92 */ 90 bool IniParser::openFile(const char* file name)93 bool IniParser::openFile(const char* fileName) 91 94 { 92 95 FILE* stream; //!< The stream we use to read the file. 93 96 94 95 if( filename == NULL)96 return false;97 char* tmpName = ResourceManager::homeDirCheck(filename);98 97 99 98 if (sections != NULL) 100 99 deleteSections(); 101 102 if( (stream = fopen (tmpName, "r")) == NULL) 103 { 104 PRINTF(1)("IniParser could not open %s\n", filename); 105 delete tmpName; 100 if( fileName == NULL) 101 return false; 102 103 if( (stream = fopen (fileName, "r")) == NULL) 104 { 105 PRINTF(1)("IniParser could not open %s\n", fileName); 106 106 return false; 107 107 } … … 189 189 { 190 190 this->currentSection = sectionEnum; 191 this->currentEntry = NULL; 191 192 delete sectionIt; 192 193 return true; … … 200 201 201 202 /** 203 * moves to the first section 204 */ 205 void IniParser::getFirstSection() 206 { 207 if (this->sections) 208 this->currentSection = this->sections->firstElement(); 209 else 210 this->currentSection = NULL; 211 this->currentEntry = NULL; 212 } 213 214 /** 202 215 * searches the next section 203 216 * @returns the name of the section if found, NULL otherwise … … 210 223 { 211 224 if (this->sections) 212 this->currentSection = sections->nextElement(this->currentSection); 213 } 225 { 226 if (this->currentSection == this->sections->lastElement()) 227 this->currentSection = NULL; 228 else 229 this->currentSection = this->sections->nextElement(this->currentSection); 230 } 231 } 232 214 233 if (this->currentSection != NULL) 215 234 return this->currentSection->name; … … 219 238 220 239 /** 240 * moves to the first Variable of the current Section 241 */ 242 void IniParser::getFirstVar() 243 { 244 if (this->currentSection) 245 this->currentEntry = this->currentSection->entries->firstElement(); 246 else 247 this->currentEntry = NULL; 248 } 249 250 /** 221 251 * gets the next VarName=VarValue pair from the parsing stream 222 * @param name: a pointer to the Name of the next Var223 * @param value: a pointer to the Value of the next Var224 252 * @return true on success, false otherwise (in the latter case name and value will be NULL) 225 253 */ 226 254 bool IniParser::nextVar() 227 255 { 228 if (this->currentSection == NULL )229 return false;230 if(this->currentEntry == this->currentSection->entries->lastElement())256 if (this->currentSection == NULL 257 || this->currentEntry == NULL 258 || this->currentEntry == this->currentSection->entries->lastElement()) 231 259 { 232 260 this->currentEntry = NULL; 233 261 return false; 234 262 } 235 if (this->currentEntry == NULL) 236 this->currentEntry = this->currentSection->entries->firstElement(); 237 else 238 this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry); 263 this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry); 239 264 240 265 if (this->currentEntry == NULL) -
orxonox/trunk/src/lib/util/ini_parser.h
r5014 r5015 43 43 bool openFile(const char* name); 44 44 45 bool getSection( const char* sectionName); 45 bool getSection(const char* sectionName); 46 47 void getFirstSection(); 46 48 const char* nextSection(); 47 49 50 /** @returns true if the file is opened, false otherwise*/ 48 51 bool isOpen() const { return (sections != NULL)?true:false; }; 49 52 50 53 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 54 55 void getFirstVar(); 51 56 bool nextVar(); 52 57 53 const char* getCurrentName() const { return (currentEntry!=NULL)?currentEntry->name:NULL; }; 54 const char* getCurrentValue() const { return (currentEntry!=NULL)?currentEntry->value:NULL; }; 58 /** @returns the name of the Current selected Section */ 59 const char* getCurrentSection() const { return (this->currentSection!=NULL)?this->currentSection->name:NULL; }; 60 /** @returns the current entries Name, or NULL if we havn't selected a Entry */ 61 const char* getCurrentName() const { return (this->currentEntry!=NULL)?this->currentEntry->name:NULL; }; 62 /** @returns the current entries Value, or NULL if we havn't selected a Entry */ 63 const char* getCurrentValue() const { return (this->currentEntry!=NULL)?this->currentEntry->value:NULL; }; 55 64 56 65 void debug() const;
Note: See TracChangeset
for help on using the changeset viewer.