Changeset 7244 in orxonox.OLD for branches/preferences/src/lib
- Timestamp:
- Mar 24, 2006, 4:47:53 PM (19 years ago)
- Location:
- branches/preferences/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/preferences/src/lib/util/preferences.cc
r7243 r7244 28 28 this->setClassID(CL_PREFERENCES, "Preferences"); 29 29 this->setName("Preferences"); 30 this->fileName = NULL;30 this->fileName = ""; 31 31 } 32 32 … … 42 42 { 43 43 Preferences::singletonRef = NULL; 44 45 if ( this->fileName )46 {47 delete this->fileName;48 this->fileName = NULL;49 }50 44 } 51 45 … … 56 50 * @return true if the item exists 57 51 */ 58 bool Preferences::exists( const char* section, const char*name)52 bool Preferences::exists( const std::string& section, const std::string& name) 59 53 { 60 54 std::list<prefSection>::const_iterator it = data.begin(); … … 62 56 for ( ; it!=data.end(); it++) 63 57 { 64 if ( strcmp(it->sectionName, section) == 0)58 if ( it->sectionName == section ) 65 59 { 66 60 std::list<prefItem>::const_iterator it2 = it->items.begin(); … … 68 62 for ( ; it2!=it->items.end(); it2++) 69 63 { 70 if ( strcmp(it2->name, name) == 0)64 if ( it2->name == name ) 71 65 return true; 72 66 } … … 85 79 * @param value value 86 80 */ 87 void Preferences::setString(const char* section, const char* name, const char*value, bool dontSetModified)81 void Preferences::setString(const std::string& section, const std::string& name, const std::string& value, bool dontSetModified) 88 82 { 89 83 MultiType t(value); … … 97 91 * @param value value 98 92 */ 99 void Preferences::setInt(const char* section, const char*name, int value, bool dontSetModified)93 void Preferences::setInt(const std::string& section, const std::string& name, int value, bool dontSetModified) 100 94 { 101 95 MultiType t(value); … … 109 103 * @param value value 110 104 */ 111 void Preferences::setFloat(const char* section, const char*name, float value, bool dontSetModified)105 void Preferences::setFloat(const std::string& section, const std::string& name, float value, bool dontSetModified) 112 106 { 113 107 MultiType t(value); … … 122 116 * @return value of the item if found. defaultValue else 123 117 */ 124 const char* Preferences::getString(const char* section, const char* name, const char*defaultValue)118 const std::string Preferences::getString(const std::string& section, const std::string& name, const std::string& defaultValue) 125 119 { 126 120 return getMultiType(section, name, MultiType(defaultValue)).getString(); … … 134 128 * @return value of the item if found. defaultValue else 135 129 */ 136 int Preferences::getInt(const char* section, const char*name, int defaultValue)130 int Preferences::getInt(const std::string& section, const std::string& name, int defaultValue) 137 131 { 138 132 return getMultiType(section, name, MultiType(defaultValue)).getInt(); … … 146 140 * @return value of the item if found. defaultValue else 147 141 */ 148 float Preferences::getFloat(const char* section, const char*name, float defaultValue)142 float Preferences::getFloat(const std::string& section, const std::string& name, float defaultValue) 149 143 { 150 144 return getMultiType(section, name, MultiType(defaultValue)).getFloat(); … … 157 151 * @param value value 158 152 */ 159 void Preferences::setMultiType(const char* section, const char*name, const MultiType& value, bool dontSetModified)153 void Preferences::setMultiType(const std::string& section, const std::string& name, const MultiType& value, bool dontSetModified) 160 154 { 161 155 std::list<prefSection>::iterator it = data.begin(); … … 163 157 for ( ; it!=data.end(); it++) 164 158 { 165 if ( strcmp(it->sectionName, section) == 0)159 if ( it->sectionName == section ) 166 160 { 167 161 std::list<prefItem>::iterator it2 = it->items.begin(); … … 169 163 for ( ; it2!=it->items.end(); it2++) 170 164 { 171 if ( strcmp(it2->name, name) == 0)165 if ( it2->name == name ) 172 166 { 173 167 if (!dontSetModified) 174 it2->modified = strcmp(value.getString(), it2->value.getString())!=0;168 it2->modified = value.getString() != it2->value.getString(); 175 169 176 170 it2->value = value; … … 182 176 item.value = value; 183 177 item.modified = !dontSetModified; 184 item.name = new char[strlen(name)+1]; 185 strcpy( item.name, name ); 178 item.name = name; 186 179 it->items.push_back(item); 187 180 return; … … 192 185 item.value = value; 193 186 item.modified = !dontSetModified; 194 item.name = new char[strlen(name)+1]; 195 strcpy( item.name, name ); 187 item.name = name; 196 188 197 189 prefSection sec; 198 190 sec.items.push_back(item); 199 sec.sectionName = new char[strlen(section)+1]; 200 strcpy( sec.sectionName, section ); 191 sec.sectionName = section; 201 192 data.push_back( sec ); 202 193 } … … 209 200 * @return value of the item if found. defaultValue else 210 201 */ 211 MultiType Preferences::getMultiType(const char* section, const char*name,const MultiType& defaultValue)202 MultiType Preferences::getMultiType(const std::string& section, const std::string& name,const MultiType& defaultValue) 212 203 { 213 204 std::list<prefSection>::const_iterator it = data.begin(); … … 215 206 for ( ; it!=data.end(); it++) 216 207 { 217 if ( strcmp(it->sectionName, section) == 0)208 if ( it->sectionName == section ) 218 209 { 219 210 std::list<prefItem>::const_iterator it2 = it->items.begin(); … … 221 212 for ( ; it2!=it->items.end(); it2++) 222 213 { 223 if ( strcmp(it2->name, name) == 0)214 if ( it2->name == name ) 224 215 { 225 216 return it2->value; … … 234 225 } 235 226 236 void Preferences::setUserIni(const char* fileName) 237 { 238 if ( this->fileName != NULL ) 239 { 240 delete this->fileName; 241 } 242 243 this->fileName = new char[strlen(fileName)+1]; 244 strcpy(this->fileName, fileName); 227 void Preferences::setUserIni(const std::string& fileName) 228 { 229 this->fileName = fileName; 245 230 } 246 231 247 232 bool Preferences::save() 248 233 { 249 if ( this->fileName == NULL)234 if ( this->fileName == "" ) 250 235 { 251 236 PRINTF(1)("You must call setUserIni before you can call save()\n"); … … 290 275 for ( ; it!=data.end(); it++) 291 276 { 292 PRINTF(0)("%s\n", it->sectionName );277 PRINTF(0)("%s\n", it->sectionName.c_str()); 293 278 std::list<prefItem>::iterator it2 = it->items.begin(); 294 279 295 280 for ( ; it2!=it->items.end(); it2++) 296 281 { 297 PRINTF(0)("--> %s = '%s'%s\n", it2->name , it2->value.getString(), ((!it2->modified)?"":" <modified>"));298 } 299 } 300 } 301 302 282 PRINTF(0)("--> %s = '%s'%s\n", it2->name.c_str(), it2->value.getString().c_str(), ((!it2->modified)?"":" <modified>")); 283 } 284 } 285 } 286 287 -
branches/preferences/src/lib/util/preferences.h
r7243 r7244 64 64 std::list<IniFilePrefsReader*> iniFilePrefsReaders; 65 65 66 std::string &fileName;66 std::string fileName; 67 67 68 68 };
Note: See TracChangeset
for help on using the changeset viewer.