Changeset 1596 for code/branches/core3/src/core/ConfigValueContainer.h
- Timestamp:
- Jun 12, 2008, 10:53:51 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/core/ConfigValueContainer.h
r1505 r1596 55 55 namespace orxonox 56 56 { 57 class ConfigValueCallbackBase 58 { 59 public: 60 virtual void call(void* object) = 0; 61 inline virtual ~ConfigValueCallbackBase() {} 62 }; 63 64 template <class T> 65 class ConfigValueCallback: public ConfigValueCallbackBase 66 { 67 public: 68 inline ConfigValueCallback(void (T::*function) (void)) : function_(function) {} 69 inline virtual ~ConfigValueCallback() {} 70 inline virtual void call(void* object) 71 { (((T*)object)->*this->function_)(); } 72 73 private: 74 void (T::*function_) (void); 75 }; 76 77 57 78 //! The ConfigValuecontainer contains all needed informations about a configurable variable. 58 79 /** … … 76 97 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue); 77 98 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue); 78 79 /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */ 80 template <typename T> 81 inline ConfigValueContainer& getValue(T* value) 82 { this->value_.getValue(value); return *this; } 83 template <typename T> 84 inline ConfigValueContainer& getValue(std::vector<T>* value) 85 { 86 value->clear(); 87 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 88 value->push_back(this->valueVector_[i]); 99 ~ConfigValueContainer(); 100 101 /** @brief Returns the configured value. @param value A pointer to the variable to store the value. @return The ConfigValueContainer */ 102 template <typename T, class C> 103 ConfigValueContainer& getValue(T* value, C* object) 104 { 105 if (this->callback_ && object) 106 { 107 T temp = *value; 108 this->value_.getValue(value); 109 if ((*value) != temp) 110 this->callback_->call(object); 111 } 112 else 113 { 114 this->value_.getValue(value); 115 } 116 return *this; 117 } 118 119 /** @brief Returns the configured vector. @param value A pointer to the vector to store the values. @return The ConfigValueContainer */ 120 template <typename T, class C> 121 ConfigValueContainer& getValue(std::vector<T>* value, C* object) 122 { 123 if (this->callback_ && object) 124 { 125 std::vector<T> temp = *value; 126 127 value->clear(); 128 for (unsigned int i = 0; i < this->valueVector_.size(); ++i) 129 value->push_back(this->valueVector_[i]); 130 131 if (value->size() != temp.size()) 132 { 133 this->callback_->call(object); 134 } 135 else 136 { 137 for (unsigned int i = 0; i < value->size(); ++i) 138 { 139 if ((*value)[i] != temp[i]) 140 { 141 this->callback_->call(object); 142 break; 143 } 144 } 145 } 146 } 147 else 148 { 149 value->clear(); 150 for (unsigned int i = 0; i < this->valueVector_.size(); ++i) 151 value->push_back(this->valueVector_[i]); 152 } 89 153 return *this; 90 154 } … … 104 168 { return this->valueVector_.size(); } 105 169 106 voiddescription(const std::string& description);170 ConfigValueContainer& description(const std::string& description); 107 171 const std::string& getDescription() const; 172 173 template <class T> 174 inline ConfigValueContainer& callback(void (T::*function) (void)) 175 { 176 if (!this->callback_) 177 this->callback_ = new ConfigValueCallback<T>(function); 178 return (*this); 179 } 108 180 109 181 bool set(const MultiTypeMath& input); … … 142 214 bool bAddedDescription_; //!< True if a description was added 143 215 LanguageEntryLabel description_; //!< The description 216 ConfigValueCallbackBase* callback_; //!< A callback function to call after getValue if the value changed 144 217 }; 145 218 }
Note: See TracChangeset
for help on using the changeset viewer.