Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1030


Ignore:
Timestamp:
Apr 12, 2008, 3:34:55 PM (16 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 ;)

Location:
code/branches/core2
Files:
1 added
1 deleted
15 edited

Legend:

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

    r1020 r1030  
    11961196        ib->registerListener(testlistener, &Testlistener::removeLast, '\b', true);
    11971197
     1198        Test3* test16_1 = new Test3;
     1199        test16_1->configOutput();
     1200
    11981201    startRenderLoop();
    11991202  }
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r1001 r1030  
    2929#include "ConsoleCommand.h"
    3030#include "util/String.h"
     31#include "util/Convert.h"
    3132#include "Identifier.h"
    3233#include "Language.h"
     
    13131314    {
    13141315        AddLanguageEntry("CommandExecutor::oldvalue", "old value");
    1315         return "{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")";
     1316        if (!container->isVector())
     1317            return ("{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")");
     1318        else
     1319            return ("(vector<" + container->getTypename() + ">) (size: " + getConvertedValue<unsigned int, std::string>(container->getVectorSize()) + ")");
    13161320    }
    13171321
  • 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
  • code/branches/core2/src/orxonox/core/ConfigFileManager.h

    r1027 r1030  
    107107
    108108    ///////////////////////////////
    109     // ConfigFileEntryArrayValue //
     109    // ConfigFileEntryVectorValue //
    110110    ///////////////////////////////
    111     class _CoreExport ConfigFileEntryArrayValue : public ConfigFileEntryValue
    112     {
    113         public:
    114             inline ConfigFileEntryArrayValue(const std::string& name, unsigned int index, const std::string& value = "", const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, additionalComment), index_(index) {}
    115             inline virtual ~ConfigFileEntryArrayValue() {}
     111    class _CoreExport ConfigFileEntryVectorValue : public ConfigFileEntryValue
     112    {
     113        public:
     114            inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, additionalComment), index_(index) {}
     115            inline virtual ~ConfigFileEntryVectorValue() {}
    116116
    117117            inline virtual unsigned int getIndex() const
     
    179179            inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback)
    180180                { return this->getEntry(name, index, fallback)->getValue(); }
     181
     182            void deleteVectorEntries(const std::string& name, unsigned int startindex = 0);
     183            unsigned int getVectorSize(const std::string& name);
    181184
    182185            std::string getFileEntry() const;
     
    216219            void load(bool bCreateIfNotExisting = true);
    217220            void save() const;
    218             void clean();
     221            void clean(bool bCleanComments = false);
    219222
    220223            inline void setValue(const std::string& section, const std::string& name, const std::string& value)
     
    228231                { const std::string& output = this->getSection(section)->getValue(name, index, fallback); this->saveIfUpdated(); return output; }
    229232
     233            inline void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0)
     234                { this->getSection(section)->deleteVectorEntries(name, startindex); }
     235            inline unsigned int getVectorSize(const std::string& section, const std::string& name)
     236                { return this->getSection(section)->getVectorSize(name); }
     237
    230238        private:
    231239            ConfigFileSection* getSection(const std::string& section);
     
    250258            void load(bool bCreateIfNotExisting = true);
    251259            void save();
    252             void clean();
     260            void clean(bool bCleanComments = false);
    253261
    254262            void load(ConfigFileType type, bool bCreateIfNotExisting = true);
    255263            void save(ConfigFileType type);
    256             void clean(ConfigFileType type);
     264            void clean(ConfigFileType type, bool bCleanComments = false);
    257265
    258266            inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value)
     
    266274                { return this->getFile(type)->getValue(section, name, index, fallback); }
    267275
     276            inline void deleteVectorEntries(ConfigFileType type, const std::string& section, const std::string& name, unsigned int startindex = 0)
     277                { this->getFile(type)->deleteVectorEntries(section, name, startindex); }
     278            inline unsigned int getVectorSize(ConfigFileType type, const std::string& section, const std::string& name)
     279                { return this->getFile(type)->getVectorSize(section, name); }
     280
    268281            void updateConfigValues() const;
    269282            void updateConfigValues(ConfigFileType type) const;
  • code/branches/core2/src/orxonox/core/ConfigValueContainer.cc

    r1023 r1030  
    3535#include "ConfigValueContainer.h"
    3636#include "Language.h"
     37#include "util/SubString.h"
     38#include "util/Convert.h"
     39
     40#define MAX_VECTOR_INDEX 255 // to avoid up to 4*10^9 vector entries in the config file after accidentally using a wrong argument
    3741
    3842
     
    4145    /**
    4246        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    43         @param value This is only needed to determine the right type.
    44         @param classname The name of the class the variable belongs to
     47        @param type The type of the corresponding config-file
     48        @param identifier The identifier of the class the variable belongs to
    4549        @param varname The name of the variable
    4650        @param defvalue The default-value
    4751    */
    48     ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMath defvalue)
     52    ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue)
    4953    {
    5054        this->type_ = type;
     
    5559        this->value_ = defvalue;
    5660        this->bAddedDescription_ = false;
     61        this->bIsVector_ = false;
    5762
    5863        this->defvalueString_ = defvalue.toString();
    5964        this->update();
     65    }
     66
     67    /**
     68        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
     69        @param type The type of the corresponding config-file
     70        @param identifier The identifier of the class the variable belongs to
     71        @param varname The name of the variable
     72        @param defvalue The default-value
     73    */
     74    ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue)
     75    {
     76        this->type_ = type;
     77        this->identifier_ = identifier;
     78        this->sectionname_ = identifier->getName();
     79        this->varname_ = varname;
     80
     81        this->valueVector_ = defvalue;
     82        this->bAddedDescription_ = false;
     83        this->bIsVector_ = true;
     84
     85        if (defvalue.size() > 0)
     86            this->value_ = defvalue[0];
     87
     88        for (unsigned int i = 0; i < defvalue.size(); i++)
     89            ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString());
     90
     91        for (unsigned int i = 0; i < defvalue.size(); i++)
     92            this->defvalueStringVector_.push_back(defvalue[i].toString());
     93
     94        this->update();
     95    }
     96
     97    /**
     98        @brief Adds a new entry to the end of the vector.
     99        @param input The new entry
     100        @return True if the new entry was successfully added
     101    */
     102    bool ConfigValueContainer::add(const std::string& input)
     103    {
     104        if (this->bIsVector_)
     105            return this->set(this->valueVector_.size(), input);
     106
     107        COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
     108        return false;
     109    }
     110
     111    /**
     112        @brief Removes an existing entry from the vector.
     113        @param index The index of the entry
     114        @return True if the entry was removed
     115    */
     116    bool ConfigValueContainer::remove(unsigned int index)
     117    {
     118        if (this->bIsVector_)
     119        {
     120            if (index < this->valueVector_.size())
     121            {
     122                this->valueVector_.erase(this->valueVector_.begin() + index);
     123                for (unsigned int i = index; i < this->valueVector_.size(); i++)
     124                    ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i]);
     125                ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
     126
     127                return true;
     128            }
     129            COUT(1) << "Error: Invalid vector-index." << std::endl;
     130        }
     131
     132        COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
     133        return false;
    60134    }
    61135
     
    67141    bool ConfigValueContainer::set(const std::string& input)
    68142    {
     143        if (this->bIsVector_)
     144        {
     145            SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0');
     146            int index = -1;
     147            bool success = false;
     148
     149            if (token.size() > 0)
     150                success = ConvertValue(&index, token[0]);
     151
     152            if (!success || index < 0 || index > MAX_VECTOR_INDEX)
     153            {
     154                if (!success)
     155                    COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;
     156                else
     157                    COUT(1) << "Error: Invalid vector-index." << std::endl;
     158                return false;
     159            }
     160
     161            if (token.size() >= 2)
     162                return this->set(index, token.subSet(1).join());
     163            else
     164                return this->set(index, "");
     165        }
     166
    69167        bool success = this->tset(input);
    70         this->setLineInConfigFile(input);
     168        ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input);
    71169        return success;
     170    }
     171
     172    /**
     173        @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
     174        @param index The index in the vector
     175        @param input The new value
     176        @return True if the new value was successfully assigned
     177    */
     178    bool ConfigValueContainer::set(unsigned int index, const std::string& input)
     179    {
     180        if (this->bIsVector_)
     181        {
     182            bool success = this->tset(index, input);
     183            ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input);
     184            return success;
     185        }
     186
     187        COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
     188        return false;
    72189    }
    73190
     
    86203
    87204    /**
     205        @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
     206        @param index The index in the vector
     207        @param input The new value
     208        @return True if the new value was successfully assigned
     209    */
     210    bool ConfigValueContainer::tset(unsigned int index, const std::string& input)
     211    {
     212        if (this->bIsVector_)
     213        {
     214            bool success = this->parse(index, input);
     215            if (this->identifier_)
     216                this->identifier_->updateConfigValues();
     217            return success;
     218        }
     219
     220        COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
     221        return false;
     222    }
     223
     224    /**
    88225        @brief Sets the value of the variable back to the default value and resets the config-file entry.
    89226    */
    90227    bool ConfigValueContainer::reset()
    91228    {
    92         return this->set(this->defvalueString_);
     229        if (!this->bIsVector_)
     230            return this->set(this->defvalueString_);
     231        else
     232        {
     233            bool success = true;
     234            for (unsigned int i = 0; i < this->defvalueStringVector_.size(); i++)
     235                if (!this->set(i, this->defvalueStringVector_[i]))
     236                    success = false;
     237            ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size());
     238            return success;
     239        }
    93240    }
    94241
     
    98245    void ConfigValueContainer::update()
    99246    {
    100         this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_));
     247        if (!this->bIsVector_)
     248            this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_));
     249        else
     250        {
     251            this->valueVector_.clear();
     252            for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++)
     253            {
     254                this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i]));
     255                this->valueVector_.push_back(this->value_);
     256            }
     257        }
    101258    }
    102259
     
    108265    bool ConfigValueContainer::parse(const std::string& input)
    109266    {
     267        if (this->bIsVector_)
     268        {
     269            SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0');
     270            int index = -1;
     271            bool success = false;
     272
     273            if (token.size() > 0)
     274                success = ConvertValue(&index, token[0]);
     275
     276            if (!success || index < 0 || index > MAX_VECTOR_INDEX)
     277                return false;
     278
     279            if (token.size() >= 2)
     280                return this->parse(index, token.subSet(1).join());
     281            else
     282                return this->parse(index, "");
     283        }
     284
    110285        MultiTypeMath temp = this->value_;
    111286        if (temp.fromString(input))
     
    114289            return true;
    115290        }
     291        return false;
     292    }
     293
     294    /**
     295        @brief Parses a given std::string into a value of the type of the associated variable and assigns it.
     296        @param index The index in the vector
     297        @param input The string to convert
     298        @return True if the string was successfully parsed
     299    */
     300    bool ConfigValueContainer::parse(unsigned int index, const std::string& input)
     301    {
     302        if (this->bIsVector_)
     303        {
     304            if (index >= this->valueVector_.size())
     305            {
     306                for (unsigned int i = this->valueVector_.size(); i <= index; i++)
     307                {
     308                    this->valueVector_.push_back(MultiTypeMath());
     309                    ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i]);
     310                }
     311            }
     312
     313            MultiTypeMath temp = this->value_;
     314            if (temp.fromString(input))
     315            {
     316                this->valueVector_[index] = temp;
     317                return true;
     318            }
     319            return false;
     320        }
     321
     322        COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
    116323        return false;
    117324    }
     
    125332    bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue)
    126333    {
    127         MultiTypeMath temp = defvalue;
    128         if (temp.fromString(input))
    129         {
    130             this->value_ = temp;
     334        if (this->parse(input))
    131335            return true;
    132         }
    133         else
    134         {
    135             this->value_ = defvalue;
     336
     337        this->value_ = defvalue;
     338        return false;
     339    }
     340
     341    /**
     342        @brief Parses a given std::string into a value of the type of the associated variable and assigns it.
     343        @param index The index in the vector
     344        @param input The string to convert
     345        @param defvalue The default value to assign if the parsing fails
     346        @return True if the string was successfully parsed
     347    */
     348    bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue)
     349    {
     350        if (this->bIsVector_)
     351        {
     352            if (this->parse(index, input))
     353                return true;
     354
     355            this->valueVector_[index] = defvalue;
    136356            return false;
    137357        }
    138     }
    139 
    140     /**
    141         @brief Sets the corresponding entry in the config-file to a given value.
    142     */
    143     void ConfigValueContainer::setLineInConfigFile(const std::string& input)
    144     {
    145         ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input);
    146     }
    147 
    148     /**
    149         @brief Sets the corresponding entry in the config-file back to the default value.
    150     */
    151     void ConfigValueContainer::resetLineInConfigFile()
    152     {
    153         this->setLineInConfigFile(this->value_.toString());
     358
     359        COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
     360        return false;
    154361    }
    155362
  • code/branches/core2/src/orxonox/core/ConfigValueContainer.h

    r1020 r1030  
    4343#define _ConfigValueContainer_H__
    4444
    45 #include <list>
    4645#include <string>
     46#include <vector>
    4747
    4848#include "CorePrereqs.h"
     
    7373    {
    7474        public:
    75             ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMath defvalue);
     75            ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue);
     76            ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue);
    7677
    7778            /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */
     
    7980            inline ConfigValueContainer& getValue(T* value)
    8081                { this->value_.getValue(value); return *this; }
     82            template <typename T>
     83            inline ConfigValueContainer& getValue(std::vector<T>* value)
     84            {
     85                value->clear();
     86                for (unsigned int i = 0; i < this->valueVector_.size(); i++)
     87                    value->push_back(this->valueVector_[i]);
     88                return *this;
     89            }
    8190
    82             inline const std::string& getName()
     91            inline const std::string& getName() const
    8392                { return this->varname_; }
     93            inline bool isVector() const
     94                { return this->bIsVector_; }
     95            inline unsigned int getVectorSize() const
     96                { return this->valueVector_.size(); }
    8497
    8598            void description(const std::string& description);
    8699            const std::string& getDescription() const;
    87100
     101            bool add(const std::string& input);
     102            bool remove(unsigned int index);
    88103            bool set(const std::string& input);
    89104            bool tset(const std::string& input);
     
    102117            bool parse(const std::string& input, const MultiTypeMath& defvalue);
    103118
    104             void setLineInConfigFile(const std::string& input);
    105             void resetLineInConfigFile();
     119            bool set(unsigned int index, const std::string& input);
     120            bool tset(unsigned int index, const std::string& input);
     121            bool parse(unsigned int index, const std::string& input);
     122            bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue);
    106123
    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
    110             std::string         varname_;                       //!< The name of the variable
    111             std::string         defvalueString_;                //!< The string of the default-variable
     124            bool                       bIsVector_;                  //!< True if the container contains a std::vector
    112125
    113             MultiTypeMath       value_;                         //!< The value
     126            ConfigFileType             type_;                       //!< The type of the corresponding config-file
     127            Identifier*                identifier_;                 //!< The identifier of the class
     128            std::string                sectionname_;                //!< The name of the class the variable belongs to
     129            std::string                varname_;                    //!< The name of the variable
     130            std::string                defvalueString_;             //!< The string of the default-value
     131            std::vector<std::string>   defvalueStringVector_;       //!< A vector, containg the strings of the default-values in case we're storing a vector
    114132
    115             std::list<std::string>::iterator configFileLine_;   //!< An iterator, pointing to the entry of the variable in the config-file
     133            MultiTypeMath              value_;                      //!< The value
     134            std::vector<MultiTypeMath> valueVector_;                //!< A vector, containg the values in case we're storing a vector
    116135
    117             bool bAddedDescription_;                            //!< True if a description was added
    118             LanguageEntryLabel description_;                    //!< The description
     136            bool                       bAddedDescription_;          //!< True if a description was added
     137            LanguageEntryLabel         description_;                //!< The description
    119138    };
    120139}
  • code/branches/core2/src/orxonox/core/CoreIncludes.h

    r1020 r1030  
    2828/**
    2929    @file CoreIncludes.h
    30     @brief Definition of macros and typedefs.
     30    @brief Definition of macros for Identifier and Factory.
    3131
    3232    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
     
    4040#define _CoreIncludes_H__
    4141
    42 #include "CorePrereqs.h"
    43 
    44 // All needed header-files
    4542#include "Identifier.h"
    4643#include "ClassManager.h"
    4744#include "Factory.h"
    4845#include "ClassFactory.h"
    49 #include "Iterator.h"
    50 #include "OrxonoxClass.h"
    51 #include "ConfigValueContainer.h"
    52 #include "ConfigFileManager.h"
    5346#include "Debug.h"
    5447
    5548
    56 // All needed macros
    5749/**
    5850    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
     
    112104    orxonox::Factory::getIdentifier(StringOrInt)
    113105
    114 /**
    115     @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
    116     @param varname The name of the variable
    117     @param defvalue The default-value of the variable
    118 */
    119 #define SetConfigValue(varname, defvalue) \
    120     orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
    121     if (!container##varname) \
    122     { \
    123         container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \
    124         this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
    125     } \
    126     container##varname->getValue(&varname)
    127 
    128 /**
    129     @brief Sets the variable and the config-file entry back to the previously defined default-value.
    130     @param varname The name of the variable
    131 */
    132 #define ResetConfigValue(varname) \
    133     orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
    134     if (container##varname##reset) \
    135     { \
    136         container##varname##reset->reset(); \
    137         container##varname##reset->getValue(&varname); \
    138     } \
    139     else \
    140         COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl
    141 
    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 
    155106#endif /* _CoreIncludes_H__ */
  • code/branches/core2/src/orxonox/core/DebugLevel.cc

    r1023 r1030  
    3333#include "DebugLevel.h"
    3434#include "CoreIncludes.h"
     35#include "ConfigValueIncludes.h"
    3536
    3637namespace orxonox
  • code/branches/core2/src/orxonox/core/Language.cc

    r1023 r1030  
    3535#include "CoreIncludes.h"
    3636#include "Language.h"
     37#include "ConfigValueIncludes.h"
    3738
    3839namespace orxonox
  • code/branches/core2/src/orxonox/core/OutputHandler.cc

    r947 r1030  
    4747        this->logfilename_ = logfilename;
    4848        this->logfile_.open(this->logfilename_.c_str(), std::fstream::out);
    49         this->logfile_ << "Started log" << std::endl;
     49        this->logfile_ << "Started log at yyyy/mm/dd hh:mm:ss" << std::endl;
    5050        this->logfile_.flush();
    5151    }
  • code/branches/core2/src/orxonox/objects/Fighter.cc

    r790 r1030  
    3737#include "util/tinyxml/tinyxml.h"
    3838#include "util/String2Number.h"
    39 #include "../core/CoreIncludes.h"
     39#include "core/CoreIncludes.h"
     40#include "core/ConfigValueIncludes.h"
    4041#include "../Orxonox.h"
    4142#include "../particle/ParticleInterface.h"
  • code/branches/core2/src/orxonox/objects/Projectile.cc

    r995 r1030  
    3030#include "core/CoreIncludes.h"
    3131#include "core/Executor.h"
     32#include "core/ConfigValueIncludes.h"
    3233
    3334#include "SpaceShip.h"
  • code/branches/core2/src/orxonox/objects/SpaceShip.cc

    r955 r1030  
    3939#include "util/String2Number.h"
    4040#include "util/Math.h"
    41 #include "../core/CoreIncludes.h"
    42 #include "../core/Debug.h"
     41#include "core/CoreIncludes.h"
     42#include "core/ConfigValueIncludes.h"
     43#include "core/Debug.h"
    4344#include "../Orxonox.h"
    4445#include "../particle/ParticleInterface.h"
  • code/branches/core2/src/orxonox/objects/test3.cc

    r871 r1030  
    3030#include "test3.h"
    3131#include "core/CoreIncludes.h"
     32#include "core/ConfigValueIncludes.h"
    3233
    3334namespace orxonox
     
    5657        SetConfigValue(value_vector3_, Vector3(13, 26, 39));
    5758        SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887));
     59        SetConfigValueVector(vector_int_, std::vector<int>(1, 13));
     60        SetConfigValueVector(vector_string_, std::vector<std::string>(3, "nothing"));
     61        SetConfigValueVector(vector_vector3_, std::vector<Vector3>(1, Vector3(3, 2, 1)));
    5862    }
    5963
     
    6468    void Test3::configOutput()
    6569    {
    66         std::cout << "int:         " << this->value_int_ << std::endl;
    67         std::cout << "uint:        " << this->value_uint_ << std::endl;
    68         std::cout << "char:        " << (int)this->value_char_ << std::endl;
    69         std::cout << "uchar:       " << (int)this->value_uchar_ << std::endl;
    70         std::cout << "float:       " << this->value_float_ << std::endl;
    71         std::cout << "double:      " << this->value_double_ << std::endl;
    72         std::cout << "bool:        " << this->value_bool_ << std::endl;
    73         std::cout << "string:      " << this->value_string_ << std::endl;
    74         std::cout << "constchar:   " << this->value_constchar_ << std::endl;
    75         std::cout << "vector2:     " << this->value_vector2_ << std::endl;
    76         std::cout << "vector3:     " << this->value_vector3_ << std::endl;
    77         std::cout << "colourvalue: " << this->value_colourvalue_ << std::endl;
     70        std::cout << "int:             " << this->value_int_ << std::endl;
     71        std::cout << "uint:            " << this->value_uint_ << std::endl;
     72        std::cout << "char:            " << (int)this->value_char_ << std::endl;
     73        std::cout << "uchar:           " << (int)this->value_uchar_ << std::endl;
     74        std::cout << "float:           " << this->value_float_ << std::endl;
     75        std::cout << "double:          " << this->value_double_ << std::endl;
     76        std::cout << "bool:            " << this->value_bool_ << std::endl;
     77        std::cout << "string:         >" << this->value_string_ << "<" << std::endl;
     78        std::cout << "constchar:      >" << this->value_constchar_ << "<" << std::endl;
     79        std::cout << "vector2:         " << this->value_vector2_ << std::endl;
     80        std::cout << "vector3:         " << this->value_vector3_ << std::endl;
     81        std::cout << "colourvalue:     " << this->value_colourvalue_ << std::endl;
     82        std::cout << std::endl;
     83        for (unsigned int i = 0; i < this->vector_int_.size(); i++)
     84        std::cout << "vector<int>:     " << i << ": " << this->vector_int_[i] << std::endl;
     85        for (unsigned int i = 0; i < this->vector_string_.size(); i++)
     86        std::cout << "vector<string>:  " << i << ": " << this->vector_string_[i] << std::endl;
     87        for (unsigned int i = 0; i < this->vector_vector3_.size(); i++)
     88        std::cout << "vector<vector3>: " << i << ": " << this->vector_vector3_[i] << std::endl;
    7889    }
    7990
  • code/branches/core2/src/orxonox/objects/test3.h

    r871 r1030  
    11#ifndef _Test3_H__
    22#define _Test3_H__
     3
     4#include <vector>
    35
    46#include "core/BaseObject.h"
     
    3638            Vector3             value_vector3_;
    3739            ColourValue         value_colourvalue_;
     40
     41            std::vector<int>         vector_int_;
     42            std::vector<std::string> vector_string_;
     43            std::vector<Vector3>     vector_vector3_;
    3844    };
    3945}
Note: See TracChangeset for help on using the changeset viewer.