[Orxonox-commit 2479] r7186 - code/branches/consolecommands3/src/libraries/core

landauf at orxonox.net landauf at orxonox.net
Thu Aug 19 02:14:55 CEST 2010


Author: landauf
Date: 2010-08-19 02:14:54 +0200 (Thu, 19 Aug 2010)
New Revision: 7186

Modified:
   code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
   code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
   code/branches/consolecommands3/src/libraries/core/Executor.cc
   code/branches/consolecommands3/src/libraries/core/Executor.h
   code/branches/consolecommands3/src/libraries/core/Language.cc
   code/branches/consolecommands3/src/libraries/core/Language.h
   code/branches/consolecommands3/src/libraries/core/XMLPort.h
Log:
Moved ability to possess descriptions from Executor to ConsoleCommand, since no other executors use this feature. Also simplified this code a little by introducing a new shortcut in Language.h. XMLPort has to use a temporary solution for descriptions without Language support atm.

Modified: code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc	2010-08-19 00:11:28 UTC (rev 7185)
+++ code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc	2010-08-19 00:14:54 UTC (rev 7186)
@@ -29,6 +29,8 @@
 #include "ConsoleCommand.h"
 #include <cassert>
 
+#include "Language.h"
+
 namespace orxonox
 {
     ConsoleCommand::ConsoleCommand(Functor* functor, const std::string& name) : Executor(functor, name)
@@ -70,6 +72,48 @@
         else
             this->argumentList_.clear();
     }
+
+    ConsoleCommand& ConsoleCommand::description(const std::string& description)
+    {
+        this->description_ = std::string("ConsoleCommandDescription::" + this->name_ + "::function");
+        AddLanguageEntry(this->description_, description);
+        return (*this);
+    }
+
+    const std::string& ConsoleCommand::getDescription() const
+    {
+        return GetLocalisation_noerror(this->description_);
+    }
+
+    ConsoleCommand& ConsoleCommand::descriptionParam(unsigned int param, const std::string& description)
+    {
+        if (param < MAX_FUNCTOR_ARGUMENTS)
+        {
+            this->descriptionParam_[param] = std::string("ConsoleCommandDescription::" + this->name_ + "::param" + multi_cast<std::string>(param));
+            AddLanguageEntry(this->descriptionParam_[param], description);
+        }
+        return (*this);
+    }
+
+    const std::string& ConsoleCommand::getDescriptionParam(unsigned int param) const
+    {
+        if (param < MAX_FUNCTOR_ARGUMENTS)
+            return GetLocalisation_noerror(this->descriptionParam_[param]);
+
+        return this->descriptionParam_[0];
+    }
+
+    ConsoleCommand& ConsoleCommand::descriptionReturnvalue(const std::string& description)
+    {
+        this->descriptionReturnvalue_ = std::string("ConsoleCommandDescription::" + this->name_ + "::returnvalue");
+        AddLanguageEntry(this->descriptionReturnvalue_, description);
+        return (*this);
+    }
+
+    const std::string& ConsoleCommand::getDescriptionReturnvalue(int param) const
+    {
+        return GetLocalisation_noerror(this->descriptionReturnvalue_);
+    }
 }
 
 #include "BaseObject.h" // remove this

Modified: code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h	2010-08-19 00:11:28 UTC (rev 7185)
+++ code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h	2010-08-19 00:14:54 UTC (rev 7186)
@@ -89,12 +89,15 @@
         public:
             ConsoleCommand(Functor* functor, const std::string& name = "");
 
-            inline ConsoleCommand& description(const std::string& description)
-                { this->Executor::setDescription(description); return (*this); }
-            inline ConsoleCommand& descriptionParam(int param, const std::string& description)
-                { this->Executor::setDescriptionParam(param, description); return (*this); }
-            inline ConsoleCommand& descriptionReturnvalue(const std::string& description)
-                { this->Executor::setDescriptionReturnvalue(description); return (*this); }
+            ConsoleCommand& description(const std::string& description);
+            const std::string& getDescription() const;
+
+            ConsoleCommand& descriptionParam(unsigned int param, const std::string& description);
+            const std::string& getDescriptionParam(unsigned int param) const;
+
+            ConsoleCommand& descriptionReturnvalue(const std::string& description);
+            const std::string& getDescriptionReturnvalue(int param) const;
+
             inline ConsoleCommand& defaultValues(const MultiType& param1)
                 { this->Executor::setDefaultValues(param1); return (*this); }
             inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2)
@@ -149,6 +152,10 @@
 
             KeybindMode::Value keybindMode_;
             int inputConfiguredParam_;
+
+            LanguageEntryLabel description_;
+            LanguageEntryLabel descriptionReturnvalue_;
+            LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
     };
 
     inline ConsoleCommand* createConsoleCommand(Functor* functor, const std::string& name = "")

Modified: code/branches/consolecommands3/src/libraries/core/Executor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.cc	2010-08-19 00:11:28 UTC (rev 7185)
+++ code/branches/consolecommands3/src/libraries/core/Executor.cc	2010-08-19 00:14:54 UTC (rev 7186)
@@ -35,7 +35,6 @@
 #include "util/Debug.h"
 #include "util/StringUtils.h"
 #include "util/SubString.h"
-#include "Language.h"
 
 namespace orxonox
 {
@@ -44,15 +43,6 @@
         this->functor_ = functor;
         this->name_ = name;
 
-        this->bAddedDescription_ = false;
-        this->bAddedDescriptionReturnvalue_ = false;
-
-        this->bAddedDescriptionParam_[0] = false;
-        this->bAddedDescriptionParam_[1] = false;
-        this->bAddedDescriptionParam_[2] = false;
-        this->bAddedDescriptionParam_[3] = false;
-        this->bAddedDescriptionParam_[4] = false;
-
         this->bAddedDefaultValue_[0] = false;
         this->bAddedDefaultValue_[1] = false;
         this->bAddedDefaultValue_[2] = false;
@@ -68,7 +58,7 @@
     bool Executor::parse(const std::string& params, const std::string& delimiter) const
     {
         unsigned int paramCount = this->functor_->getParamCount();
-       
+
         if (paramCount == 0)
         {
             COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl;
@@ -96,7 +86,7 @@
         else
         {
             SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0');
-           
+
             for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
             {
                 if (!this->bAddedDefaultValue_[i])
@@ -105,7 +95,7 @@
                     return false;
                 }
             }
-           
+
             MultiType param[MAX_FUNCTOR_ARGUMENTS];
             COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens (";
             for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++)
@@ -128,10 +118,10 @@
                 COUT(5) << this->defaultValue_[i];
             }
             COUT(5) << ")." << std::endl;
-           
+
             if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string"))
                 param[paramCount - 1] = tokens.subSet(paramCount - 1).join();
-           
+
             switch(paramCount)
             {
                 case 2:
@@ -199,64 +189,6 @@
         }
     }
 
-    Executor& Executor::setDescription(const std::string& description)
-    {
-        if (!this->bAddedDescription_)
-        {
-            this->description_ = std::string("ExecutorDescription::" + this->name_ + "::function");
-            AddLanguageEntry(this->description_, description);
-            this->bAddedDescription_ = true;
-        }
-        return (*this);
-    }
-
-    const std::string& Executor::getDescription() const
-    {
-        return GetLocalisation(this->description_);
-    }
-
-    Executor& Executor::setDescriptionParam(unsigned int param, const std::string& description)
-    {
-        if (param < MAX_FUNCTOR_ARGUMENTS)
-        {
-            if (!this->bAddedDescriptionParam_[param])
-            {
-                std::string paramnumber;
-                if (!convertValue(&paramnumber, param))
-                    return (*this);
-
-                this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber);
-                AddLanguageEntry(this->descriptionParam_[param], description);
-                this->bAddedDescriptionParam_[param] = true;
-            }
-        }
-        return (*this);
-    }
-
-    const std::string& Executor::getDescriptionParam(unsigned int param) const
-    {
-        if (param < MAX_FUNCTOR_ARGUMENTS)
-            return GetLocalisation(this->descriptionParam_[param]);
-
-        return this->descriptionParam_[0];
-    }
-
-    Executor& Executor::setDescriptionReturnvalue(const std::string& description)
-    {
-        if (!this->bAddedDescriptionReturnvalue_)
-        {
-            this->descriptionReturnvalue_ = std::string("ExecutorDescription::" + this->name_ + "::returnvalue");
-            AddLanguageEntry(this->descriptionReturnvalue_, description);
-            this->bAddedDescriptionReturnvalue_ = true;
-        }
-        return (*this);
-    }
-
-    const std::string& Executor::getDescriptionReturnvalue(int param) const
-    {
-        return GetLocalisation(this->descriptionReturnvalue_);
-    }
-
     Executor& Executor::setDefaultValues(const MultiType& param1)
     {
         this->defaultValue_[0] = param1;

Modified: code/branches/consolecommands3/src/libraries/core/Executor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.h	2010-08-19 00:11:28 UTC (rev 7185)
+++ code/branches/consolecommands3/src/libraries/core/Executor.h	2010-08-19 00:14:54 UTC (rev 7186)
@@ -61,15 +61,6 @@
 
             bool evaluate(const std::string& params, MultiType param[5], const std::string& delimiter = " ") const;
 
-            Executor& setDescription(const std::string& description);
-            const std::string& getDescription() const;
-
-            Executor& setDescriptionParam(unsigned int param, const std::string& description);
-            const std::string& getDescriptionParam(unsigned int param) const;
-
-            Executor& setDescriptionReturnvalue(const std::string& description);
-            const std::string& getDescriptionReturnvalue(int param) const;
-
             inline Functor* getFunctor() const
                 { return this->functor_; }
             inline unsigned int getParamCount() const
@@ -119,15 +110,6 @@
             std::string name_;
             MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS];
             bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS];
-
-        private:
-            LanguageEntryLabel description_;
-            LanguageEntryLabel descriptionReturnvalue_;
-            LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
-
-            bool bAddedDescription_;
-            bool bAddedDescriptionReturnvalue_;
-            bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS];
     };
 
     class _CoreExport ExecutorStatic : public Executor

Modified: code/branches/consolecommands3/src/libraries/core/Language.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Language.cc	2010-08-19 00:11:28 UTC (rev 7185)
+++ code/branches/consolecommands3/src/libraries/core/Language.cc	2010-08-19 00:14:54 UTC (rev 7186)
@@ -35,6 +35,7 @@
 
 #include <fstream>
 #include "util/Debug.h"
+#include "util/StringUtils.h"
 #include "Core.h"
 #include "PathConfig.h"
 
@@ -168,17 +169,19 @@
         @param label The label of the entry
         @return The localisation
     */
-    const std::string& Language::getLocalisation(const LanguageEntryLabel& label) const
+    const std::string& Language::getLocalisation(const LanguageEntryLabel& label, bool bError) const
     {
         std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label);
         if (it != this->languageEntries_.end())
             return it->second->getLocalisation();
-        else
+        else if (bError)
         {
             // Uh, oh, an undefined entry was requested: return the default string
             COUT(2) << "Warning: Language entry \"" << label << "\" not found!" << std::endl;
             return this->defaultLocalisation_;
         }
+        else
+            return BLANKSTRING;
     }
 
     /**

Modified: code/branches/consolecommands3/src/libraries/core/Language.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Language.h	2010-08-19 00:11:28 UTC (rev 7185)
+++ code/branches/consolecommands3/src/libraries/core/Language.h	2010-08-19 00:14:54 UTC (rev 7186)
@@ -115,7 +115,7 @@
             ~Language();
 
             void addEntry(const LanguageEntryLabel& label, const std::string& entry);
-            const std::string& getLocalisation(const LanguageEntryLabel& label) const;
+            const std::string& getLocalisation(const LanguageEntryLabel& label, bool bError = true) const;
 
         private:
             Language(const Language&);
@@ -144,6 +144,12 @@
     {
         return Language::getInstance().getLocalisation(label);
     }
+
+    //! Shortcut function for Language::getLocalisation without printing an error in case the label doesn't exist
+    inline const std::string& GetLocalisation_noerror(const LanguageEntryLabel& label)
+    {
+        return Language::getInstance().getLocalisation(label, false);
+    }
 }
 
 #endif /* _Language_H__ */

Modified: code/branches/consolecommands3/src/libraries/core/XMLPort.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/XMLPort.h	2010-08-19 00:11:28 UTC (rev 7185)
+++ code/branches/consolecommands3/src/libraries/core/XMLPort.h	2010-08-19 00:14:54 UTC (rev 7186)
@@ -316,8 +316,10 @@
             inline const std::string& getName() const
                 { return this->paramname_; }
 
-            virtual XMLPortParamContainer& description(const std::string& description) = 0;
-            virtual const std::string& getDescription() = 0;
+            inline XMLPortParamContainer& description(const std::string& description)
+                { this->description_ = description; return *this; }
+            inline const std::string& getDescription() const
+                { return this->description_; }
 
             virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiType& param) = 0;
             virtual XMLPortParamContainer& defaultValues(const MultiType& param1) = 0;
@@ -331,6 +333,7 @@
             ParseResult parseResult_;
             Identifier* identifier_;
             BaseObject* owner_;
+            std::string description_;
     };
 
     template <class T>
@@ -435,11 +438,6 @@
                     return (*this);
             }
 
-            virtual XMLPortParamContainer& description(const std::string& description)
-                { this->loadexecutor_->setDescription(description); return (*this); }
-            virtual const std::string& getDescription()
-                { return this->loadexecutor_->getDescription(); }
-
             virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiType& param)
             {
                 if (!this->loadexecutor_->defaultValueSet(index))
@@ -501,8 +499,10 @@
             inline const std::string& getName() const
                 { return this->sectionname_; }
 
-            virtual XMLPortObjectContainer& description(const std::string& description) = 0;
-            virtual const std::string& getDescription() = 0;
+            inline XMLPortObjectContainer& description(const std::string& description)
+                { this->description_ = description; return *this; }
+            const std::string& getDescription() const
+                { return this->description_; }
 
             bool identifierIsIncludedInLoaderMask(const Identifier* identifier);
 
@@ -512,6 +512,7 @@
             bool bLoadBefore_;
             Identifier* identifier_;
             Identifier* objectIdentifier_;
+            std::string description_;
     };
 
     template <class T, class O>
@@ -548,11 +549,6 @@
                 (*this->loadexecutor_)(castedObject, castedNewObject);
             }
 
-            virtual XMLPortObjectContainer& description(const std::string& description)
-                { this->loadexecutor_->setDescription(description); return (*this); }
-            virtual const std::string& getDescription()
-                { return this->loadexecutor_->getDescription(); }
-
         private:
             ExecutorMember<T>* loadexecutor_;
             ExecutorMember<T>* saveexecutor_;




More information about the Orxonox-commit mailing list