Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2008, 3:34:55 PM (17 years ago)
Author:
landauf
Message:

extracted all config-value related macros from CoreIncludes.h and moved them to ConfigValueIncludes.h.

ConfigValueContainer can now handle std::vector<x> where 'x' is is any type supported by MultiTypeMath (all primitives, pointer, string, vector2, vector3, quaternion, colourvalue, radian, degree).

the vectors size is currently limited to 256 elements. this is just a practical limit, it can be raised if it's necessary. the reason for the limit is: you can add new elements to a vector by simply typing 'set classname varname index value' into the console or adding a new entry in the config-file. if 'index' is bigger than the vectors size, all elements up to 'index' are inserted. if the user accidentally enters a big number, he could end up with >4*109 elements in his config-file, resulting in 10-100gb on the hdd and a completely filled memory. and that's not exactly what i want ;)

File:
1 edited

Legend:

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

    r1027 r1030  
    4949    void cleanConfig()
    5050    {
    51         ConfigFileManager::getSingleton()->clean();
     51        ConfigFileManager::getSingleton()->clean(false);
    5252    }
    5353
     
    7676
    7777    ///////////////////////////////
    78     // ConfigFileEntryArrayValue //
     78    // ConfigFileEntryVectorValue //
    7979    ///////////////////////////////
    80     std::string ConfigFileEntryArrayValue::getFileEntry() const
     80    std::string ConfigFileEntryVectorValue::getFileEntry() const
    8181    {
    8282        if (this->additionalComment_ == "" || this->additionalComment_.size() == 0)
    83             return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, 0) + "]" + "=" + this->value_);
     83            return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, "0") + "]" + "=" + this->value_);
    8484        else
    85             return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, 0) + "]=" + this->value_ + " " + this->additionalComment_);
     85            return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, "0") + "]=" + this->value_ + " " + this->additionalComment_);
    8686    }
    8787
     
    9696    }
    9797
     98    void ConfigFileSection::deleteVectorEntries(const std::string& name, unsigned int startindex)
     99    {
     100        for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); )
     101        {
     102            if (((*it)->getName() == name) && ((*it)->getIndex() >= startindex))
     103            {
     104                delete (*it);
     105                this->entries_.erase(it++);
     106            }
     107            else
     108            {
     109                ++it;
     110            }
     111        }
     112    }
     113
     114    unsigned int ConfigFileSection::getVectorSize(const std::string& name)
     115    {
     116        unsigned int size = 0;
     117        for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
     118            if ((*it)->getName() == name)
     119                if ((*it)->getIndex() > size)
     120                    size = (*it)->getIndex();
     121        return (size + 1);
     122    }
     123
    98124    std::string ConfigFileSection::getFileEntry() const
    99125    {
     
    124150
    125151        if (index == 0)
    126             return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index, fallback)));
     152            return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback)));
    127153        else
    128             return this->entries_.insert(this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index, fallback)));
     154            return this->entries_.insert(++this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback)));
    129155    }
    130156
     
    173199            if (!isEmpty(temp) && !isComment(temp))
    174200            {
    175                 unsigned int pos1 = line.find('[');
    176                 unsigned int pos2 = line.find(']');
     201                unsigned int   pos1 = temp.find('[');
     202                if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos;
     203                unsigned int   pos2 = line.find(']');
    177204
    178205                if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1)
    179206                {
    180207                    // New section
    181                     std::string comment = temp.substr(pos2 + 1);
     208                    std::string comment = line.substr(pos2 + 1);
    182209                    if (isComment(comment))
    183210                        newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment);
     
    232259                            {
    233260                                // New array
    234                                 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryArrayValue(getStripped(line.substr(0, pos2)), index, value, comment));
     261                                std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value);
     262                                (*it)->setValue(value);
     263                                (*it)->setComment(comment);
    235264                                continue;
    236265                            }
     
    284313    }
    285314
    286     void ConfigFile::clean()
     315    void ConfigFile::clean(bool bCleanComments)
    287316    {
    288317        for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); )
     
    292321            {
    293322                // The section exists, delete comment
    294                 (*it1)->setComment("");
     323                if (bCleanComments)
     324                    (*it1)->setComment("");
    295325                for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); )
    296326                {
     
    299329                    {
    300330                        // The config-value exists, delete comment
    301                         (*it3)->setComment("");
     331                        if (bCleanComments)
     332                            (*it3)->setComment("");
    302333                        ++it3;
    303334                    }
     
    331362        this->bUpdated_ = true;
    332363
    333         return (*this->sections_.insert(this->sections_.begin(), new ConfigFileSection(section)));
     364        return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(section)));
    334365    }
    335366
     
    400431    }
    401432
    402     void ConfigFileManager::clean()
     433    void ConfigFileManager::clean(bool bCleanComments)
    403434    {
    404435        for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
    405             this->clean((*it).first);
     436            this->clean((*it).first, bCleanComments);
    406437    }
    407438
     
    417448    }
    418449
    419     void ConfigFileManager::clean(ConfigFileType type)
    420     {
    421         this->getFile(type)->clean();
    422         this->getFile(type)->save();
     450    void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments)
     451    {
     452        this->getFile(type)->clean(bCleanComments);
    423453    }
    424454
Note: See TracChangeset for help on using the changeset viewer.