Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 29, 2009, 10:30:19 PM (14 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/ArgumentCompletionFunctions.cc

    r6417 r6432  
    3636#include "util/StringUtils.h"
    3737#include "Identifier.h"
     38#include "ConfigFileManager.h"
    3839#include "ConfigValueContainer.h"
    3940#include "TclThreadManager.h"
     
    9697        }
    9798
    98         ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)()
     99        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)()
    99100        {
    100             ArgumentCompletionList classlist;
     101            ArgumentCompletionList sectionList;
    101102
    102             for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)
    103                 if (it->second->hasConfigValues())
    104                     classlist.push_back(ArgumentCompletionListElement(it->first, getLowercase(it->first)));
     103            const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames();
     104            for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
     105                sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it)));
    105106
    106             return classlist;
     107            return sectionList;
    107108        }
    108109
    109         ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname)
     110        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section)
    110111        {
    111             ArgumentCompletionList configvalues;
    112             std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
     112            ArgumentCompletionList entryList;
     113            SettingsConfigFile& settings = SettingsConfigFile::getInstance();
     114            const std::string& sectionLC = getLowercase(section);
    113115
    114             if (identifier != Identifier::getLowercaseStringIdentifierMapEnd() && identifier->second->hasConfigValues())
     116            SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
     117            for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
     118                entryList.push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first));
     119
     120            return entryList;
     121        }
     122
     123        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section)
     124        {
     125            ArgumentCompletionList oldValue;
     126            SettingsConfigFile& settings = SettingsConfigFile::getInstance();
     127            const std::string& sectionLC = getLowercase(section);
     128            const std::string& entryLC = getLowercase(entry);
     129
     130            SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
     131            for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
    115132            {
    116                 for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->second->getConfigValueMapBegin(); it != identifier->second->getConfigValueMapEnd(); ++it)
    117                     configvalues.push_back(ArgumentCompletionListElement(it->first, getLowercase(it->first)));
     133                if (it->second.first == entryLC)
     134                {
     135                    const std::string& valuestring = it->second.second->toString();
     136                    oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
     137                }
    118138            }
    119139
    120             return configvalues;
    121         }
    122 
    123         ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname)
    124         {
    125             ArgumentCompletionList oldvalue;
    126             std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
    127             if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
    128             {
    129                 std::map<std::string, ConfigValueContainer*>::const_iterator variable = identifier->second->getLowercaseConfigValueMap().find(getLowercase(varname));
    130                 if (variable != identifier->second->getLowercaseConfigValueMapEnd())
    131                 {
    132                     const std::string& valuestring = variable->second->toString();
    133                     oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
    134                 }
    135             }
    136             return oldvalue;
     140            return oldValue;
    137141        }
    138142
Note: See TracChangeset for help on using the changeset viewer.