Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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())
Note: See TracChangeset for help on using the changeset viewer.