Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 19, 2008, 5:02:45 AM (16 years ago)
Author:
landauf
Message:
  • fixed bug #2 in ConfigValueContainer (callback not being called if the configured value is the same as default value)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/ConfigValueContainer.h

    r1610 r1611  
    9595    {
    9696        public:
    97             ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue);
    98             ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue);
     97            /**
     98                @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
     99                @param type The type of the corresponding config-file
     100                @param identifier The identifier of the class the variable belongs to
     101                @param varname The name of the variable
     102                @param defvalue The default-value
     103                @param value Only needed do determine the right type.
     104            */
     105            template <class D, class V>
     106            ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const D& defvalue, const V& value)
     107            {
     108                this->init(type, identifier, varname);
     109                this->initValue((V)defvalue);
     110            }
     111
     112            /**
     113                @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
     114                @param type The type of the corresponding config-file
     115                @param identifier The identifier of the class the variable belongs to
     116                @param varname The name of the variable
     117                @param defvalue The default-value
     118            */
     119            template <class V>
     120            ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<V>& defvalue)
     121            {
     122                this->init(type, identifier, varname);
     123
     124                this->value_ = V();
     125                for (unsigned int i = 0; i < defvalue.size(); i++)
     126                    this->valueVector_.push_back(MultiTypeMath(defvalue[i]));
     127
     128                this->initVector();
     129            }
     130
    99131            ~ConfigValueContainer();
    100132
    101             /** @brief Returns the configured value. @param value A pointer to the variable to store the value. @return The ConfigValueContainer */
     133            /**
     134                @brief Returns the configured value.
     135                @param value A pointer to the variable to store the value.
     136                @param object The object calling this function
     137                @return The ConfigValueContainer
     138            */
    102139            template <typename T, class C>
    103140            ConfigValueContainer& getValue(T* value, C* object)
    104141            {
    105 std::cout << "start: " << this->getName() << std::endl;
    106142                if ((this->callback_ && object) || this->bContainerIsNew_)
    107143                {
     
    123159                    this->value_.getValue(value);
    124160                }
    125 std::cout << "end" << std::endl;
    126161                return *this;
    127162            }
    128163
    129             /** @brief Returns the configured vector. @param value A pointer to the vector to store the values. @return The ConfigValueContainer */
     164            /**
     165                @brief Returns the configured vector.
     166                @param value A pointer to the vector to store the values.
     167                @param object The object calling this function
     168                @return The ConfigValueContainer
     169            */
    130170            template <typename T, class C>
    131171            ConfigValueContainer& getValue(std::vector<T>* value, C* object)
     
    172212            }
    173213
    174             template <typename T>
    175             inline void setVectorType(const std::vector<T>& value)
    176             {
    177                 this->value_ = T();
    178                 this->update();
    179             }
    180 
     214            /** @brief Returns the name of this container. */
    181215            inline const std::string& getName() const
    182216                { return this->varname_; }
     217            /** @brief Returns true if this config-value is a vector */
    183218            inline bool isVector() const
    184219                { return this->bIsVector_; }
     220            /** @brief Returns the vectors size (or zero if it's not a vector). */
    185221            inline unsigned int getVectorSize() const
    186222                { return this->valueVector_.size(); }
     
    189225            const std::string& getDescription() const;
    190226
     227            /**
     228                @brief Adds a callback function, that gets called after getValue() if the newly assigned value differs from the old value of the variable.
     229                @param object The object to call the function
     230                @param function The callback function
     231            */
    191232            template <class T>
    192233            inline ConfigValueContainer& callback(T* object, void (T::*function) (void))
     
    225266
    226267        private:
     268            void init(ConfigFileType type, Identifier* identifier, const std::string& varname);
     269            void initValue(const MultiTypeMath& defvalue);
     270            void initVector();
    227271            bool callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input);
    228272
Note: See TracChangeset for help on using the changeset viewer.