[Orxonox-commit 2482] r7189 - in code/branches/consolecommands3/src/libraries: core util

landauf at orxonox.net landauf at orxonox.net
Thu Aug 19 16:57:07 CEST 2010


Author: landauf
Date: 2010-08-19 16:57:06 +0200 (Thu, 19 Aug 2010)
New Revision: 7189

Modified:
   code/branches/consolecommands3/src/libraries/core/CommandEvaluation.cc
   code/branches/consolecommands3/src/libraries/core/CommandEvaluation.h
   code/branches/consolecommands3/src/libraries/core/CommandExecutor.cc
   code/branches/consolecommands3/src/libraries/core/CommandExecutor.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/LuaState.cc
   code/branches/consolecommands3/src/libraries/core/LuaState.h
   code/branches/consolecommands3/src/libraries/core/Shell.cc
   code/branches/consolecommands3/src/libraries/core/TclBind.cc
   code/branches/consolecommands3/src/libraries/core/TclBind.h
   code/branches/consolecommands3/src/libraries/core/TclThreadManager.cc
   code/branches/consolecommands3/src/libraries/core/XMLPort.h
   code/branches/consolecommands3/src/libraries/util/MultiType.h
Log:
changed passing of the returnvalue in the command execution pipeline:
 - Functor: operator() directly returns the returnvalue of the executed function (if any, otherwise a MultiType whose null() function evaluates to true). The returnvalue is no longer stored in the Functor.
 - Executor: The same behavior of operator() like in Functor. Additionally the parse() function returns the returnvalue of the executed function instead of a boolean status. The status can be retrieved by passing a pointer to a bool to the function.
 - CommandExecutor: execute() works like before (returns only a boolean status), but added a new function query() which returns the returnvalue of the executed command. The status of query() can be retrieved by optionally passing an pointer to a bool.
 - CommandEvaluation: same as for CommandExecutor: execute() like before, added query()
 - TclBind::eval() returns the returnvalue of the evaluated tcl command. The status can also be retrieved by passing a pointer to a bool.
 - The Shell prints the returnvalue (if available) of an executed command

 - added a constructor to MultiType to directly create it from an mbool. The mbool will be converted to a bool, so it loses it's internal state.

Modified: code/branches/consolecommands3/src/libraries/core/CommandEvaluation.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/CommandEvaluation.cc	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/CommandEvaluation.cc	2010-08-19 14:57:06 UTC (rev 7189)
@@ -73,14 +73,25 @@
 
     bool CommandEvaluation::execute() const
     {
+        bool success;
+        this->query(&success);
+        return success;
+    }
+
+    MultiType CommandEvaluation::query(bool* success) const
+    {
+        if (success)
+            *success = false;
+
         if (!this->isValid())
-            return false;
+            return MT_Type::Null;
 
         if (this->bEvaluatedParams_ && this->function_)
         {
+            if (success)
+                *success = true;
             COUT(6) << "CE_execute (evaluation): " << this->function_->getName() << ' ' << this->param_[0] << ' ' << this->param_[1] << ' ' << this->param_[2] << ' ' << this->param_[3] << ' ' << this->param_[4] << std::endl;
-            (*this->function_)(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);
-            return true;
+            return (*this->function_)(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);
         }
 
         if (!this->bCommandChanged_ || nocaseCmp(removeTrailingWhitespaces(this->command_), removeTrailingWhitespaces(this->originalCommand_)) == 0)
@@ -89,12 +100,12 @@
 
             unsigned int startindex = this->getStartindex();
             if (this->commandTokens_.size() > startindex)
-                return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()));
+                return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()), success);
             else
-                return this->function_->parse(removeSlashes(this->additionalParameter_));
+                return this->function_->parse(removeSlashes(this->additionalParameter_), success);
         }
 
-        return false;
+        return MT_Type::Null;
     }
 
     const std::string& CommandEvaluation::complete()
@@ -232,23 +243,6 @@
         return MT_Type::Null;
     }
 
-    bool CommandEvaluation::hasReturnvalue() const
-    {
-        if (this->function_)
-            return this->function_->hasReturnvalue();
-
-        return MT_Type::Null;
-    }
-
-    MultiType CommandEvaluation::getReturnvalue() const
-    {
-        if (this->function_)
-            return this->function_->getReturnvalue();
-
-        return MultiType();
-    }
-
-
     unsigned int CommandEvaluation::getStartindex() const
     {
         if (this->functionclass_ && this->function_)

Modified: code/branches/consolecommands3/src/libraries/core/CommandEvaluation.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/CommandEvaluation.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/CommandEvaluation.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -65,6 +65,8 @@
             void initialize(const std::string& command);
 
             bool execute() const;
+            MultiType query(bool* success = 0) const;
+
             const std::string& complete();
             std::string hint() const;
             void evaluateParams();
@@ -86,9 +88,6 @@
             void setEvaluatedParameter(unsigned int index, MultiType param);
             MultiType getEvaluatedParameter(unsigned int index) const;
 
-            bool hasReturnvalue() const;
-            MultiType getReturnvalue() const;
-
         private:
             unsigned int getStartindex() const;
             static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);

Modified: code/branches/consolecommands3/src/libraries/core/CommandExecutor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/CommandExecutor.cc	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/CommandExecutor.cc	2010-08-19 14:57:06 UTC (rev 7189)
@@ -103,20 +103,42 @@
     bool CommandExecutor::execute(const std::string& command, bool useTcl)
     {
         if (useTcl)
-            return TclBind::eval(command);
-
-        CommandExecutor::parseIfNeeded(command);
-        return CommandExecutor::getEvaluation().execute();
+        {
+            bool success;
+            TclBind::eval(command, &success);
+            return success;
+        }
+        else
+        {
+            CommandExecutor::parseIfNeeded(command);
+            return CommandExecutor::getEvaluation().execute();
+        }
     }
 
-    MultiType CommandExecutor::getReturnValue()
+    MultiType CommandExecutor::queryMT(const std::string& command, bool* success, bool useTcl)
     {
-        return CommandExecutor::getEvaluation().getReturnvalue();
+        if (useTcl)
+        {
+            return TclBind::eval(command, success);
+        }
+        else
+        {
+            CommandExecutor::parseIfNeeded(command);
+            return CommandExecutor::getEvaluation().query(success);
+        }
     }
 
-    std::string CommandExecutor::getReturnValueString()
+    std::string CommandExecutor::query(const std::string& command, bool* success, bool useTcl)
     {
-        return CommandExecutor::getEvaluation().getReturnvalue().getString();
+        if (useTcl)
+        {
+            return TclBind::eval(command, success);
+        }
+        else
+        {
+            CommandExecutor::parseIfNeeded(command);
+            return CommandExecutor::getEvaluation().query(success).getString();
+        }
     }
 
     std::string CommandExecutor::complete(const std::string& command)

Modified: code/branches/consolecommands3/src/libraries/core/CommandExecutor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/CommandExecutor.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/CommandExecutor.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -46,9 +46,10 @@
 // tolua_end
         public:
             static bool execute(const std::string& command, bool useTcl = true); // tolua_export
-            static MultiType getReturnValue();
-            static std::string getReturnValueString(); // tolua_export
 
+            static MultiType queryMT(const std::string& command, bool* success = 0, bool useTcl = true);
+            static std::string query(const std::string& command, bool* success = 0, bool useTcl = true); // tolua_export
+
             static std::string complete(const std::string& command);
             static std::string hint(const std::string& command);
 

Modified: code/branches/consolecommands3/src/libraries/core/Executor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.cc	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/Executor.cc	2010-08-19 14:57:06 UTC (rev 7189)
@@ -49,14 +49,17 @@
         delete this->functor_;
     }
 
-    bool Executor::parse(const std::string& params, const std::string& delimiter) const
+    MultiType Executor::parse(const std::string& params, bool* success, const std::string& delimiter) const
     {
+        if (success)
+            *success = true;
+
         unsigned int paramCount = this->functor_->getParamCount();
 
         if (paramCount == 0)
         {
             COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl;
-            (*this->functor_)();
+            return (*this->functor_)();
         }
         else if (paramCount == 1)
         {
@@ -64,17 +67,19 @@
             if (!temp.empty())
             {
                 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl;
-                (*this->functor_)(MultiType(params));
+                return (*this->functor_)(MultiType(params));
             }
             else if (!this->defaultValue_[0].null())
             {
                 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl;
-                (*this->functor_)(this->defaultValue_[0]);
+                return (*this->functor_)(this->defaultValue_[0]);
             }
             else
             {
                 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl;
-                return false;
+                if (success)
+                    *success = false;
+                return MT_Type::Null;
             }
         }
         else
@@ -86,7 +91,9 @@
                 if (this->defaultValue_[i].null())
                 {
                     COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl;
-                    return false;
+                    if (success)
+                        *success = false;
+                    return MT_Type::Null;
                 }
             }
 
@@ -119,21 +126,17 @@
             switch(paramCount)
             {
                 case 2:
-                    (*this->functor_)(param[0], param[1]);
-                    break;
+                    return (*this->functor_)(param[0], param[1]);
                 case 3:
-                    (*this->functor_)(param[0], param[1], param[2]);
-                    break;
+                    return (*this->functor_)(param[0], param[1], param[2]);
                 case 4:
-                    (*this->functor_)(param[0], param[1], param[2], param[3]);
-                    break;
+                    return (*this->functor_)(param[0], param[1], param[2], param[3]);
                 case 5:
-                    (*this->functor_)(param[0], param[1], param[2], param[3], param[4]);
-                    break;
+                    return (*this->functor_)(param[0], param[1], param[2], param[3], param[4]);
             }
         }
 
-        return true;
+        return MT_Type::Null;
     }
 
     bool Executor::evaluate(const std::string& params, MultiType param[5], const std::string& delimiter) const

Modified: code/branches/consolecommands3/src/libraries/core/Executor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/Executor.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -44,20 +44,20 @@
             Executor(Functor* functor, const std::string& name = "");
             virtual ~Executor();
 
-            inline void operator()() const
-                { (*this->functor_)(this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const MultiType& param1) const
-                { (*this->functor_)(param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const MultiType& param1, const MultiType& param2) const
-                { (*this->functor_)(param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3) const
-                { (*this->functor_)(param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
-                { (*this->functor_)(param1, param2, param3, param4, this->defaultValue_[4]); }
-            inline void operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
-                { (*this->functor_)(param1, param2, param3, param4, param5); }
+            inline MultiType operator()() const
+                { return (*this->functor_)(this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+            inline MultiType operator()(const MultiType& param1) const
+                { return (*this->functor_)(param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+            inline MultiType operator()(const MultiType& param1, const MultiType& param2) const
+                { return (*this->functor_)(param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
+            inline MultiType operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3) const
+                { return (*this->functor_)(param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
+            inline MultiType operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
+                { return (*this->functor_)(param1, param2, param3, param4, this->defaultValue_[4]); }
+            inline MultiType operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
+                { return (*this->functor_)(param1, param2, param3, param4, param5); }
 
-            bool parse(const std::string& params, const std::string& delimiter = " ") const;
+            MultiType parse(const std::string& params, bool* success = 0, const std::string& delimiter = " ") const;
 
             bool evaluate(const std::string& params, MultiType param[5], const std::string& delimiter = " ") const;
 
@@ -69,8 +69,6 @@
                 { return this->functor_->hasReturnvalue(); }
             inline Functor::Type::Enum getType() const
                 { return this->functor_->getType(); }
-            inline const MultiType& getReturnvalue() const
-                { return this->functor_->getReturnvalue(); }
             inline std::string getTypenameParam(unsigned int param) const
                 { return this->functor_->getTypenameParam(param); }
             inline std::string getTypenameReturnvalue() const
@@ -127,32 +125,32 @@
 
             using Executor::operator();
 
-            inline void operator()(T* object) const
-                { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(T* object, const MultiType& param1) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(T* object, const MultiType& param1, const MultiType& param2) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
-            inline void operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
+            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]); }
+            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]); }
+            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]); }
+            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]); }
+            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]); }
+            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); }
 
 
-            inline void operator()(const T* object) const
-                { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const T* object, const MultiType& param1) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const T* object, const MultiType& param1, const MultiType& param2) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
-            inline void operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
-                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
-            inline void operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
-                { (*((FunctorMember<T>*)this->functor_))(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]); }
+            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]); }
+            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]); }
+            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]); }
+            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]); }
+            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); }
 
             inline void setObject(T* object) const
                 { ((FunctorMember<T>*)this->functor_)->setObject(object); }
@@ -161,27 +159,27 @@
 
             using Executor::parse;
 
-            bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
+            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 = functorMember->getObjects();
 
                 functorMember->setObject(object);
-                bool result = Executor::parse(params, delimiter);
+                const MultiType& result = Executor::parse(params, success, delimiter);
                 functorMember->setObjects(objects);
 
                 return result;
             }
 
-            bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const
+            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 = functorMember->getObjects();
 
                 functorMember->setObject(object);
-                bool result = Executor::parse(params, delimiter);
+                const MultiType& result = Executor::parse(params, success, delimiter);
                 functorMember->setObjects(objects);
 
                 return result;

Modified: code/branches/consolecommands3/src/libraries/core/Functor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Functor.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/Functor.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -103,10 +103,8 @@
             Functor() {}
             virtual ~Functor() {}
 
-            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) = 0;
+            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;
 
-            inline const MultiType& getReturnvalue() const { return this->returnedValue_; }
-
             virtual Type::Enum getType() const = 0;
             virtual unsigned int getParamCount() const = 0;
             virtual bool hasReturnvalue() const = 0;
@@ -120,16 +118,13 @@
             virtual void* getRawObjectPointer() const { return 0; }
 
             virtual const std::type_info& getHeaderIdentifier() const = 0;
-
-        protected:
-            MultiType returnedValue_;
     };
 
     class _CoreExport FunctorStatic : public Functor
     {
         public:
             virtual ~FunctorStatic() {}
-            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) = 0;
+            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;
     };
 
     template <class T>
@@ -143,19 +138,20 @@
             }
             virtual ~FunctorMember() {}
 
-            virtual void operator()(T* object, 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 void operator()(const T* object, 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 MultiType operator()(T* object, 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 MultiType operator()(const T* object, 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 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)
+            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)
             {
                 if (this->object_)
-                    (*this)(this->object_, param1, param2, param3, param4, param5);
+                    return (*this)(this->object_, param1, param2, param3, param4, param5);
                 else if (this->constObject_)
-                    (*this)(this->constObject_, param1, param2, param3, param4, param5);
+                    return (*this)(this->constObject_, param1, param2, param3, param4, param5);
                 else
                 {
                     COUT(1) << "An error occurred in Functor.h:" << std::endl;
                     COUT(1) << "Error: No object set." << std::endl;
+                    return MT_Type::Null;
                 }
             }
 
@@ -339,8 +335,8 @@
 #define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5
 
 #define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall)
-#define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall
-#define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall
+#define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall; return MT_Type::Null
+#define FUNCTOR_STORE_RETURNVALUE1(functioncall) return functioncall
 
 
 
@@ -394,7 +390,7 @@
                 this->functionPointer_ = functionPointer; \
             } \
     \
-            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) \
+            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) \
             { \
                 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
             } \
@@ -440,15 +436,16 @@
                 this->functionPointer_ = functionPointer; \
             } \
     \
-            void operator()(T* object, 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) \
+            MultiType operator()(T* object, 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) \
             { \
                 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
             } \
     \
-            void operator()(const T* object, 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) \
+            MultiType operator()(const T* object, 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) \
             { \
                 COUT(1) << "An error occurred in Functor.h:" << std::endl; \
                 COUT(1) << "Error: Function is not const." << std::endl; \
+                return MT_Type::Null; \
             } \
     \
             void evaluateParam(unsigned int index, MultiType& param) const \
@@ -481,12 +478,12 @@
                 this->functionPointer_ = functionPointer; \
             } \
     \
-            void operator()(T* object, 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) \
+            MultiType operator()(T* object, 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) \
             { \
                 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
             } \
     \
-            void operator()(const T* object, 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) \
+            MultiType operator()(const T* object, 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) \
             { \
                 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
             } \

Modified: code/branches/consolecommands3/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/LuaState.cc	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/LuaState.cc	2010-08-19 14:57:06 UTC (rev 7189)
@@ -369,8 +369,9 @@
         this->lua_ = luaState;
     }
 
-    void LuaFunctor::operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
+    MultiType LuaFunctor::operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
     {
         lua_->doString(this->code_);
+        return MT_Type::Null;
     }
 }

Modified: code/branches/consolecommands3/src/libraries/core/LuaState.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/LuaState.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/LuaState.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -51,7 +51,7 @@
     {
         public:
             LuaFunctor(const std::string& code, LuaState* luaState);
-            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);
+            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);
             void evaluateParam(unsigned int index, MultiType& param) const {}
 
             Functor::Type::Enum getType() const { return Functor::Type::Lua; } \

Modified: code/branches/consolecommands3/src/libraries/core/Shell.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Shell.cc	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/Shell.cc	2010-08-19 14:57:06 UTC (rev 7189)
@@ -307,11 +307,18 @@
         this->addToHistory(this->inputBuffer_->get());
         this->updateListeners<&ShellListener::executed>();
 
-        if (!CommandExecutor::execute(this->inputBuffer_->get()))
+        bool success;
+        const std::string& result = CommandExecutor::query(this->inputBuffer_->get(), &success);
+        if (!success)
         {
             this->outputBuffer_ << "Error: Can't execute \"" << this->inputBuffer_->get() << "\"." << std::endl;
             this->outputChanged(Error);
         }
+        else if (result != "")
+        {
+            this->outputBuffer_ << result << std::endl;
+            this->outputChanged(Command);
+        }
 
         this->clearInput();
     }

Modified: code/branches/consolecommands3/src/libraries/core/TclBind.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/TclBind.cc	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/TclBind.cc	2010-08-19 14:57:06 UTC (rev 7189)
@@ -133,15 +133,14 @@
 
         const std::string& command = stripEnclosingBraces(args.get());
 
-        if (!CommandExecutor::execute(command, false))
+        bool success;
+        const std::string& result = CommandExecutor::query(command, &success, false);
+        if (!success)
         {
             COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
         }
 
-        if (CommandExecutor::getLastEvaluation().hasReturnvalue())
-            return CommandExecutor::getLastEvaluation().getReturnvalue().getString();
-
-        return "";
+        return result;
     }
 
     void TclBind::tcl_execute(Tcl::object const &args)
@@ -180,16 +179,20 @@
         COUT(1) << "Tcl background error: " << stripEnclosingBraces(error) << std::endl;
     }
 
-    bool TclBind::eval(const std::string& tclcode)
+    std::string TclBind::eval(const std::string& tclcode, bool* success)
     {
+        if (success)
+            *success = true;
+
         try
         {
-            TclBind::getInstance().interpreter_->eval(tclcode);
-            return true;
+            return TclBind::getInstance().interpreter_->eval(tclcode);
         }
         catch (Tcl::tcl_error const &e)
         {   COUT(1) << "Tcl error: " << e.what() << std::endl;   }
 
-        return false;
+        if (success)
+            *success = false;
+        return "";
     }
 }

Modified: code/branches/consolecommands3/src/libraries/core/TclBind.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/TclBind.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/TclBind.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -58,7 +58,7 @@
             static std::string tcl_query(Tcl::object const &args);
             static void tcl_execute(Tcl::object const &args);
 
-            static bool eval(const std::string& tclcode);
+            static std::string eval(const std::string& tclcode, bool* success = 0);
 
         private:
             TclBind(const TclBind& other);

Modified: code/branches/consolecommands3/src/libraries/core/TclThreadManager.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/TclThreadManager.cc	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/TclThreadManager.cc	2010-08-19 14:57:06 UTC (rev 7189)
@@ -438,11 +438,10 @@
                     {
                         // It's a query to the CommandExecutor
                         TclThreadManager::debug("TclThread_query -> CE: " + command);
-                        if (!CommandExecutor::execute(command, false))
+                        bool success;
+                        output = CommandExecutor::query(command, &success, false);
+                        if (!success)
                             TclThreadManager::error("Error: Can't execute command \"" + command + "\"!");
-
-                        if (CommandExecutor::getLastEvaluation().hasReturnvalue())
-                            output = CommandExecutor::getLastEvaluation().getReturnvalue().getString();
                     }
                     else
                     {

Modified: code/branches/consolecommands3/src/libraries/core/XMLPort.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/XMLPort.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/core/XMLPort.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -397,7 +397,9 @@
                         if ((!attributeValue.empty()) || ((mode != XMLPort::ExpandObject) && this->loadexecutor_->allDefaultValuesSet()))
                         {
                             COUT(5) << this->owner_->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->identifier_->getName() << " (objectname " << this->owner_->getName() << ")." << std::endl << this->owner_->getLoaderIndentation();
-                            if (this->loadexecutor_->parse(object, attributeValue, ",") || (mode  == XMLPort::ExpandObject))
+                            bool success;
+                            this->loadexecutor_->parse(object, attributeValue, &success, ",");
+                            if (success || (mode  == XMLPort::ExpandObject))
                                 this->parseResult_ = PR_finished;
                             else
                                 this->parseResult_ = PR_waiting_for_default_values;

Modified: code/branches/consolecommands3/src/libraries/util/MultiType.h
===================================================================
--- code/branches/consolecommands3/src/libraries/util/MultiType.h	2010-08-19 11:23:43 UTC (rev 7188)
+++ code/branches/consolecommands3/src/libraries/util/MultiType.h	2010-08-19 14:57:06 UTC (rev 7189)
@@ -77,6 +77,7 @@
 #include <OgreColourValue.h>
 
 #include "TypeTraits.h"
+#include "mbool.h"
 
 namespace orxonox
 {
@@ -265,6 +266,7 @@
             inline MultiType(const orxonox::Quaternion& value)  : value_(0) { this->assignValue(value); }           /** @brief Constructor: Assigns the given value and sets the type. */
             inline MultiType(const orxonox::Radian& value)      : value_(0) { this->assignValue(value); }           /** @brief Constructor: Assigns the given value and sets the type. */
             inline MultiType(const orxonox::Degree& value)      : value_(0) { this->assignValue(value); }           /** @brief Constructor: Assigns the given value and sets the type. */
+            inline MultiType(const orxonox::mbool& value)       : value_(0) { this->assignValue((bool)value); }     /** @brief Constructor: Assigns the given mbool and converts it to bool. */
             inline MultiType(const char* value)                 : value_(0) { this->setValue(std::string(value)); } /** @brief Constructor: Converts the char array to a std::string, assigns the value and sets the type. */
             inline MultiType(const MultiType& other)            : value_(0) { this->setValue(other); }              /** @brief Copyconstructor: Assigns value and type of the other MultiType. */
             inline MultiType(MT_Type::Value type)               : value_(0) { this->setType(type); }                /** @brief Constructor: Sets the type, the next assignment will determine the value. */




More information about the Orxonox-commit mailing list