Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 25, 2010, 7:07:08 PM (14 years ago)
Author:
landauf
Message:

removed old console command implementation (doesn't compile)

Location:
code/branches/consolecommands3/src/libraries/core/command
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc

    r7203 r7216  
    5454    }
    5555
    56     ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit)
    57     {
    58         std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName());
    59         if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
    60         {
    61             COUT(2) << "Warning: Overwriting console-command shortcut with name " << command->getName() << '.' << std::endl;
    62         }
    63 
    64         // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier
    65         if (command && bDeleteAtExit)
    66         {
    67             CommandExecutor::getInstance().consoleCommandExternals_.insert(command);
    68         }
    69 
    70         CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
    71         CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(command->getName())] = command;
    72         return (*command);
    73     }
    74 
    75     /**
    76         @brief Returns the executor of a console command shortcut with given name.
    77         @brief name The name of the requested console command shortcut
    78         @return The executor of the requested console command shortcut
    79     */
    80     ConsoleCommand* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
    81     {
    82         std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
    83         if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
    84             return it->second;
    85         else
    86             return 0;
    87     }
    88 
    89     /**
    90         @brief Returns the executor of a console command shortcut with given name in lowercase.
    91         @brief name The name of the requested console command shortcut in lowercase
    92         @return The executor of the requested console command shortcut
    93     */
    94     ConsoleCommand* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
    95     {
    96         std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
    97         if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end())
    98             return it->second;
    99         else
    100             return 0;
    101     }
    102 
    10356    bool CommandExecutor::execute(const std::string& command, bool useTcl)
    10457    {
  • code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h

    r7203 r7216  
    5757            static const CommandEvaluation& getLastEvaluation();
    5858
    59             static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false);
    60             static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
    61             static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
    62 
    63             /** @brief Returns the map that stores all console commands. @return The const_iterator */
    64             static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
    65             /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
    66             static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
    67             /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
    68             static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
    69 
    70             /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
    71             static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
    72             /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    73             static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
    74             /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    75             static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
    76 
    77             static void destroyExternalCommands();
    78 
    7959        private:
    8060            CommandExecutor() {}
     
    10787
    10888            CommandEvaluation evaluation_;
    109             std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
    110             std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
    111             std::set<ConsoleCommand*>              consoleCommandExternals_;
    11289    }; // tolua_export
    11390} // tolua_export
  • code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc

    r7215 r7216  
    2828
    2929#include "ConsoleCommand.h"
    30 #include <cassert>
    3130
    3231#include "util/Convert.h"
    3332#include "core/Language.h"
    34 
    35 namespace orxonox
    36 {
    37     ConsoleCommand::ConsoleCommand(const FunctorPtr& functor, const std::string& name) : Executor(functor, name)
    38     {
    39         this->accessLevel_ = AccessLevel::None;
    40         this->argumentCompleter_[0] = 0;
    41         this->argumentCompleter_[1] = 0;
    42         this->argumentCompleter_[2] = 0;
    43         this->argumentCompleter_[3] = 0;
    44         this->argumentCompleter_[4] = 0;
    45 
    46         this->keybindMode_ = KeybindMode::OnPress;
    47         this->inputConfiguredParam_ = -1;
    48     }
    49 
    50     ConsoleCommand& ConsoleCommand::argumentCompleter(unsigned int param, ArgumentCompleter* completer)
    51     {
    52         if (param < 5)
    53             this->argumentCompleter_[param] = completer;
    54         else
    55         {
    56             COUT(2) << "Warning: Couldn't add autocompletion-function for param " << param << ": index out of bound." << std::endl;
    57         }
    58         return (*this);
    59     }
    60 
    61     ArgumentCompleter* ConsoleCommand::getArgumentCompleter(unsigned int param) const
    62     {
    63         if (param < 5)
    64             return this->argumentCompleter_[param];
    65         else
    66             return 0;
    67     }
    68 
    69     void ConsoleCommand::createArgumentCompletionList(unsigned int param, const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)
    70     {
    71         if (param < 5 && this->argumentCompleter_[param])
    72             this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5);
    73         else
    74             this->argumentList_.clear();
    75     }
    76 
    77     ConsoleCommand& ConsoleCommand::description(const std::string& description)
    78     {
    79         this->description_ = std::string("ConsoleCommandDescription::" + this->name_ + "::function");
    80         AddLanguageEntry(this->description_, description);
    81         return (*this);
    82     }
    83 
    84     const std::string& ConsoleCommand::getDescription() const
    85     {
    86         return GetLocalisation_noerror(this->description_);
    87     }
    88 
    89     ConsoleCommand& ConsoleCommand::descriptionParam(unsigned int param, const std::string& description)
    90     {
    91         if (param < MAX_FUNCTOR_ARGUMENTS)
    92         {
    93             this->descriptionParam_[param] = std::string("ConsoleCommandDescription::" + this->name_ + "::param" + multi_cast<std::string>(param));
    94             AddLanguageEntry(this->descriptionParam_[param], description);
    95         }
    96         return (*this);
    97     }
    98 
    99     const std::string& ConsoleCommand::getDescriptionParam(unsigned int param) const
    100     {
    101         if (param < MAX_FUNCTOR_ARGUMENTS)
    102             return GetLocalisation_noerror(this->descriptionParam_[param]);
    103 
    104         return this->descriptionParam_[0];
    105     }
    106 
    107     ConsoleCommand& ConsoleCommand::descriptionReturnvalue(const std::string& description)
    108     {
    109         this->descriptionReturnvalue_ = std::string("ConsoleCommandDescription::" + this->name_ + "::returnvalue");
    110         AddLanguageEntry(this->descriptionReturnvalue_, description);
    111         return (*this);
    112     }
    113 
    114     const std::string& ConsoleCommand::getDescriptionReturnvalue(int param) const
    115     {
    116         return GetLocalisation_noerror(this->descriptionReturnvalue_);
    117     }
    118 }
    119 
    12033#include "core/BaseObject.h" // remove this
    12134
     
    537450        }
    538451    }
     452
     453    /* static */ void _ConsoleCommand::destroyAll()
     454    {
     455        while (!_ConsoleCommand::getCommandMap().empty() && !_ConsoleCommand::getCommandMap().begin().empty())
     456            _ConsoleCommand::getCommandMap().begin().erase(_ConsoleCommand::getCommandMap().begin().begin());
     457    }
    539458}
  • code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h

    r7215 r7216  
    3737
    3838#include "util/VA_NARGS.h"
    39 #include "core/Identifier.h"
    4039#include "ArgumentCompletionFunctions.h"
    41 #include "CommandExecutor.h"
    4240#include "Executor.h"
    43 
    44 
    45 #define SetConsoleCommand(classname, function, bCreateShortcut) \
    46     SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut)
    47 #define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \
    48     SetConsoleCommandGeneric(classname, function, name, bCreateShortcut)
    49 
    50 #define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \
    51     orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
    52 
    53 
    54 #define SetConsoleCommandShortcut(classname, function) \
    55     SetConsoleCommandShortcutAliasGeneric(classname, function, #function)
    56 #define SetConsoleCommandShortcutAlias(classname, function, name) \
    57     SetConsoleCommandShortcutAliasGeneric(classname, function, name)
    58 #define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \
    59     SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
    60 
    61 #define SetConsoleCommandShortcutExtern(function) \
    62     SetConsoleCommandShortcutExternAliasGeneric(function, #function)
    63 #define SetConsoleCommandShortcutExternAlias(function, name) \
    64     SetConsoleCommandShortcutExternAliasGeneric(function, name)
    65 #define SetConsoleCommandShortcutExternAliasGeneric(function, name) \
    66     SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
    67 
    68 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \
    69     orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)
    70 
    71 
    72 namespace orxonox
    73 {
    74     namespace AccessLevel
    75     {
    76         enum Value
    77         {
    78             None,
    79             User,
    80             Admin,
    81             Offline,
    82             Debug,
    83             Disabled
    84         };
    85     }
    86 
    87     class _CoreExport ConsoleCommand : public Executor
    88     {
    89         public:
    90             ConsoleCommand(const FunctorPtr& functor, const std::string& name = "");
    91 
    92             ConsoleCommand& description(const std::string& description);
    93             const std::string& getDescription() const;
    94 
    95             ConsoleCommand& descriptionParam(unsigned int param, const std::string& description);
    96             const std::string& getDescriptionParam(unsigned int param) const;
    97 
    98             ConsoleCommand& descriptionReturnvalue(const std::string& description);
    99             const std::string& getDescriptionReturnvalue(int param) const;
    100 
    101             inline ConsoleCommand& defaultValues(const MultiType& param1)
    102                 { this->Executor::setDefaultValues(param1); return (*this); }
    103             inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2)
    104                 { this->Executor::setDefaultValues(param1, param2); return (*this); }
    105             inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
    106                 { this->Executor::setDefaultValues(param1, param2, param3); return (*this); }
    107             inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
    108                 { this->Executor::setDefaultValues(param1, param2, param3, param4); return (*this); }
    109             inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
    110                 { this->Executor::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
    111             inline ConsoleCommand& defaultValue(unsigned int index, const MultiType& param)
    112                 { this->Executor::setDefaultValue(index, param); return (*this); }
    113 
    114             inline ConsoleCommand& accessLevel(AccessLevel::Value level)
    115                 { this->accessLevel_ = level; return (*this); }
    116             inline AccessLevel::Value getAccessLevel() const
    117                 { return this->accessLevel_; }
    118 
    119             ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer);
    120             ArgumentCompleter* getArgumentCompleter(unsigned int param) const;
    121 
    122             void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "");
    123             const ArgumentCompletionList& getArgumentCompletionList() const
    124                 { return this->argumentList_; }
    125             ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
    126                 { return this->argumentList_.begin(); }
    127             ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
    128                 { return this->argumentList_.end(); }
    129 
    130             inline ConsoleCommand& setAsInputCommand()
    131             {
    132                 this->keybindMode(KeybindMode::OnHold);
    133                 this->defaultValue(0, Vector2(0.0f, 0.0f));
    134                 this->inputConfiguredParam(0);
    135                 return *this;
    136             }
    137 
    138             inline ConsoleCommand& keybindMode(KeybindMode::Value mode)
    139                 { this->keybindMode_ = mode; return *this; }
    140             inline KeybindMode::Value getKeybindMode() const
    141                 { return this->keybindMode_; }
    142 
    143             inline ConsoleCommand& inputConfiguredParam(int index)
    144                 { this->inputConfiguredParam_ = index; return *this; }
    145             inline int getInputConfiguredParam_() const
    146                 { return this->inputConfiguredParam_; }
    147 
    148         private:
    149             AccessLevel::Value accessLevel_;
    150             ArgumentCompleter* argumentCompleter_[5];
    151             ArgumentCompletionList argumentList_;
    152 
    153             KeybindMode::Value keybindMode_;
    154             int inputConfiguredParam_;
    155 
    156             LanguageEntryLabel description_;
    157             LanguageEntryLabel descriptionReturnvalue_;
    158             LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
    159     };
    160 
    161     inline ConsoleCommand* createConsoleCommand(const FunctorPtr& functor, const std::string& name = "")
    162     {
    163         return new ConsoleCommand(functor, name);
    164     }
    165 }
    16641
    16742
     
    452327            static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
    453328
     329            static void destroyAll();
     330
    454331        private:
    455332            static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
Note: See TracChangeset for help on using the changeset viewer.