Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10352 for code/branches/core7


Ignore:
Timestamp:
Apr 8, 2015, 11:15:11 PM (10 years ago)
Author:
landauf
Message:

wrap ConsoleCommands in StaticallyInitializedInstances

Location:
code/branches/core7/src/libraries/core
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/Core.cc

    r10347 r10352  
    141141
    142142        // TODO: initialize CommandLineParser here
     143        // TODO: initialize ConsoleCommandManager here
    143144        ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances();
    144145
  • code/branches/core7/src/libraries/core/command/CMakeLists.txt

    r10346 r10352  
    44  ConsoleCommand.cc
    55  ConsoleCommandCompilation.cc
     6  ConsoleCommandIncludes.cc
    67  ConsoleCommandManager.cc
    78  Executor.cc
  • code/branches/core7/src/libraries/core/command/ConsoleCommand.cc

    r10348 r10352  
    8484            this->executor_ = executor;
    8585
    86         ConsoleCommandManager::registerCommand(group, name, this);
     86        this->names_.push_back(CommandName(group, name));
    8787    }
    8888
     
    100100    ConsoleCommand& ConsoleCommand::addShortcut()
    101101    {
    102         ConsoleCommandManager::registerCommand("", this->baseName_, this);
     102        this->names_.push_back(CommandName("", this->baseName_));
    103103        return *this;
    104104    }
     
    109109    ConsoleCommand& ConsoleCommand::addShortcut(const std::string&  name)
    110110    {
    111         ConsoleCommandManager::registerCommand("", name, this);
     111        this->names_.push_back(CommandName("", name));
    112112        return *this;
    113113    }
     
    118118    ConsoleCommand& ConsoleCommand::addGroup(const std::string& group)
    119119    {
    120         ConsoleCommandManager::registerCommand(group, this->baseName_, this);
     120        this->names_.push_back(CommandName(group, this->baseName_));
    121121        return *this;
    122122    }
     
    127127    ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string&  name)
    128128    {
    129         ConsoleCommandManager::registerCommand(group, name, this);
     129        this->names_.push_back(CommandName(group, name));
    130130        return *this;
    131131    }
  • code/branches/core7/src/libraries/core/command/ConsoleCommand.h

    r10348 r10352  
    104104
    105105        public:
     106            /**
     107             * @brief Defines the name of a command, consisting of an optional group ("" means no group) and the name itself.
     108             */
     109            struct CommandName
     110            {
     111                CommandName(const std::string& group, const std::string& name) : group_(group), name_(name) {}
     112                std::string group_;
     113                std::string name_;
     114            };
     115
    106116            /**
    107117                @brief Helper class that is used to manipulate console commands.
     
    360370                { return this; }
    361371
     372            inline const std::vector<CommandName>& getNames()
     373                { return this->names_; }
     374
    362375        private:
    363376            void init(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized);
     
    383396            AccessLevel::Enum accessLevel_;                                 ///< The access level (the state of the game in which you can access the command)
    384397            std::string baseName_;                                          ///< The name that was first assigned to the command
     398            std::vector<CommandName> names_;                                ///< All names and aliases of this command
    385399            FunctorPtr baseFunctor_;                                        ///< The functor that defines the header of the command-function
    386400
  • code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.h

    r10348 r10352  
    223223#include "ConsoleCommandManager.h"
    224224#include "util/VA_NARGS.h"
     225#include "core/module/StaticallyInitializedInstance.h"
    225226
    226227
     
    264265/// Internal macro
    265266#define SetConsoleCommandGeneric(group, name, functor) \
    266     static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) = (*new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor)))
     267    static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) \
     268        = (new orxonox::SI_CC(new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor))))->getCommand()
    267269
    268270
     
    299301/// Internal macro
    300302#define DeclareConsoleCommandGeneric(group, name, functor) \
    301     static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) = (*new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor), false))
     303    static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) \
     304        = (new orxonox::SI_CC(new orxonox::ConsoleCommand(group, name, orxonox::createExecutor(functor), false)))->getCommand()
    302305
    303306
    304307namespace orxonox
    305308{
     309    class _CoreExport StaticallyInitializedConsoleCommand : public StaticallyInitializedInstance
     310    {
     311        public:
     312            StaticallyInitializedConsoleCommand(ConsoleCommand* command) : command_(command) {}
     313
     314            virtual void load();
     315
     316            inline ConsoleCommand& getCommand()
     317                { return *this->command_; }
     318
     319        private:
     320            ConsoleCommand* command_;
     321    };
     322
     323    typedef StaticallyInitializedConsoleCommand SI_CC;
     324
    306325    /**
    307326        @brief Returns a manipulator for a command with the given name.
Note: See TracChangeset for help on using the changeset viewer.