Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7244 in orxonox.OLD for branches/preferences/src/lib/util


Ignore:
Timestamp:
Mar 24, 2006, 4:47:53 PM (18 years ago)
Author:
rennerc
Message:

preferences.cc compiles again

Location:
branches/preferences/src/lib/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/preferences/src/lib/util/preferences.cc

    r7243 r7244  
    2828   this->setClassID(CL_PREFERENCES, "Preferences");
    2929   this->setName("Preferences");
    30    this->fileName = NULL;
     30   this->fileName = "";
    3131}
    3232
     
    4242{
    4343  Preferences::singletonRef = NULL;
    44 
    45   if ( this->fileName )
    46   {
    47     delete this->fileName;
    48     this->fileName = NULL;
    49   }
    5044}
    5145
     
    5650 * @return true if the item exists
    5751 */
    58 bool Preferences::exists(const char* section, const char* name)
     52bool Preferences::exists( const std::string& section, const std::string& name)
    5953{
    6054  std::list<prefSection>::const_iterator it = data.begin();
     
    6256  for ( ; it!=data.end(); it++)
    6357  {
    64     if ( strcmp(it->sectionName, section) == 0 )
     58    if ( it->sectionName == section )
    6559    {
    6660      std::list<prefItem>::const_iterator it2 = it->items.begin();
     
    6862      for ( ; it2!=it->items.end(); it2++)
    6963      {
    70         if ( strcmp(it2->name, name) == 0 )
     64        if ( it2->name == name )
    7165          return true;
    7266      }
     
    8579 * @param value value
    8680 */
    87 void Preferences::setString(const char* section, const char* name, const char* value, bool dontSetModified)
     81void Preferences::setString(const std::string& section, const std::string& name, const std::string& value, bool dontSetModified)
    8882{
    8983  MultiType t(value);
     
    9791 * @param value value
    9892 */
    99 void Preferences::setInt(const char* section, const char* name, int value, bool dontSetModified)
     93void Preferences::setInt(const std::string& section, const std::string& name, int value, bool dontSetModified)
    10094{
    10195  MultiType t(value);
     
    109103 * @param value value
    110104 */
    111 void Preferences::setFloat(const char* section, const char* name, float value, bool dontSetModified)
     105void Preferences::setFloat(const std::string& section, const std::string& name, float value, bool dontSetModified)
    112106{
    113107  MultiType t(value);
     
    122116 * @return value of the item if found. defaultValue else
    123117 */
    124 const char* Preferences::getString(const char* section, const char* name, const char* defaultValue)
     118const std::string Preferences::getString(const std::string& section, const std::string& name, const std::string& defaultValue)
    125119{
    126120  return getMultiType(section, name, MultiType(defaultValue)).getString();
     
    134128 * @return value of the item if found. defaultValue else
    135129 */
    136 int Preferences::getInt(const char* section, const char* name, int defaultValue)
     130int Preferences::getInt(const std::string& section, const std::string& name, int defaultValue)
    137131{
    138132  return getMultiType(section, name, MultiType(defaultValue)).getInt();
     
    146140 * @return value of the item if found. defaultValue else
    147141 */
    148 float Preferences::getFloat(const char* section, const char* name, float defaultValue)
     142float Preferences::getFloat(const std::string& section, const std::string& name, float defaultValue)
    149143{
    150144  return getMultiType(section, name, MultiType(defaultValue)).getFloat();
     
    157151 * @param value value
    158152 */
    159 void Preferences::setMultiType(const char* section, const char* name, const MultiType& value, bool dontSetModified)
     153void Preferences::setMultiType(const std::string& section, const std::string& name, const MultiType& value, bool dontSetModified)
    160154{
    161155  std::list<prefSection>::iterator it = data.begin();
     
    163157  for ( ; it!=data.end(); it++)
    164158  {
    165     if ( strcmp(it->sectionName, section) == 0 )
     159    if ( it->sectionName == section )
    166160    {
    167161      std::list<prefItem>::iterator it2 = it->items.begin();
     
    169163      for ( ; it2!=it->items.end(); it2++)
    170164      {
    171         if ( strcmp(it2->name, name) == 0 )
     165        if ( it2->name == name )
    172166        {
    173167          if (!dontSetModified)
    174             it2->modified = strcmp(value.getString(), it2->value.getString())!=0;
     168            it2->modified = value.getString() != it2->value.getString();
    175169
    176170          it2->value = value;
     
    182176      item.value = value;
    183177      item.modified = !dontSetModified;
    184       item.name = new char[strlen(name)+1];
    185       strcpy( item.name, name );
     178      item.name = name;
    186179      it->items.push_back(item);
    187180      return;
     
    192185  item.value = value;
    193186  item.modified = !dontSetModified;
    194   item.name = new char[strlen(name)+1];
    195   strcpy( item.name, name );
     187  item.name = name;
    196188
    197189  prefSection sec;
    198190  sec.items.push_back(item);
    199   sec.sectionName = new char[strlen(section)+1];
    200   strcpy( sec.sectionName, section );
     191  sec.sectionName = section;
    201192  data.push_back( sec );
    202193}
     
    209200 * @return value of the item if found. defaultValue else
    210201 */
    211 MultiType Preferences::getMultiType(const char* section, const char* name,const MultiType& defaultValue)
     202MultiType Preferences::getMultiType(const std::string& section, const std::string& name,const MultiType& defaultValue)
    212203{
    213204  std::list<prefSection>::const_iterator it = data.begin();
     
    215206  for ( ; it!=data.end(); it++)
    216207  {
    217     if ( strcmp(it->sectionName, section) == 0 )
     208    if ( it->sectionName == section )
    218209    {
    219210      std::list<prefItem>::const_iterator it2 = it->items.begin();
     
    221212      for ( ; it2!=it->items.end(); it2++)
    222213      {
    223         if ( strcmp(it2->name, name) == 0 )
     214        if ( it2->name == name )
    224215        {
    225216          return it2->value;
     
    234225}
    235226
    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);
     227void Preferences::setUserIni(const std::string& fileName)
     228{
     229  this->fileName = fileName;
    245230}
    246231
    247232bool Preferences::save()
    248233{
    249   if ( this->fileName == NULL )
     234  if ( this->fileName == "" )
    250235  {
    251236    PRINTF(1)("You must call setUserIni before you can call save()\n");
     
    290275  for ( ; it!=data.end(); it++)
    291276  {
    292     PRINTF(0)("%s\n", it->sectionName);
     277    PRINTF(0)("%s\n", it->sectionName.c_str());
    293278    std::list<prefItem>::iterator it2 = it->items.begin();
    294279
    295280    for ( ; it2!=it->items.end(); it2++)
    296281    {
    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  
    6464   std::list<IniFilePrefsReader*> iniFilePrefsReaders;
    6565
    66    std::string& fileName;
     66   std::string fileName;
    6767
    6868};
Note: See TracChangeset for help on using the changeset viewer.