Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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 ;)

File:
1 edited

Legend:

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