Changeset 6388 in orxonox.OLD for branches/preferences/src/lib/util/preferences.cc
- Timestamp:
- Jan 2, 2006, 11:09:42 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/preferences/src/lib/util/preferences.cc
r6383 r6388 28 28 this->setClassID(CL_PREFERENCES, "Preferences"); 29 29 this->setName("Preferences"); 30 this->fileName = NULL; 30 31 } 31 32 … … 41 42 { 42 43 Preferences::singletonRef = NULL; 44 45 if ( this->fileName ) 46 { 47 delete this->fileName; 48 this->fileName = NULL; 49 } 43 50 } 44 51 … … 78 85 * @param value value 79 86 */ 80 void Preferences::setString(const char* section, const char* name, const char* value) 81 { 82 setMultiType(section, name, MultiType(value)); 87 void Preferences::setString(const char* section, const char* name, const char* value, bool dontSetModified) 88 { 89 MultiType t(value); 90 setMultiType(section, name, t, dontSetModified); 83 91 } 84 92 … … 89 97 * @param value value 90 98 */ 91 void Preferences::setInt(const char* section, const char* name, int value) 92 { 93 setMultiType(section, name, MultiType(value)); 99 void Preferences::setInt(const char* section, const char* name, int value, bool dontSetModified) 100 { 101 MultiType t(value); 102 setMultiType(section, name, t, dontSetModified); 94 103 } 95 104 … … 100 109 * @param value value 101 110 */ 102 void Preferences::setFloat(const char* section, const char* name, float value) 103 { 104 setMultiType(section, name, MultiType(value)); 111 void Preferences::setFloat(const char* section, const char* name, float value, bool dontSetModified) 112 { 113 MultiType t(value); 114 setMultiType(section, name, t, dontSetModified); 105 115 } 106 116 … … 147 157 * @param value value 148 158 */ 149 void Preferences::setMultiType(const char* section, const char* name, const MultiType& value)159 void Preferences::setMultiType(const char* section, const char* name, MultiType& value, bool dontSetModified) 150 160 { 151 161 std::list<prefSection>::iterator it = data.begin(); … … 161 171 if ( strcmp(it2->name, name) == 0 ) 162 172 { 173 if (!dontSetModified) 174 it2->modified = strcmp(value.getString(), it2->value.getString())!=0; 175 163 176 it2->value = value; 177 164 178 return; 165 179 } … … 167 181 prefItem item; 168 182 item.value = value; 183 item.modified = !dontSetModified; 169 184 item.name = new char[strlen(name)+1]; 170 185 strcpy( item.name, name ); … … 176 191 prefItem item; 177 192 item.value = value; 193 item.modified = !dontSetModified; 178 194 item.name = new char[strlen(name)+1]; 179 195 strcpy( item.name, name ); … … 218 234 } 219 235 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); 245 } 246 247 bool Preferences::save() 248 { 249 if ( this->fileName == NULL ) 250 { 251 PRINTF(1)("You must call setUserIni before you can call save()\n"); 252 return false; 253 } 254 IniParser iniParser(this->fileName); 255 256 if ( !iniParser.isOpen() ) 257 return false; 258 259 std::list<prefSection>::iterator it = data.begin(); 260 bool didChanges = false; 261 for ( ; it!=data.end(); it++) 262 { 263 std::list<prefItem>::iterator it2 = it->items.begin(); 264 265 for ( ; it2!=it->items.end(); it2++) 266 { 267 if ( it2->modified ) 268 { 269 iniParser.editVar(it2->name, it2->value.getString(), it->sectionName); 270 didChanges = true; 271 } 272 } 273 } 274 275 if ( didChanges ) 276 { 277 iniParser.writeFile( this->fileName ); 278 } 279 280 return true; 281 } 282 220 283 /** 221 284 * prints out all section with its items and values … … 232 295 for ( ; it2!=it->items.end(); it2++) 233 296 { 234 PRINTF(0)("--> %s = '%s' \n", it2->name, it2->value.getString());235 } 236 } 237 } 238 239 297 PRINTF(0)("--> %s = '%s'%s\n", it2->name, it2->value.getString(), ((!it2->modified)?"":" <modified>")); 298 } 299 } 300 } 301 302
Note: See TracChangeset
for help on using the changeset viewer.