Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 29, 2009, 10:30:19 PM (15 years ago)
Author:
rgrieder
Message:

Changed the way config values associated with general settings (ConfigFileType::Settings) are handled:

  • ConfigFileManager only handles config files listed in the ConfigFileType enum (normal enum again)
  • ConfigFileManager only takes care of ConfigFiles and returns a pointer to the right one, just two functions left. —> use like: ConfigFileManager::getInstance().getConfigFile(myType)→doSomething();
  • Moved all code (except for the argument completion functions) relating to ConfigFileType::Settings to a new class: SettingsConfigFile, which is a Singleton (it doesn't make sense to have multiple instances unless you start coding a lot more)
  • SettingsConfigFile handles config value containers according to their section and entry in the ini file, not according to class and variables names. (In most cases it will be class and variable names though)
  • SettingsConfigFile supports:
    • clear() (removes any file entries not associated to a config value container)
    • updateConfigValues() (does exactly that through the identifier)
    • config, tconfig and getConfig
    • commands listed above are exported to tolua, and tconfig, config and getConfig were given shortcuts in Lua (e.g. orxonox.config)
  • If you need to organise ConfigFiles yourself, just do it without the ConfigFileManager, like the KeyBinder does.
  • All getValue() functions have been split into getOrCreateValue() and getValue(), which is const
  • Removed obsolete config value management code in the Identifier (it still stores and destroys them and provides access to them)

All of that leads to one HUGE advantage:
"config OutputHandler softDebugLevelInGameConsole"
works now :D (any further implications are up to the reader…)
(it didn't work before because the actual config value container is in the InGameConsole singleton)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestate/src/libraries/core/ConfigValueContainer.cc

    r5738 r6432  
    3636#include "util/Convert.h"
    3737#include "util/SubString.h"
     38#include "ConfigFileManager.h"
    3839#include "Language.h"
    3940
     
    4344
    4445    /**
    45         @brief Initializes the ConfigValueContainer with defaultvalues.
    46     */
    47     void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname)
     46        @brief Initializes the ConfigValueContainer with default values.
     47    */
     48    void ConfigValueContainer::init(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname)
    4849    {
    4950        this->type_ = type;
     
    5556        this->bDoInitialCallback_ = false;
    5657        this->bAddedDescription_ = false;
     58
     59        // Register containers for general settings
     60        if (this->type_ == ConfigFileType::Settings)
     61            SettingsConfigFile::getInstance().addConfigValueContainer(this);
    5762    }
    5863
     
    7883        for (unsigned int i = 0; i < this->valueVector_.size(); i++)
    7984        {
    80             ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
     85            ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
    8186            this->defvalueStringVector_.push_back(this->valueVector_[i]);
    8287        }
     
    9297        if (this->callback_)
    9398            delete this->callback_;
     99
     100        // Unregister general settings containers
     101        if (this->type_ == ConfigFileType::Settings && SettingsConfigFile::exists())
     102            SettingsConfigFile::getInstance().removeConfigValueContainer(this);
    94103    }
    95104
     
    109118            if (this->tset(input))
    110119            {
    111                 ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isType(MT_Type::String));
     120                ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, input, this->value_.isType(MT_Type::String));
    112121                return true;
    113122            }
     
    128137            if (this->tset(index, input))
    129138            {
    130                 ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isType(MT_Type::String));
     139                ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, index, input, this->value_.isType(MT_Type::String));
    131140                return true;
    132141            }
     
    228237                this->valueVector_.erase(this->valueVector_.begin() + index);
    229238                for (unsigned int i = index; i < this->valueVector_.size(); i++)
    230                     ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
    231                 ConfigFileManager::getInstance().deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
     239                    ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
     240                ConfigFileManager::getInstance().getConfigFile(this->type_)->deleteVectorEntries(this->sectionname_, this->varname_, this->valueVector_.size());
    232241
    233242                return true;
     
    253262                if (!this->set(i, this->defvalueStringVector_[i]))
    254263                    success = false;
    255             ConfigFileManager::getInstance().deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size());
     264            ConfigFileManager::getInstance().getConfigFile(this->type_)->deleteVectorEntries(this->sectionname_, this->varname_, this->defvalueStringVector_.size());
    256265            return success;
    257266        }
     
    264273    {
    265274        if (!this->bIsVector_)
    266             this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_Type::String));
     275            this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_Type::String));
    267276        else
    268277        {
    269278            this->valueVector_.clear();
    270             unsigned int vectorSize = ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_);
     279            unsigned int vectorSize = ConfigFileManager::getInstance().getConfigFile(this->type_)->getVectorSize(this->sectionname_, this->varname_);
    271280            for (unsigned int i = 0; i < vectorSize; i++)
    272281            {
    273282                if (i < this->defvalueStringVector_.size())
    274283                {
    275                     this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_Type::String));
     284                    this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_Type::String));
    276285                }
    277286                else
    278287                {
    279                     this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_Type::String));
     288                    this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_Type::String));
    280289                }
    281290
Note: See TracChangeset for help on using the changeset viewer.