Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1020


Ignore:
Timestamp:
Apr 10, 2008, 4:39:06 PM (16 years ago)
Author:
landauf
Message:

changed ConfigValueContainer to use ConfigFileManager, but there is still an error

Location:
code/branches/core2/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/Orxonox.cc

    r993 r1020  
    8989#include "core/CommandExecutor.h"
    9090#include "core/InputBuffer.h"
     91#include "core/ConfigFileManager.h"
    9192
    9293#include "Orxonox.h"
     
    250251    ogre_->startRender();
    251252    //TODO: run engine
     253    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    252254    Factory::createClassHierarchy();
    253255    createScene();
     
    12311233    setupInputSystem();
    12321234    createFrameListener();
     1235    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    12331236    Factory::createClassHierarchy();
    12341237    startRenderLoop();*/
     
    12451248    initializeResourceGroups();
    12461249    setupInputSystem();
     1250    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    12471251    Factory::createClassHierarchy();
    12481252    createScene();
  • code/branches/core2/src/orxonox/core/ConfigFileManager.cc

    r1006 r1020  
    4444    void reloadConfig()
    4545    {
    46         ConfigFileManager::getInstance()->load();
     46        ConfigFileManager::getSingleton()->load();
    4747    }
    4848
    4949    void saveConfig()
    5050    {
    51         ConfigFileManager::getInstance()->save();
     51        ConfigFileManager::getSingleton()->save();
    5252    }
    5353
    5454    void cleanConfig()
    5555    {
    56         ConfigFileManager::getInstance()->clean();
     56        ConfigFileManager::getSingleton()->clean();
    5757    }
    5858
    5959    void loadSettings(const std::string& filename)
    6060    {
    61         ConfigFileManager::getInstance()->setFile(CFT_Settings, filename);
     61        ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename);
    6262    }
    6363
    6464    void loadKeybindings(const std::string& filename)
    6565    {
    66         ConfigFileManager::getInstance()->setFile(CFT_Keybindings, filename);
     66        ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, filename);
    6767    }
    6868
     
    109109    }
    110110
    111     std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index)
    112     {
     111    std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback)
     112    {
     113std::cout << "a33333333333333333333333333\n";
     114        for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
     115            if ((*it)->getName() == name)
     116                return it;
     117
     118        this->bUpdated_ = true;
     119
     120        return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryValue(name, fallback)));
     121    }
     122
     123    std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback)
     124    {
     125std::cout << "b3333333333333333333333333\n";
    113126        for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
    114127            if (((*it)->getName() == name) && ((*it)->getIndex() == index))
     
    118131
    119132        if (index == 0)
    120             return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index)));
     133            return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index, fallback)));
    121134        else
    122             return this->entries_.insert(this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index)));
     135            return this->entries_.insert(this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index, fallback)));
    123136    }
    124137
     
    184197                if (isComment(line))
    185198                {
     199std::cout << "1_7\n";
    186200                    // New comment
    187                     newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(line));
     201                    newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line)));
    188202                    continue;
    189203                }
    190204                else
    191205                {
     206std::cout << "1_8\n";
    192207                    unsigned int pos1 = line.find('=');
    193208
    194209                    if (pos1 != std::string::npos && pos1 > 0)
    195210                    {
     211std::cout << "1_9\n";
    196212                        // New entry
    197 
    198213                        unsigned int pos2 = line.find('[');
    199214                        unsigned int pos3 = line.find(']');
     
    205220                        if (value.size() > 0 && value[0] == '"' && betweenQuotes != "" && betweenQuotes.size() > 0)
    206221                        {
     222std::cout << "1_10\n";
    207223                            value = betweenQuotes;
    208                             comment = getComment(value.substr(betweenQuotes.size() + 2));
     224                            if (line.size() > pos1 + 1 + betweenQuotes.size() + 2)
     225                                comment = removeTrailingWhitespaces(getComment(line.substr(pos1 + 1 + betweenQuotes.size() + 2)));
    209226                        }
    210227                        else
    211228                        {
     229std::cout << "1_11\n";
    212230                            unsigned int pos4 = getCommentPosition(line);
     231std::cout << "a\n";
     232std::cout << line << std::endl;
     233std::cout << line.substr(pos1 + 1, pos4 - pos1 - 1) << std::endl;
    213234                            value = removeTrailingWhitespaces(line.substr(pos1 + 1, pos4 - pos1 - 1));
    214                             comment = line.substr(pos4);
     235std::cout << value << std::endl;
     236std::cout << "b\n";
     237                            if (pos4 != std::string::npos)
     238                                comment = removeTrailingWhitespaces(line.substr(pos4));
     239std::cout << comment << std::endl;
     240std::cout << "c\n";
    215241                        }
    216242
    217 
     243std::cout << "1_12\n";
    218244                        if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1)
    219245                        {
     246std::cout << "1_13\n";
    220247                            // There might be an array index
    221248                            unsigned int index = 0;
     
    224251                                // New array
    225252                                newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryArrayValue(getStripped(line.substr(0, pos2)), index, value, comment));
     253std::cout << "1_14\n";
    226254                                continue;
    227255                            }
     
    230258                        // New value
    231259                        newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, comment));
     260std::cout << "1_15\n";
    232261                        continue;
    233262                    }
     
    235264            }
    236265        }
     266std::cout << "1_16\n";
    237267
    238268        file.close();
     269
     270        COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
    239271
    240272        // Save the file in case something changed (like stripped whitespaces)
    241273        this->save();
     274std::cout << "1_17\n";
    242275    }
    243276
     
    269302
    270303        file.close();
     304
     305        COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl;
    271306    }
    272307
     
    277312    ConfigFileSection* ConfigFile::getSection(const std::string& section)
    278313    {
     314std::cout << "22222222222222222222\n";
    279315        for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
    280316            if ((*it)->getName() == section)
     
    321357    }
    322358
    323     ConfigFileManager* ConfigFileManager::getInstance()
     359    ConfigFileManager* ConfigFileManager::getSingleton()
    324360    {
    325361        static ConfigFileManager instance;
     
    397433    ConfigFile* ConfigFileManager::getFile(ConfigFileType type)
    398434    {
     435std::cout << "111111111111111111\n";
    399436        std::map<ConfigFileType, ConfigFile*>::iterator it = this->configFiles_.find(type);
    400437        if (it != this->configFiles_.end())
  • code/branches/core2/src/orxonox/core/ConfigFileManager.h

    r1006 r1020  
    7676    {
    7777        public:
    78             inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", const std::string& additionalComment = "") : name_(name), value_(value), additionalComment_(additionalComment), bString_(false) {}
     78            inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", const std::string& additionalComment = "") : name_(name), value_(value), additionalComment_(additionalComment), bString_(false) { std::cout << "************* " << value << std::endl; }
    7979            inline virtual ~ConfigFileEntryValue() {}
    8080
     
    161161
    162162            inline void setValue(const std::string& name, const std::string& value)
    163                 { this->getEntry(name)->setValue(value); }
    164             inline const std::string& getValue(const std::string& name)
    165                 { return this->getEntry(name)->getValue(); }
     163                { this->getEntry(name, value)->setValue(value); }
     164            inline const std::string& getValue(const std::string& name, const std::string& fallback)
     165                { return this->getEntry(name, fallback)->getValue(); }
    166166
    167167            inline void setValue(const std::string& name, unsigned int index, const std::string& value)
    168                 { this->getEntry(name, index)->setValue(value); }
    169             inline const std::string& getValue(const std::string& name, unsigned int index)
    170                 { return this->getEntry(name, index)->getValue(); }
     168                { this->getEntry(name, index, value)->setValue(value); }
     169            inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback)
     170                { return this->getEntry(name, index, fallback)->getValue(); }
    171171
    172172            std::string getFileEntry() const;
     
    180180                { return this->entries_.end(); }
    181181
    182             std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index);
    183 
    184             inline ConfigFileEntry* getEntry(const std::string& name)
    185                 { return (*this->getEntryIterator(name, 0)); }
    186             inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index)
    187                 { return (*this->getEntryIterator(name, index)); }
     182            std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, const std::string& fallback = "");
     183            std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback = "");
     184
     185            inline ConfigFileEntry* getEntry(const std::string& name, const std::string& fallback)
     186                { return (*this->getEntryIterator(name, fallback)); }
     187            inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index, const std::string& fallback)
     188                { return (*this->getEntryIterator(name, index, fallback)); }
    188189
    189190            std::string name_;
     
    209210            inline void setValue(const std::string& section, const std::string& name, const std::string& value)
    210211                { this->getSection(section)->setValue(name, value); this->save(); }
    211             inline const std::string& getValue(const std::string& section, const std::string& name)
    212                 { return this->getSection(section)->getValue(name); this->saveIfUpdated(); }
     212            inline const std::string& getValue(const std::string& section, const std::string& name, const std::string& fallback)
     213                { return this->getSection(section)->getValue(name, fallback); this->saveIfUpdated(); }
    213214
    214215            inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value)
    215216                { this->getSection(section)->setValue(name, index, value); this->save(); }
    216             inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index)
    217                 { return this->getSection(section)->getValue(name, index); this->saveIfUpdated(); }
     217            inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback)
     218                { return this->getSection(section)->getValue(name, index, fallback); this->saveIfUpdated(); }
    218219
    219220        private:
     
    233234    {
    234235        public:
    235             static ConfigFileManager* getInstance();
     236            static ConfigFileManager* getSingleton();
    236237
    237238            void setFile(ConfigFileType type, const std::string& filename);
     
    247248            inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value)
    248249                { this->getFile(type)->setValue(section, name, value); }
    249             inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name)
    250                 { return this->getFile(type)->getValue(section, name); }
     250            inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback)
     251                { return this->getFile(type)->getValue(section, name, fallback); }
    251252
    252253            inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value)
    253254                { this->getFile(type)->setValue(section, name, index, value); }
    254             inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index)
    255                 { return this->getFile(type)->getValue(section, name, index); }
     255            inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback)
     256                { return this->getFile(type)->getValue(section, name, index, fallback); }
    256257
    257258            void updateConfigValues() const;
  • code/branches/core2/src/orxonox/core/ConfigValueContainer.cc

    r989 r1020  
    3535#include "ConfigValueContainer.h"
    3636#include "Language.h"
    37 #include "Iterator.h"
    38 #include "BaseObject.h"
    3937
    40 #define CONFIGFILEPATH "orxonox.ini"
    4138
    4239namespace orxonox
     
    4946        @param defvalue The default-value
    5047    */
    51     ConfigValueContainer::ConfigValueContainer(Identifier* identifier, const std::string& varname, MultiTypeMath defvalue)
     48    ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMath defvalue)
    5249    {
    53         this->bAddedDescription_ = false;
     50        this->type_ = type;
    5451        this->identifier_ = identifier;
     52        this->sectionname_ = identifier->getName();
    5553        this->varname_ = varname;
    5654
    57         this->defvalueString_ = defvalue.toString();                                // Convert the default-value to a string
    58         this->searchLineInConfigFile();                                             // Search the entry in the config-file
     55        this->bAddedDescription_ = false;
    5956
    60         std::string valueString = this->parseValueStringFromConfigFile(!(defvalue.isA(MT_string) || defvalue.isA(MT_constchar)));     // Parses the value string from the config-file-entry
    61         if (!this->parse(valueString, defvalue))                                    // Try to convert the string to a value
    62             this->resetLineInConfigFile();                                            // The conversion failed
     57        this->defvalueString_ = defvalue.toString();
     58        this->update();
    6359    }
    6460
     
    9490    {
    9591        return this->set(this->defvalueString_);
     92    }
     93
     94    /**
     95        @brief Retrieves the configured value from the currently loaded config-file.
     96    */
     97    void ConfigValueContainer::update()
     98    {
     99std::cout << "AAA1: " << this->value_ << std::endl;
     100std::cout << "    : " << ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_) << std::endl;
     101        this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_));
     102std::cout << "AAA2: " << this->value_ << std::endl;
    96103    }
    97104
     
    138145    void ConfigValueContainer::setLineInConfigFile(const std::string& input)
    139146    {
    140         (*this->configFileLine_) = this->varname_ + "=" + input;
    141         ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     147        ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input);
    142148    }
    143149
     
    147153    void ConfigValueContainer::resetLineInConfigFile()
    148154    {
    149         this->setLineInConfigFile(this->defvalueString_);
    150     }
    151 
    152     /**
    153         @brief Searches the corresponding entry in the config-file and creates it, if there is no entry.
    154     */
    155     void ConfigValueContainer::searchLineInConfigFile()
    156     {
    157         // Read the file if needed
    158         if (!ConfigValueContainer::finishedReadingConfigFile())
    159             ConfigValueContainer::readConfigFile(CONFIGFILEPATH);
    160 
    161         // The string of the section we're searching
    162         std::string section = "";
    163         section.append("[");
    164         section.append(this->identifier_->getName());
    165         section.append("]");
    166 
    167         // Iterate through all config-file-lines
    168         bool success = false;
    169         std::list<std::string>::iterator it1;
    170         for(it1 = ConfigValueContainer::getConfigFileLines().begin(); it1 != ConfigValueContainer::getConfigFileLines().end(); ++it1)
    171         {
    172             // Don't try to parse comments
    173             if (isComment(*it1))
    174                 continue;
    175 
    176             if ((*it1).find(section) < (*it1).length())
    177             {
    178                 // We found the right section
    179                 bool bLineIsEmpty = false;
    180                 std::list<std::string>::iterator positionToPutNewLineAt;
    181 
    182                 // Iterate through all lines in the section
    183                 std::list<std::string>::iterator it2;
    184                 for(it2 = ++it1; it2 != ConfigValueContainer::getConfigFileLines().end(); ++it2)
    185                 {
    186                     // Don't try to parse comments
    187                     if (isComment(*it2))
    188                         continue;
    189 
    190                     // This if-else block is used to write a new line right after the last line of the
    191                     // section but in front of the following empty lines before the next section.
    192                     // (So this helps to keep a nice formatting with empty-lines between sections in the config-file)
    193                     if (isEmpty(*it2))
    194                     {
    195                         if (!bLineIsEmpty)
    196                         {
    197                             bLineIsEmpty = true;
    198                             positionToPutNewLineAt = it2;
    199                         }
    200                     }
    201                     else
    202                     {
    203                         if (!bLineIsEmpty)
    204                             positionToPutNewLineAt = it2;
    205 
    206                         bLineIsEmpty = false;
    207                     }
    208 
    209                     // Look out for the beginning of the next section
    210                     unsigned int open = (*it2).find("[");
    211                     unsigned int close = (*it2).find("]");
    212                     if ((open < (*it2).length()) && (close < (*it2).length()) && (open < close))
    213                     {
    214                         // The next section startet, so our line isn't yet in the file - now we add it and safe the file
    215                         this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_);
    216                         ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
    217                         success = true;
    218                         break;
    219                     }
    220 
    221                     // Look out for the variable-name
    222                     if ((*it2).find(this->varname_) < (*it2).length())
    223                     {
    224                         // We found the right line - safe it and return
    225                         this->configFileLine_ = it2;
    226                         success = true;
    227                         break;
    228                     }
    229                 }
    230 
    231                 // Check if we succeeded
    232                 if (!success)
    233                 {
    234                     // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file
    235                     this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_);
    236                     ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
    237                     success = true;
    238                 }
    239                 break;
    240             }
    241         }
    242 
    243         // Check if we succeeded
    244         if (!success)
    245         {
    246             // We obviously didn't found the right section, so we'll create it
    247             this->getConfigFileLines().push_back("[" + this->identifier_->getName() + "]");                   // Create the section
    248             this->getConfigFileLines().push_back(this->varname_ + "=" + this->defvalueString_);   // Create the line
    249             this->configFileLine_ = --this->getConfigFileLines().end();                           // Set the pointer to the last element
    250             success = true;
    251             this->getConfigFileLines().push_back("");                                             // Add an empty line - this is needed for the algorithm in the searchLineInConfigFile-function
    252             ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);                                // Save the changed config-file
    253         }
    254     }
    255 
    256     /**
    257         @brief Returns the part in the corresponding config-file-entry of the container that defines the value.
    258         @param bStripped True = strip the value-string
    259         @return The value-string
    260     */
    261     std::string ConfigValueContainer::parseValueStringFromConfigFile(bool bStripped)
    262     {
    263         std::string output;
    264         if (bStripped)
    265             output = getStripped(*this->configFileLine_);
    266         else
    267             output = *this->configFileLine_;
    268 
    269         return output.substr(output.find("=") + 1);
    270     }
    271 
    272     /**
    273         @brief Rreturns a list, containing all entrys in the config-file.
    274         @return The list
    275     */
    276     std::list<std::string>& ConfigValueContainer::getConfigFileLines()
    277     {
    278         // This is done to avoid problems while executing this code before main()
    279         static std::list<std::string> configFileLinesStaticReference = std::list<std::string>();
    280         return configFileLinesStaticReference;
    281     }
    282 
    283     /**
    284         @brief Returns true if the ConfigFile is read and stored into the ConfigFile-lines-list.
    285         @param finished This is used to change the state
    286         @return True if the ConfigFile is read and stored into the ConfigFile-lines-list
    287     */
    288     bool ConfigValueContainer::finishedReadingConfigFile(bool finished)
    289     {
    290         // This is done to avoid problems while executing this code before main()
    291         static bool finishedReadingConfigFileStaticVariable = false;
    292 
    293         if (finished)
    294             finishedReadingConfigFileStaticVariable = true;
    295 
    296         return finishedReadingConfigFileStaticVariable;
    297     }
    298 
    299     /**
    300         @brief Reads the config-file and stores the lines in a list.
    301         @param filename The name of the config-file
    302     */
    303     void ConfigValueContainer::readConfigFile(const std::string& filename)
    304     {
    305         // This creates the file if it's not existing
    306         std::ofstream createFile;
    307         createFile.open(filename.c_str(), std::fstream::app);
    308         createFile.close();
    309 
    310         // Open the file
    311         std::ifstream file;
    312         file.open(filename.c_str(), std::fstream::in);
    313 
    314         if (!file.is_open())
    315         {
    316             COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl;
    317             COUT(1) << "Error: Couldn't open config-file " << filename << " to read the config values!" << std::endl;
    318             return;
    319         }
    320 
    321         char line[1024];
    322 
    323         // Iterate through the file and add the lines into the list
    324         while (file.good() && !file.eof())
    325         {
    326             file.getline(line, 1024);
    327             ConfigValueContainer::getConfigFileLines().push_back(line);
    328         }
    329 
    330         // The last line is useless
    331         ConfigValueContainer::getConfigFileLines().pop_back();
    332 
    333         // Add an empty line to the end of the file if needed
    334         // this is needed for the algorithm in the searchLineInConfigFile-function
    335         if ((ConfigValueContainer::getConfigFileLines().size() > 0) && !isEmpty(*ConfigValueContainer::getConfigFileLines().rbegin()))
    336             ConfigValueContainer::getConfigFileLines().push_back("");
    337 
    338         file.close();
    339 
    340         ConfigValueContainer::finishedReadingConfigFile(true);
    341     }
    342 
    343     /**
    344         @brief Writes the content of the list, containing all lines of the config-file, into the config-file.
    345         @param filename The name of the config-file
    346     */
    347     void ConfigValueContainer::writeConfigFile(const std::string& filename)
    348     {
    349         // Make sure we stored the config-file in the list
    350         if (!ConfigValueContainer::finishedReadingConfigFile())
    351             ConfigValueContainer::readConfigFile(filename);
    352 
    353         // Open the file
    354         std::ofstream file;
    355         file.open(filename.c_str(), std::fstream::out);
    356         file.setf(std::ios::fixed, std::ios::floatfield);
    357         file.precision(6);
    358 
    359         if (!file.is_open())
    360         {
    361             COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl;
    362             COUT(1) << "Error: Couldn't open config-file " << filename << " to write the config values!" << std::endl;
    363             return;
    364         }
    365 
    366         // Iterate through the list an write the lines into the file
    367         std::list<std::string>::iterator it;
    368         for (it = ConfigValueContainer::getConfigFileLines().begin(); it != ConfigValueContainer::getConfigFileLines().end(); ++it)
    369         {
    370             file << (*it) << std::endl;
    371         }
    372 
    373         file.close();
     155        this->setLineInConfigFile(this->value_.toString());
    374156    }
    375157
  • code/branches/core2/src/orxonox/core/ConfigValueContainer.h

    r972 r1020  
    5050#include "util/Math.h"
    5151#include "util/MultiTypeMath.h"
     52#include "ConfigFileManager.h"
    5253
    5354namespace orxonox
     
    7273    {
    7374        public:
    74             ConfigValueContainer(Identifier* identifier, const std::string& varname, MultiTypeMath defvalue);
     75            ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMath defvalue);
    7576
    7677            /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */
     
    8889            bool tset(const std::string& input);
    8990            bool reset();
     91            void update();
    9092
    9193            /** @brief Converts the config-value to a string. @return The string */
     
    9799
    98100        private:
    99             static void readConfigFile(const std::string& filename);
    100             static void writeConfigFile(const std::string& filename);
    101             static std::list<std::string>& getConfigFileLines();
    102             static bool finishedReadingConfigFile(bool finished = false);
    103 
    104101            bool parse(const std::string& input);
    105102            bool parse(const std::string& input, const MultiTypeMath& defvalue);
     
    107104            void setLineInConfigFile(const std::string& input);
    108105            void resetLineInConfigFile();
    109             void searchLineInConfigFile();
    110106
    111             std::string parseValueStringFromConfigFile(bool bStripped = true);
    112 
    113             Identifier*         identifier_;                    //!< The name of the class the variable belongs to
     107            ConfigFileType      type_;                          //!< The type of the corresponding config-file
     108            Identifier*         identifier_;                    //!< The identifier of the class
     109            std::string         sectionname_;                   //!< The name of the class the variable belongs to
    114110            std::string         varname_;                       //!< The name of the variable
    115111            std::string         defvalueString_;                //!< The string of the default-variable
  • code/branches/core2/src/orxonox/core/CoreIncludes.h

    r957 r1020  
    5050#include "OrxonoxClass.h"
    5151#include "ConfigValueContainer.h"
     52#include "ConfigFileManager.h"
    5253#include "Debug.h"
    5354
     
    120121    if (!container##varname) \
    121122    { \
    122         container##varname = new orxonox::ConfigValueContainer(this->getIdentifier(), #varname, varname = defvalue); \
     123        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \
    123124        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
    124125    } \
     
    139140        COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl
    140141
     142/**
     143    @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file).
     144    @param varname The name of the key-variable
     145*/
     146#define SetKeybind(keyname) \
     147    orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \
     148    if (!container##keyname) \
     149    { \
     150        container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \
     151        this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \
     152    } \
     153    container##keyname->getValue(&varname)
     154
    141155#endif /* _CoreIncludes_H__ */
  • code/branches/core2/src/orxonox/core/DebugLevel.cc

    r948 r1020  
    9595
    9696        // Return a constant value while we're creating the object
    97         return 2;
     97        return 4;
    9898    }
    9999}
  • code/branches/core2/src/orxonox/core/Language.cc

    r931 r1020  
    108108
    109109        // Read the translation file after the language was configured
     110std::cout << "asdfasdfkjsfkdjaslfkjsaflkjsdfkl\n";
    110111        this->readTranslatedLanguageFile();
    111112    }
  • code/branches/core2/src/util/MultiTypeMath.cc

    r1003 r1020  
    169169        ConvertValue(&output, this->vector3_);
    170170    else if (this->type_ == MT_colourvalue)
    171     { std::cout << "3_1\n";
    172         ConvertValue(&output, this->colourvalue_);}
     171        ConvertValue(&output, this->colourvalue_);
    173172    else if (this->type_ == MT_quaternion)
    174173        ConvertValue(&output, this->quaternion_);
     
    190189        return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0));
    191190    else if (this->type_ == MT_colourvalue)
    192     { std::cout << "4_1\n";
    193         return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0)); }
     191        return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0));
    194192    else if (this->type_ == MT_quaternion)
    195193        return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0));
  • code/branches/core2/src/util/String.cc

    r1006 r1020  
    6262std::string removeTrailingWhitespaces(const std::string& str)
    6363{
     64    unsigned int pos1 = 0;
     65    unsigned int pos2 = str.size() - 1;
     66    for (; pos1 < str.size() && (str[pos1] == ' ' || str[pos1] == '\t' || str[pos1] == '\n'); pos1++);
     67    for (; pos2 >= 0         && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
     68    return str.substr(pos1, pos2 - pos1 + 1);
     69}
     70
     71/**
     72    @brief Returns the position of the next quote in the string, starting with start.
     73    @param str The string
     74    @param start The startposition
     75    @return The position of the next quote (std::string::npos if there is no next quote)
     76*/
     77unsigned int getNextQuote(const std::string& str, unsigned int start)
     78{
     79    unsigned int quote = start - 1;
     80
     81    while ((quote = str.find('\"', quote + 1)) != std::string::npos)
     82    {
     83        unsigned int backslash = quote;
     84        unsigned int numbackslashes = 0;
     85        for (; backslash > 0; backslash--, numbackslashes++)
     86            if (str[backslash - 1] != '\\')
     87                break;
     88
     89        if (numbackslashes % 2 == 0)
     90            break;
     91    }
     92
     93    return quote;
    6494}
    6595
     
    71101bool hasStringBetweenQuotes(const std::string& str)
    72102{
     103    unsigned int pos1 = getNextQuote(str, 0);
     104    unsigned int pos2 = getNextQuote(str, pos1 + 1);
     105    return (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1);
    73106}
    74107
     
    80113std::string getStringBetweenQuotes(const std::string& str)
    81114{
     115    unsigned int pos1 = getNextQuote(str, 0);
     116    unsigned int pos2 = getNextQuote(str, pos1 + 1);
     117    if (pos1 != std::string::npos && pos2 != std::string::npos)
     118        return str.substr(pos1, pos2 - pos1 + 1);
     119    else
     120        return "";
    82121}
    83122
  • code/branches/core2/src/util/String.h

    r1006 r1020  
    3838
    3939_UtilExport std::string  removeTrailingWhitespaces(const std::string& str);
     40
     41_UtilExport unsigned int getNextQuote(const std::string& str, unsigned int start);
    4042
    4143_UtilExport bool         hasStringBetweenQuotes(const std::string& str);
Note: See TracChangeset for help on using the changeset viewer.