[Orxonox-commit 2470] r7177 - code/trunk/src/libraries/core
landauf at orxonox.net
landauf at orxonox.net
Wed Aug 18 01:52:55 CEST 2010
Author: landauf
Date: 2010-08-18 01:52:55 +0200 (Wed, 18 Aug 2010)
New Revision: 7177
Modified:
code/trunk/src/libraries/core/Executor.h
code/trunk/src/libraries/core/Functor.h
Log:
fixed a potential problem introduced in r7158 - calling an executor on a temporary object shouldn't change the internal state of the underlying functor.
Modified: code/trunk/src/libraries/core/Executor.h
===================================================================
--- code/trunk/src/libraries/core/Executor.h 2010-08-17 23:01:31 UTC (rev 7176)
+++ code/trunk/src/libraries/core/Executor.h 2010-08-17 23:52:55 UTC (rev 7177)
@@ -182,26 +182,28 @@
bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
{
- static_cast<FunctorMember<T>*>(this->functor_)->setObject(object);
- if (Executor::parse(params, delimiter))
- return true;
- else
- {
- static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL);
- return false;
- }
+ FunctorMember<T>* functorMember = static_cast<FunctorMember<T>*>(this->functor_);
+
+ const typename FunctorMember<T>::Objects& objects = functorMember->getObjects();
+
+ functorMember->setObject(object);
+ bool result = Executor::parse(params, delimiter);
+ functorMember->setObjects(objects);
+
+ return result;
}
bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const
{
- static_cast<FunctorMember<T>*>(this->functor_)->setObject(object);
- if (Executor::parse(params, delimiter))
- return true;
- else
- {
- static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL);
- return false;
- }
+ FunctorMember<T>* functorMember = static_cast<FunctorMember<T>*>(this->functor_);
+
+ const typename FunctorMember<T>::Objects& objects = functorMember->getObjects();
+
+ functorMember->setObject(object);
+ bool result = Executor::parse(params, delimiter);
+ functorMember->setObjects(objects);
+
+ return result;
}
};
Modified: code/trunk/src/libraries/core/Functor.h
===================================================================
--- code/trunk/src/libraries/core/Functor.h 2010-08-17 23:01:31 UTC (rev 7176)
+++ code/trunk/src/libraries/core/Functor.h 2010-08-17 23:52:55 UTC (rev 7177)
@@ -134,9 +134,8 @@
public:
FunctorMember()
{
- constObject_ = 0;
- object_ = 0;
- bConstObject_ = false;
+ this->object_ = 0;
+ this->constObject_ = 0;
}
virtual ~FunctorMember() {}
@@ -145,46 +144,47 @@
virtual void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null)
{
- if (this->bConstObject_)
- {
- if (this->constObject_)
- (*this)(this->constObject_, param1, param2, param3, param4, param5);
- else
- {
- COUT(1) << "An error occurred in Functor.h:" << std::endl;
- COUT(1) << "Error: No const object set." << std::endl;
- }
- }
+ if (this->object_)
+ (*this)(this->object_, param1, param2, param3, param4, param5);
+ else if (this->constObject_)
+ (*this)(this->constObject_, param1, param2, param3, param4, param5);
else
{
- if (this->object_)
- (*this)(this->object_, param1, param2, param3, param4, param5);
- else
- {
- COUT(1) << "An error occurred in Functor.h:" << std::endl;
- COUT(1) << "Error: No object set." << std::endl;
- }
+ COUT(1) << "An error occurred in Functor.h:" << std::endl;
+ COUT(1) << "Error: No object set." << std::endl;
}
}
- FunctorMember<T>* setObject(T* object)
+ inline FunctorMember<T>* setObject(T* object)
{
- this->bConstObject_ = false;
this->object_ = object;
+ this->constObject_ = 0;
return this;
}
- FunctorMember<T>* setObject(const T* object)
+ inline FunctorMember<T>* setObject(const T* object)
{
- this->bConstObject_ = true;
+ this->object_ = 0;
this->constObject_ = object;
return this;
}
+ typedef std::pair<T*, const T*> Objects;
+
+ inline Objects getObjects() const
+ {
+ return Objects(this->object_, this->constObject_);
+ }
+
+ inline void setObjects(const Objects& objects)
+ {
+ this->object_ = objects.first;
+ this->constObject_ = objects.second;
+ }
+
private:
+ T* object_;
const T* constObject_;
- T* object_;
- bool bConstObject_;
};
More information about the Orxonox-commit
mailing list