[Orxonox-commit 2565] r7270 - code/branches/consolecommands3/src/libraries/core/command

landauf at orxonox.net landauf at orxonox.net
Mon Aug 30 19:52:33 CEST 2010


Author: landauf
Date: 2010-08-30 19:52:33 +0200 (Mon, 30 Aug 2010)
New Revision: 7270

Modified:
   code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
   code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
   code/branches/consolecommands3/src/libraries/core/command/Executor.cc
   code/branches/consolecommands3/src/libraries/core/command/Executor.h
   code/branches/consolecommands3/src/libraries/core/command/Functor.h
Log:
pushFunction() (which explicitly adds a new level to the console command stack) was not forwarded to ConsoleCommandManipulator

also fixed a bug which was caused by pushFunction() with a subsequent call to setFunction(...) because it may have unexpectedly changed the functor of the lower stack levels. now pushFunction() not only copyconstructs the executor, but also the Functor (with a clone() function)

Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc	2010-08-30 17:44:01 UTC (rev 7269)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc	2010-08-30 17:52:33 UTC (rev 7270)
@@ -192,9 +192,9 @@
     void ConsoleCommand::pushFunction(const ExecutorPtr& executor, bool bForce)
     {
         Command command;
-        command.executor_ = this->getExecutor();
+        command.executor_ = this->executor_;
         if (command.executor_)
-            command.functor_ = this->getExecutor()->getFunctor();
+            command.functor_ = this->executor_->getFunctor();
 
         if (this->setFunction(executor, bForce))
             this->commandStack_.push(command);
@@ -203,9 +203,9 @@
     void ConsoleCommand::pushFunction(const FunctorPtr& functor, bool bForce)
     {
         Command command;
-        command.executor_ = this->getExecutor();
+        command.executor_ = this->executor_;
         if (command.executor_)
-            command.functor_ = this->getExecutor()->getFunctor();
+            command.functor_ = this->executor_->getFunctor();
 
         if (this->setFunction(functor, bForce))
             this->commandStack_.push(command);

Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h	2010-08-30 17:44:01 UTC (rev 7269)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h	2010-08-30 17:52:33 UTC (rev 7270)
@@ -141,6 +141,8 @@
                     inline ConsoleCommandManipulator& setFunction(const ExecutorPtr& executor, bool bForce = false)
                         { if (this->command_) { this->command_->setFunction(executor, bForce); } return *this; }
 
+                    inline ConsoleCommandManipulator& pushFunction()
+                        { if (this->command_) { this->command_->pushFunction(); } return *this; }
                     template <class F>
                     inline ConsoleCommandManipulator& pushFunction(F function, bool bForce = false)
                         { if (this->command_) { this->command_->pushFunction(createFunctor(function), bForce); } return *this; }

Modified: code/branches/consolecommands3/src/libraries/core/command/Executor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/Executor.cc	2010-08-30 17:44:01 UTC (rev 7269)
+++ code/branches/consolecommands3/src/libraries/core/command/Executor.cc	2010-08-30 17:52:33 UTC (rev 7270)
@@ -45,6 +45,11 @@
         this->name_ = name;
     }
 
+    Executor::Executor(const Executor& other) : name_(other.name_), defaultValue_(other.defaultValue_)
+    {
+        this->functor_ = other.functor_->clone();
+    }
+
     Executor::~Executor()
     {
     }

Modified: code/branches/consolecommands3/src/libraries/core/command/Executor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/Executor.h	2010-08-30 17:44:01 UTC (rev 7269)
+++ code/branches/consolecommands3/src/libraries/core/command/Executor.h	2010-08-30 17:52:33 UTC (rev 7270)
@@ -43,6 +43,7 @@
     {
         public:
             Executor(const FunctorPtr& functor, const std::string& name = "");
+            Executor(const Executor& other);
             virtual ~Executor();
 
             inline MultiType operator()() const

Modified: code/branches/consolecommands3/src/libraries/core/command/Functor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/Functor.h	2010-08-30 17:44:01 UTC (rev 7269)
+++ code/branches/consolecommands3/src/libraries/core/command/Functor.h	2010-08-30 17:52:33 UTC (rev 7270)
@@ -85,6 +85,8 @@
         public:
             virtual MultiType 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) = 0;
 
+            virtual FunctorPtr clone() = 0;
+
             virtual Type::Enum getType() const = 0;
             virtual unsigned int getParamCount() const = 0;
             virtual bool hasReturnvalue() const = 0;
@@ -268,6 +270,11 @@
                 return detail::FunctorCaller<R, O, isconst, P1, P2, P3, P4, P5>::call(this->functionPointer_, object, param1, param2, param3, param4, param5);
             }
 
+            FunctorPtr clone()
+            {
+                return new FunctorTemplate(*this);
+            }
+
             void evaluateParam(unsigned int index, MultiType& param) const
             {
                 switch (index)




More information about the Orxonox-commit mailing list