[Orxonox-commit 5692] r10352 - in code/branches/core7/src/libraries/core: . command

landauf at orxonox.net landauf at orxonox.net
Wed Apr 8 23:15:11 CEST 2015


Author: landauf
Date: 2015-04-08 23:15:11 +0200 (Wed, 08 Apr 2015)
New Revision: 10352

Added:
   code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.cc
Modified:
   code/branches/core7/src/libraries/core/Core.cc
   code/branches/core7/src/libraries/core/command/CMakeLists.txt
   code/branches/core7/src/libraries/core/command/ConsoleCommand.cc
   code/branches/core7/src/libraries/core/command/ConsoleCommand.h
   code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.h
Log:
wrap ConsoleCommands in StaticallyInitializedInstances

Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc	2015-04-07 20:12:07 UTC (rev 10351)
+++ code/branches/core7/src/libraries/core/Core.cc	2015-04-08 21:15:11 UTC (rev 10352)
@@ -140,6 +140,7 @@
         }
 
         // TODO: initialize CommandLineParser here
+        // TODO: initialize ConsoleCommandManager here
         ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances();
 
         // Parse command line arguments AFTER the modules have been loaded (static code!)

Modified: code/branches/core7/src/libraries/core/command/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/core/command/CMakeLists.txt	2015-04-07 20:12:07 UTC (rev 10351)
+++ code/branches/core7/src/libraries/core/command/CMakeLists.txt	2015-04-08 21:15:11 UTC (rev 10352)
@@ -3,6 +3,7 @@
   CommandExecutor.cc
   ConsoleCommand.cc
   ConsoleCommandCompilation.cc
+  ConsoleCommandIncludes.cc
   ConsoleCommandManager.cc
   Executor.cc
   IOConsole.cc

Modified: code/branches/core7/src/libraries/core/command/ConsoleCommand.cc
===================================================================
--- code/branches/core7/src/libraries/core/command/ConsoleCommand.cc	2015-04-07 20:12:07 UTC (rev 10351)
+++ code/branches/core7/src/libraries/core/command/ConsoleCommand.cc	2015-04-08 21:15:11 UTC (rev 10352)
@@ -83,7 +83,7 @@
         if (bInitialized)
             this->executor_ = executor;
 
-        ConsoleCommandManager::registerCommand(group, name, this);
+        this->names_.push_back(CommandName(group, name));
     }
 
     /**
@@ -99,7 +99,7 @@
     */
     ConsoleCommand& ConsoleCommand::addShortcut()
     {
-        ConsoleCommandManager::registerCommand("", this->baseName_, this);
+        this->names_.push_back(CommandName("", this->baseName_));
         return *this;
     }
 
@@ -108,7 +108,7 @@
     */
     ConsoleCommand& ConsoleCommand::addShortcut(const std::string&  name)
     {
-        ConsoleCommandManager::registerCommand("", name, this);
+        this->names_.push_back(CommandName("", name));
         return *this;
     }
 
@@ -117,7 +117,7 @@
     */
     ConsoleCommand& ConsoleCommand::addGroup(const std::string& group)
     {
-        ConsoleCommandManager::registerCommand(group, this->baseName_, this);
+        this->names_.push_back(CommandName(group, this->baseName_));
         return *this;
     }
 
@@ -126,7 +126,7 @@
     */
     ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string&  name)
     {
-        ConsoleCommandManager::registerCommand(group, name, this);
+        this->names_.push_back(CommandName(group, name));
         return *this;
     }
 

Modified: code/branches/core7/src/libraries/core/command/ConsoleCommand.h
===================================================================
--- code/branches/core7/src/libraries/core/command/ConsoleCommand.h	2015-04-07 20:12:07 UTC (rev 10351)
+++ code/branches/core7/src/libraries/core/command/ConsoleCommand.h	2015-04-08 21:15:11 UTC (rev 10352)
@@ -104,6 +104,16 @@
 
         public:
             /**
+             * @brief Defines the name of a command, consisting of an optional group ("" means no group) and the name itself.
+             */
+            struct CommandName
+            {
+                CommandName(const std::string& group, const std::string& name) : group_(group), name_(name) {}
+                std::string group_;
+                std::string name_;
+            };
+
+            /**
                 @brief Helper class that is used to manipulate console commands.
 
                 An instance of this class is returned if you call the ModifyConsoleCommand macro.
@@ -359,6 +369,9 @@
             inline ConsoleCommandManipulator getManipulator()
                 { return this; }
 
+            inline const std::vector<CommandName>& getNames()
+                { return this->names_; }
+
         private:
             void init(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized);
 
@@ -382,6 +395,7 @@
             bool bHidden_;                                                  ///< True if the command is hidden (it is still executable, but not visible in the list of available commands)
             AccessLevel::Enum accessLevel_;                                 ///< The access level (the state of the game in which you can access the command)
             std::string baseName_;                                          ///< The name that was first assigned to the command
+            std::vector<CommandName> names_;                                ///< All names and aliases of this command
             FunctorPtr baseFunctor_;                                        ///< The functor that defines the header of the command-function
 
             ExecutorPtr executor_;                                          ///< The Executor that is used to execute the command

Added: code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.cc
===================================================================
--- code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.cc	                        (rev 0)
+++ code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.cc	2015-04-08 21:15:11 UTC (rev 10352)
@@ -0,0 +1,43 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ConsoleCommandIncludes.h"
+
+#include "ConsoleCommandManager.h"
+
+namespace orxonox
+{
+    void StaticallyInitializedConsoleCommand::load()
+    {
+        for (size_t i = 0; i < this->command_->getNames().size(); ++i)
+        {
+            const ConsoleCommand::CommandName& name = this->command_->getNames()[i];
+            ConsoleCommandManager::registerCommand(name.group_, name.name_, this->command_);
+        }
+    }
+}

Modified: code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.h
===================================================================
--- code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.h	2015-04-07 20:12:07 UTC (rev 10351)
+++ code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.h	2015-04-08 21:15:11 UTC (rev 10352)
@@ -222,6 +222,7 @@
 #include "ConsoleCommand.h"
 #include "ConsoleCommandManager.h"
 #include "util/VA_NARGS.h"
+#include "core/module/StaticallyInitializedInstance.h"
 
 
 /**
@@ -263,7 +264,8 @@
 
 /// Internal macro
 #define SetConsoleCommandGeneric(group, name, functor) \
-    static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) = (*new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor)))
+    static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) \
+        = (new orxonox::SI_CC(new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor))))->getCommand()
 
 
 /**
@@ -298,11 +300,28 @@
 
 /// Internal macro
 #define DeclareConsoleCommandGeneric(group, name, functor) \
-    static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) = (*new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor), false))
+    static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) \
+        = (new orxonox::SI_CC(new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor), false)))->getCommand()
 
 
 namespace orxonox
 {
+    class _CoreExport StaticallyInitializedConsoleCommand : public StaticallyInitializedInstance
+    {
+        public:
+            StaticallyInitializedConsoleCommand(ConsoleCommand* command) : command_(command) {}
+
+            virtual void load();
+
+            inline ConsoleCommand& getCommand()
+                { return *this->command_; }
+
+        private:
+            ConsoleCommand* command_;
+    };
+
+    typedef StaticallyInitializedConsoleCommand SI_CC;
+
     /**
         @brief Returns a manipulator for a command with the given name.
 




More information about the Orxonox-commit mailing list