[Orxonox-commit 2491] r7198 - in code/branches/consolecommands3/src/libraries: core core/input network
landauf at orxonox.net
landauf at orxonox.net
Sat Aug 21 21:52:13 CEST 2010
Author: landauf
Date: 2010-08-21 21:52:13 +0200 (Sat, 21 Aug 2010)
New Revision: 7198
Modified:
code/branches/consolecommands3/src/libraries/core/BaseObject.h
code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
code/branches/consolecommands3/src/libraries/core/Event.cc
code/branches/consolecommands3/src/libraries/core/Event.h
code/branches/consolecommands3/src/libraries/core/Executor.cc
code/branches/consolecommands3/src/libraries/core/Executor.h
code/branches/consolecommands3/src/libraries/core/Functor.h
code/branches/consolecommands3/src/libraries/core/WeakPtr.h
code/branches/consolecommands3/src/libraries/core/input/InputState.h
code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.cc
code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.h
code/branches/consolecommands3/src/libraries/core/input/KeyDetector.h
code/branches/consolecommands3/src/libraries/network/NetworkFunction.cc
code/branches/consolecommands3/src/libraries/network/NetworkFunction.h
Log:
createFunctor() now returns a SharedPtr instead of a pointer. Adapted code that uses createFunctor() accordingly.
Modified: code/branches/consolecommands3/src/libraries/core/BaseObject.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/BaseObject.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/BaseObject.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -195,7 +195,7 @@
mbool bActive_; //!< True = the object is active
mbool bVisible_; //!< True = the object is visible
std::string mainStateName_;
- Functor* mainStateFunctor_;
+ FunctorPtr mainStateFunctor_;
std::set<std::string> networkTemplateNames_;
private:
Modified: code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc 2010-08-21 19:52:13 UTC (rev 7198)
@@ -33,7 +33,7 @@
namespace orxonox
{
- ConsoleCommand::ConsoleCommand(Functor* functor, const std::string& name) : Executor(functor, name)
+ ConsoleCommand::ConsoleCommand(const FunctorPtr& functor, const std::string& name) : Executor(functor, name)
{
this->accessLevel_ = AccessLevel::None;
this->argumentCompleter_[0] = 0;
@@ -123,7 +123,7 @@
_SetConsoleCommand("BaseObject", "setName", &BaseObject::setName, (BaseObject*)0);
_ConsoleCommand::_ConsoleCommandManipulator test(_ModifyConsoleCommand("BaseObject", "setName").setFunction(&BaseObject::setActive));
- _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
+ _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
{
this->bActive_ = true;
this->bInitialized_ = bInitialized;
@@ -154,7 +154,7 @@
return *this;
}
- bool _ConsoleCommand::setFunctor(Functor* functor, bool bForce)
+ bool _ConsoleCommand::setFunctor(const FunctorPtr& functor, bool bForce)
{
if (!functor)
{
@@ -173,9 +173,9 @@
return true;
}
- void _ConsoleCommand::pushFunctor(Functor* functor, bool bForce)
+ void _ConsoleCommand::pushFunctor(const FunctorPtr& functor, bool bForce)
{
- Functor* oldfunctor = this->getFunctor();
+ const FunctorPtr& oldfunctor = this->getFunctor();
if (this->setFunctor(functor, bForce));
this->functorStack_.push(oldfunctor);
@@ -183,7 +183,7 @@
void _ConsoleCommand::popFunctor()
{
- Functor* newfunctor = 0;
+ FunctorPtr newfunctor;
if (!this->functorStack_.empty())
{
newfunctor = this->functorStack_.top();
@@ -192,15 +192,15 @@
this->setFunctor(newfunctor);
}
- Functor* _ConsoleCommand::getFunctor() const
+ const FunctorPtr& _ConsoleCommand::getFunctor() const
{
- if (this->bInitialized_)
+// if (this->bInitialized_) // FIXME
return this->functor_;
- else
- return 0;
+// else
+// return 0;
}
- bool _ConsoleCommand::functionHeaderMatches(Functor* functor) const
+ bool _ConsoleCommand::functionHeaderMatches(const FunctorPtr& functor) const
{
if (!this->functor_)
{
@@ -215,7 +215,7 @@
if (this->functor_)
this->functor_->setRawObjectPointer(object);
else if (object)
- COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
+ COUT(1) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
}
void _ConsoleCommand::pushObject(void* object)
@@ -226,7 +226,7 @@
this->setObject(object);
}
else
- COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
+ COUT(1) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
}
void _ConsoleCommand::popObject()
@@ -262,9 +262,9 @@
if (bPrintError)
{
if (group == "")
- COUT(0) << "Error: Couldn't find console command with shortcut \"" << name << "\"" << std::endl;
+ COUT(1) << "Error: Couldn't find console command with shortcut \"" << name << "\"" << std::endl;
else
- COUT(0) << "Error: Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << std::endl;
+ COUT(1) << "Error: Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << std::endl;
}
return 0;
}
Modified: code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -87,7 +87,7 @@
class _CoreExport ConsoleCommand : public Executor
{
public:
- ConsoleCommand(Functor* functor, const std::string& name = "");
+ ConsoleCommand(const FunctorPtr& functor, const std::string& name = "");
ConsoleCommand& description(const std::string& description);
const std::string& getDescription() const;
@@ -158,7 +158,7 @@
LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
};
- inline ConsoleCommand* createConsoleCommand(Functor* functor, const std::string& name = "")
+ inline ConsoleCommand* createConsoleCommand(const FunctorPtr& functor, const std::string& name = "")
{
return new ConsoleCommand(functor, name);
}
@@ -211,7 +211,7 @@
template <class F, class O>
inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false)
{ if (this->command_) { this->command_->setFunctor(createFunctor(function, object), bForce); } return *this; }
- inline _ConsoleCommandManipulator& setFunction(Functor* functor, bool bForce = false)
+ inline _ConsoleCommandManipulator& setFunction(const FunctorPtr& functor, bool bForce = false)
{ if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; }
template <class F>
@@ -220,7 +220,7 @@
template <class F, class O>
inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false)
{ if (this->command_) { this->command_->pushFunctor(createFunctor(function, object), bForce); } return *this; }
- inline _ConsoleCommandManipulator& pushFunction(Functor* functor, bool bForce = false)
+ inline _ConsoleCommandManipulator& pushFunction(const FunctorPtr& functor, bool bForce = false)
{ if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; }
inline _ConsoleCommandManipulator& popFunction()
@@ -244,7 +244,7 @@
};
public:
- _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true);
+ _ConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true);
_ConsoleCommand& addShortcut();
_ConsoleCommand& addShortcut(const std::string& name);
@@ -270,12 +270,12 @@
static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
- bool setFunctor(Functor* functor, bool bForce = false);
- void pushFunctor(Functor* functor, bool bForce = false);
+ bool setFunctor(const FunctorPtr& functor, bool bForce = false);
+ void pushFunctor(const FunctorPtr& functor, bool bForce = false);
void popFunctor();
- Functor* getFunctor() const;
+ const FunctorPtr& getFunctor() const;
- bool functionHeaderMatches(Functor* functor) const;
+ bool functionHeaderMatches(const FunctorPtr& functor) const;
void setObject(void* object);
void pushObject(void* object);
@@ -285,16 +285,16 @@
bool bActive_;
bool bInitialized_;
const std::type_info& functionHeader_;
- std::stack<Functor*> functorStack_;
+ std::stack<FunctorPtr> functorStack_;
std::stack<void*> objectStack_;
};
- inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, bool bInitialized = true)
+ inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const FunctorPtr& functor, bool bInitialized = true)
{
return new _ConsoleCommand("", name, functor, bInitialized);
}
- inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true)
+ inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true)
{
return new _ConsoleCommand(group, name, functor, bInitialized);
}
Modified: code/branches/consolecommands3/src/libraries/core/Event.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Event.cc 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/Event.cc 2010-08-21 19:52:13 UTC (rev 7198)
@@ -34,15 +34,6 @@
namespace orxonox
{
/**
- @brief Destructor: Deletes the functor of the event state.
- */
- EventState::~EventState()
- {
- if (this->statefunction_)
- delete this->statefunction_;
- }
-
- /**
@brief Processes an event (calls the set-function if the necessary conditions are met).
@param event The fired event
Modified: code/branches/consolecommands3/src/libraries/core/Event.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Event.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/Event.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -66,18 +66,17 @@
class _CoreExport EventState
{
public:
- EventState(Functor* statefunction, Identifier* subclass, bool bSink = false) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass), bSink_(bSink) {}
- virtual ~EventState();
+ EventState(const FunctorPtr& statefunction, Identifier* subclass, bool bSink = false) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass), bSink_(bSink) {}
void process(const Event& event, BaseObject* object);
- Functor* getFunctor() const
+ const FunctorPtr& getFunctor() const
{ return this->statefunction_; }
private:
bool bProcessingEvent_; //!< This becomes true while the container processes an event (used to prevent loops)
int activeEvents_; //!< The number of events which affect this state and are currently active
- Functor* statefunction_; //!< A functor to set the state
+ FunctorPtr statefunction_; //!< A functor to set the state
Identifier* subclass_; //!< Originators must be an instance of this class (usually BaseObject, but some statefunctions allow a second argument with an originator of a specific class)
bool bSink_; //!< Determines whether the EventState acts as an EventSink forwarding any Event (even if the state didn't change) or in the normal manner, only processing Events that change the state.
};
Modified: code/branches/consolecommands3/src/libraries/core/Executor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.cc 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/Executor.cc 2010-08-21 19:52:13 UTC (rev 7198)
@@ -41,7 +41,7 @@
int Functor::instances_s = 0;
int Executor::instances_s = 0;
- Executor::Executor(Functor* functor, const std::string& name)
+ Executor::Executor(const FunctorPtr& functor, const std::string& name)
{
this->functor_ = functor;
this->name_ = name;
@@ -50,7 +50,6 @@
Executor::~Executor()
{
- delete this->functor_;
--instances_s; COUT(0) << "executor --: " << instances_s << std::endl;
}
Modified: code/branches/consolecommands3/src/libraries/core/Executor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/Executor.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -41,10 +41,8 @@
{
class _CoreExport Executor
{
- friend class SharedPtr<Executor>;
-
public:
- Executor(Functor* functor, const std::string& name = "");
+ Executor(const FunctorPtr& functor, const std::string& name = "");
virtual ~Executor();
inline MultiType operator()() const
@@ -64,7 +62,7 @@
bool evaluate(const std::string& params, MultiType param[5], const std::string& delimiter = " ") const;
- inline Functor* getFunctor() const
+ inline const FunctorPtr& getFunctor() const
{ return this->functor_; }
inline unsigned int getParamCount() const
{ return this->functor_->getParamCount(); }
@@ -107,7 +105,7 @@
}
protected:
- Functor* functor_;
+ FunctorPtr functor_;
std::string name_;
MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS];
@@ -118,7 +116,7 @@
class _CoreExport ExecutorStatic : public Executor
{
public:
- ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {}
+ ExecutorStatic(const FunctorStaticPtr& functor, const std::string& name = "") : Executor(functor, name) {}
virtual ~ExecutorStatic() {}
};
@@ -126,84 +124,83 @@
class ExecutorMember : public Executor
{
public:
- ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {}
+ ExecutorMember(const FunctorMemberPtr<T>& functor, const std::string& name = "") : Executor(functor, name), functorMember_(functor) {}
virtual ~ExecutorMember() {}
using Executor::operator();
inline MultiType operator()(T* object) const
- { return (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(T* object, const MultiType& param1) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, param2, param3, param4, this->defaultValue_[4]); }
inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
+ { return (*this->functorMember_)(object, param1, param2, param3, param4, param5); }
inline MultiType operator()(const T* object) const
- { return (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(const T* object, const MultiType& param1) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
+ { return (*this->functorMember_)(object, param1, param2, param3, param4, this->defaultValue_[4]); }
inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
- { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
+ { return (*this->functorMember_)(object, param1, param2, param3, param4, param5); }
inline void setObject(T* object) const
- { ((FunctorMember<T>*)this->functor_)->setObject(object); }
+ { this->functorMember_->setObject(object); }
inline void setObject(const T* object) const
- { ((FunctorMember<T>*)this->functor_)->setObject(object); }
+ { this->functorMember_->setObject(object); }
using Executor::parse;
MultiType parse(T* object, const std::string& params, bool* success = 0, const std::string& delimiter = " ") const
{
- FunctorMember<T>* functorMember = static_cast<FunctorMember<T>*>(this->functor_);
+ const typename FunctorMember<T>::Objects& objects = this->functorMember_->getObjects();
- const typename FunctorMember<T>::Objects& objects = functorMember->getObjects();
-
- functorMember->setObject(object);
+ this->functorMember_->setObject(object);
const MultiType& result = Executor::parse(params, success, delimiter);
- functorMember->setObjects(objects);
+ this->functorMember_->setObjects(objects);
return result;
}
MultiType parse(const T* object, const std::string& params, bool* success = 0, const std::string& delimiter = " ") const
{
- FunctorMember<T>* functorMember = static_cast<FunctorMember<T>*>(this->functor_);
+ const typename FunctorMember<T>::Objects& objects = this->functorMember_->getObjects();
- const typename FunctorMember<T>::Objects& objects = functorMember->getObjects();
-
- functorMember->setObject(object);
+ this->functorMember_->setObject(object);
const MultiType& result = Executor::parse(params, success, delimiter);
- functorMember->setObjects(objects);
+ this->functorMember_->setObjects(objects);
return result;
}
+
+ protected:
+ FunctorMemberPtr<T> functorMember_;
};
- inline Executor* createExecutor(Functor* functor, const std::string& name = "")
+ inline Executor* createExecutor(const FunctorPtr& functor, const std::string& name = "")
{
return new Executor(functor, name);
}
template <class T>
- inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "")
+ inline ExecutorMember<T>* createExecutor(const FunctorMemberPtr<T>& functor, const std::string& name = "")
{
return new ExecutorMember<T>(functor, name);
}
- inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "")
+ inline ExecutorStatic* createExecutor(const FunctorStaticPtr& functor, const std::string& name = "")
{
return new ExecutorStatic(functor, name);
}
Modified: code/branches/consolecommands3/src/libraries/core/Functor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Functor.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/Functor.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -88,8 +88,6 @@
class _CoreExport Functor
{
- friend class SharedPtr<Functor>;
-
public:
struct Type
{
@@ -214,7 +212,7 @@
- inline Functor* createFunctor(Functor* functor)
+ inline const FunctorPtr& createFunctor(const FunctorPtr& functor)
{
return functor;
}
@@ -423,7 +421,7 @@
\
\
FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \
- inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
+ inline SharedChildPtr<FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams), FunctorStaticPtr> createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
{ \
return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \
}
@@ -516,20 +514,20 @@
\
\
FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
- inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
+ inline SharedChildPtr<FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
{ \
return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
} \
\
\
FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
- inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
+ inline SharedChildPtr<FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
{ \
return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
} \
\
FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
- inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)), O* object) \
+ inline SharedChildPtr<FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)), O* object) \
{ \
FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
functor->setObject(object); \
@@ -538,7 +536,7 @@
\
\
FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
- inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const, O* object) \
+ inline SharedChildPtr<FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const, O* object) \
{ \
FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
functor->setObject(object); \
Modified: code/branches/consolecommands3/src/libraries/core/WeakPtr.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/WeakPtr.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/WeakPtr.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -76,8 +76,6 @@
{
if (this->base_)
this->base_->unregisterWeakPtr(this);
- if (this->callback_)
- delete this->callback_;
}
@@ -167,12 +165,12 @@
WeakPtr().swap(*this);
}
- inline void setCallback(Functor* callback)
+ inline void setCallback(const FunctorPtr& callback)
{
this->callback_ = callback;
}
- inline Functor* getFunctor() const
+ inline const FunctorPtr& getCallback() const
{
return this->callback_;
}
@@ -188,7 +186,7 @@
T* pointer_;
OrxonoxClass* base_;
- Functor* callback_;
+ FunctorPtr callback_;
};
template <class T>
Modified: code/branches/consolecommands3/src/libraries/core/input/InputState.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/input/InputState.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/input/InputState.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -149,9 +149,9 @@
//! Called upon deactivation of the state
void left();
//! Sets a functor to be called upon activation of the state
- void setEnterFunctor(Functor* functor) { this->enterFunctor_ = functor; }
+ void setEnterFunctor(const FunctorPtr& functor) { this->enterFunctor_ = functor; }
//! Sets a functor to be called upon deactivation of the state
- void setLeaveFunctor(Functor* functor) { this->leaveFunctor_ = functor; }
+ void setLeaveFunctor(const FunctorPtr& functor) { this->leaveFunctor_ = functor; }
private:
InputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority);
@@ -171,8 +171,8 @@
std::vector<InputHandler*> handlers_; //!< Vector with all handlers where the index is the device ID
//! Handler to be used for all joy sticks (needs to be saved in case another joy stick gets attached)
InputHandler* joyStickHandlerAll_;
- Functor* enterFunctor_; //!< Functor to be executed on enter
- Functor* leaveFunctor_; //!< Functor to be executed on leave
+ FunctorPtr enterFunctor_; //!< Functor to be executed on enter
+ FunctorPtr leaveFunctor_; //!< Functor to be executed on leave
};
FORCEINLINE void InputState::update(float dt)
Modified: code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.cc 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.cc 2010-08-21 19:52:13 UTC (rev 7198)
@@ -155,7 +155,7 @@
if (!this->bBinding_)
{
COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
- KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this)));
+ KeyDetector::getInstance().setCallback(createFunctor(&KeyBinderManager::keybindKeyPressed, this));
InputManager::getInstance().enterState("detector");
this->command_ = command;
this->bTemporary_ = bTemporary;
Modified: code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -98,7 +98,7 @@
{ this->keybindInternal(command, true); }
void unbind(const std::string& binding); //tolua_export
void tunbind(const std::string& binding);
- inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export
+ inline void registerKeybindCallback(const FunctorPtr& function) { this->callbackFunction_ = function; } // tolua//_//export // <-- FIXME
private:
KeyBinderManager(const KeyBinderManager&);
@@ -113,7 +113,7 @@
std::string defaultFilename_; //! Name of the file with the default key bindings
// keybind command related
- shared_ptr<Functor> callbackFunction_; //! Function to be called when key was pressed after "keybind" command
+ FunctorPtr callbackFunction_; //! Function to be called when key was pressed after "keybind" command
bool bBinding_; //! Tells whether a key binding process is active
bool bTemporary_; //! Stores tkeybind/keybind value
std::string command_; //! Stores the command received by (t)keybind
Modified: code/branches/consolecommands3/src/libraries/core/input/KeyDetector.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/input/KeyDetector.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/core/input/KeyDetector.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -45,7 +45,7 @@
KeyDetector();
~KeyDetector();
- void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; }
+ void setCallback(const FunctorPtr& function) { this->callbackFunction_ = function; }
private:
KeyDetector(const KeyDetector&);
@@ -54,7 +54,7 @@
void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
void assignCommands();
- shared_ptr<Functor> callbackFunction_;
+ FunctorPtr callbackFunction_;
InputState* inputState_;
static std::string callbackCommand_s;
static KeyDetector* singletonPtr_s;
Modified: code/branches/consolecommands3/src/libraries/network/NetworkFunction.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/network/NetworkFunction.cc 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/network/NetworkFunction.cc 2010-08-21 19:52:13 UTC (rev 7198)
@@ -67,7 +67,7 @@
}
- NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
+ NetworkFunctionStatic::NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p):
NetworkFunctionBase(name)
{
RegisterObject(NetworkFunctionStatic);
@@ -77,11 +77,6 @@
NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this;
}
- NetworkFunctionStatic::~NetworkFunctionStatic()
- {
- delete this->functor_;
- }
-
/*static*/ std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& NetworkFunctionStatic::getFunctorMap()
{
static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_;
Modified: code/branches/consolecommands3/src/libraries/network/NetworkFunction.h
===================================================================
--- code/branches/consolecommands3/src/libraries/network/NetworkFunction.h 2010-08-21 19:03:23 UTC (rev 7197)
+++ code/branches/consolecommands3/src/libraries/network/NetworkFunction.h 2010-08-21 19:52:13 UTC (rev 7198)
@@ -101,8 +101,7 @@
class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
public:
- NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p);
- ~NetworkFunctionStatic();
+ NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p);
inline void call(){ (*this->functor_)(); }
inline void call(const MultiType& mt1){ (*this->functor_)(mt1); }
@@ -123,7 +122,7 @@
private:
static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap();
static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap();
- FunctorStatic* functor_;
+ FunctorStaticPtr functor_;
};
@@ -154,8 +153,7 @@
template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase {
public:
- NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p);
- ~NetworkMemberFunction();
+ NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p);
inline void call(uint32_t objectID)
{
@@ -189,17 +187,13 @@
}
private:
- FunctorMember<T>* functor_;
+ FunctorMemberPtr<T> functor_;
};
-template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p):
+template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p):
NetworkMemberFunctionBase(name, p), functor_(functor)
{
}
-template <class T> NetworkMemberFunction<T>::~NetworkMemberFunction()
-{
- delete this->functor_;
-}
template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)
{
More information about the Orxonox-commit
mailing list