Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1611


Ignore:
Timestamp:
Jun 19, 2008, 5:02:45 AM (17 years ago)
Author:
landauf
Message:
  • fixed bug #2 in ConfigValueContainer (callback not being called if the configured value is the same as default value)
Location:
code/branches/core3/src
Files:
5 edited

Legend:

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

    r1610 r1611  
    4747{
    4848    /**
    49         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    50         @param type The type of the corresponding config-file
    51         @param identifier The identifier of the class the variable belongs to
    52         @param varname The name of the variable
    53         @param defvalue The default-value
    54     */
    55     ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue)
     49        @brief Initializes the ConfigValueContainer with defaultvalues.
     50    */
     51    void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& varname)
    5652    {
    5753        this->type_ = type;
     
    6359        this->bDoInitialCallback_ = false;
    6460        this->bAddedDescription_ = false;
    65 
     61    }
     62
     63    /**
     64        @brief Does some special initialization for single config-values.
     65    */
     66    void ConfigValueContainer::initValue(const MultiTypeMath& defvalue)
     67    {
    6668        this->value_ = defvalue;
    6769        this->bIsVector_ = false;
    6870
    69         this->defvalueString_ = defvalue.toString();
     71        this->defvalueString_ = this->value_.toString();
    7072        this->update();
    7173    }
    7274
    7375    /**
    74         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    75         @param type The type of the corresponding config-file
    76         @param identifier The identifier of the class the variable belongs to
    77         @param varname The name of the variable
    78         @param defvalue The default-value
    79     */
    80     ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue)
    81     {
    82         this->type_ = type;
    83         this->identifier_ = identifier;
    84         this->sectionname_ = identifier->getName();
    85         this->varname_ = varname;
    86         this->callback_ = 0;
    87         this->bContainerIsNew_ = true;
    88         this->bDoInitialCallback_ = false;
    89         this->bAddedDescription_ = false;
    90 
    91         this->valueVector_ = defvalue;
     76        @brief Does some special initialization for vector config-values.
     77    */
     78    void ConfigValueContainer::initVector()
     79    {
    9280        this->bIsVector_ = true;
    9381
    94         if (defvalue.size() > 0)
    95         {
    96                 this->value_ = defvalue[0];
    97 
    98             for (unsigned int i = 0; i < defvalue.size(); i++)
    99             {
    100                 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string));
    101                 this->defvalueStringVector_.push_back(defvalue[i].toString());
    102             }
    103 
    104             this->update();
    105         }
     82        for (unsigned int i = 0; i < this->valueVector_.size(); i++)
     83        {
     84            ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i].toString(), this->value_.isA(MT_string));
     85            this->defvalueStringVector_.push_back(this->valueVector_[i].toString());
     86        }
     87
     88        this->update();
    10689    }
    10790
  • 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
  • code/branches/core3/src/core/ConfigValueIncludes.h

    r1596 r1611  
    4747    @param defvalue The default-value of the variable
    4848*/
    49 #define SetConfigValue(varname, defvalue) \
     49#define SetConfigValueGeneric(type, varname, defvalue) \
    5050    static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
    5151    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
    5252    if (!container##varname) \
    5353    { \
    54         container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, varname = defvalue); \
     54        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, defvalue, varname); \
    5555        identifier##varname->addConfigValueContainer(#varname, container##varname); \
    5656    } \
    5757    container##varname->getValue(&varname, this)
    5858
    59 /**
    60     @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
    61     @param classname name in which the config value should be stored
    62     @param varname The name of the variable
    63     @param defvalue The default-value of the variable
    64 */
    65 #define SetConfigValueGeneric(classname, varname, defvalue) \
    66     static orxonox::Identifier* identifier##varname = ClassIdentifier<classname>::getIdentifier(); \
    67     orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
    68     if (!container##varname) \
    69     { \
    70         container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, varname = defvalue); \
    71         identifier##varname->addConfigValueContainer(#varname, container##varname); \
    72     } \
    73     container##varname->getValue(&varname, this)
     59#define SetConfigValue(varname, defvalue) SetConfigValueGeneric(CFT_Settings, varname, defvalue)
     60#define SetKeybindingValue(varname, defvalue) SetConfigValueGeneric(CFT_Keybindings, varname, defvalue)
     61
    7462
    7563/**
     
    7866    @param defvalue The default-value
    7967*/
    80 #define SetConfigValueVector(varname, defvalue) \
     68#define SetConfigValueVectorGeneric(type, varname, defvalue) \
    8169    static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
    8270    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
    8371    if (!container##varname) \
    8472    { \
    85         std::vector<MultiTypeMath> temp; \
    86         for (unsigned int i = 0; i < defvalue.size(); i++) \
    87             temp.push_back(MultiTypeMath(defvalue[i])); \
    88         container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, temp); \
    89         container##varname->setVectorType(varname); \
     73        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, defvalue); \
    9074        identifier##varname->addConfigValueContainer(#varname, container##varname); \
    9175    } \
    9276    container##varname->getValue(&varname, this)
     77
     78#define SetConfigValueVector(varname, defvalue) SetConfigValueVectorGeneric(CFT_Settings, varname, defvalue)
     79#define SetKeybindingValueVector(varname, defvalue) SetConfigValueVectorGeneric(CFT_Keybindings, varname, defvalue)
     80
    9381
    9482/**
     
    10795        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
    10896    }
     97
    10998
    11099/**
  • code/branches/core3/src/core/input/KeyBinder.cc

    r1597 r1611  
    268268    if (!cont)
    269269    {
    270       cont = new ConfigValueContainer(CFT_Keybindings, ClassIdentifier<KeyBinder>::getIdentifier(), button.name_, "");
     270      cont = new ConfigValueContainer(CFT_Keybindings, ClassIdentifier<KeyBinder>::getIdentifier(), button.name_, "", button.name_);
    271271      ClassIdentifier<KeyBinder>::getIdentifier()->addConfigValueContainer(button.name_, cont);
    272272    }
  • code/branches/core3/src/orxonox/objects/WorldEntity.cc

    r1610 r1611  
    112112        BaseObject::XMLPort(xmlelement, mode);
    113113
    114 std::cout << "111111111111111\n";
    115114        XMLPortParamExternTemplate(WorldEntity, Ogre::Node, this->node_, "position", setPosition, getPosition, xmlelement, mode, Ogre::Node, const Vector3&);
    116 std::cout << "222222222222222\n";
    117115        XMLPortParamLoadOnly(WorldEntity, "direction", setDirectionSimple, xmlelement, mode);
    118116        XMLPortParamLoadOnly(WorldEntity, "yawpitchroll", setYawPitchRoll, xmlelement, mode);
Note: See TracChangeset for help on using the changeset viewer.