Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
13 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/command/ArgumentCompletionFunctions.cc

    r9667 r10624  
    4444#include "CommandExecutor.h"
    4545#include "ConsoleCommand.h"
     46#include "ConsoleCommandManager.h"
    4647#include "TclThreadManager.h"
    4748
     
    9899
    99100                // get all the groups that are visible (except the shortcut group "")
    100                 const std::map<std::string, std::map<std::string, ConsoleCommand*> >& commands = ConsoleCommand::getCommands();
     101                const std::map<std::string, std::map<std::string, ConsoleCommand*> >& commands = ConsoleCommandManager::getInstance().getCommands();
    101102                for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)
    102103                    if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find(fragmentLC) == 0))
     
    137138
    138139                // find the iterator of the given group
    139                 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommands().begin();
    140                 for ( ; it_group != ConsoleCommand::getCommands().end(); ++it_group)
     140                std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommands().begin();
     141                for ( ; it_group != ConsoleCommandManager::getInstance().getCommands().end(); ++it_group)
    141142                    if (getLowercase(it_group->first) == groupLC)
    142143                        break;
    143144
    144145                // add all commands in the group to the list
    145                 if (it_group != ConsoleCommand::getCommands().end())
     146                if (it_group != ConsoleCommandManager::getInstance().getCommands().end())
    146147                {
    147148                    for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
     
    206207                return detail::_groupsandcommands(fragment, true);
    207208
    208             if (ConsoleCommand::getCommandLC(getLowercase(tokens[0])))
     209            if (ConsoleCommandManager::getInstance().getCommandLC(getLowercase(tokens[0])))
    209210                return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment);
    210211
    211212            if (tokens.size() == 1)
    212213            {
    213                 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommands().find(tokens[0]);
    214                 if (it_group != ConsoleCommand::getCommands().end())
     214                std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommands().find(tokens[0]);
     215                if (it_group != ConsoleCommandManager::getInstance().getCommands().end())
    215216                    return detail::_subcommands(fragment, tokens[0], true);
    216217                else
     
    218219            }
    219220
    220             if (ConsoleCommand::getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1])))
     221            if (ConsoleCommandManager::getInstance().getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1])))
    221222                return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment);
    222223
  • code/trunk/src/libraries/core/command/CMakeLists.txt

    r7284 r10624  
    44  ConsoleCommand.cc
    55  ConsoleCommandCompilation.cc
     6  ConsoleCommandIncludes.cc
     7  ConsoleCommandManager.cc
    68  Executor.cc
    79  IOConsole.cc
  • code/trunk/src/libraries/core/command/CommandEvaluation.cc

    r9550 r10624  
    3737#include "CommandExecutor.h"
    3838#include "ConsoleCommand.h"
     39#include "ConsoleCommandManager.h"
    3940
    4041namespace orxonox
     
    305306                // the user typed 1-2 arguments, check what he tried to type and print a suitable error
    306307                std::string groupLC = getLowercase(this->getToken(0));
    307                 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group)
     308                for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group)
    308309                    if (it_group->first == groupLC)
    309310                        return std::string("Error: There is no command in group \"") + this->getToken(0) + "\" starting with \"" + this->getToken(1) + "\".";
     
    327328
    328329        // iterate through all groups and their commands and calculate the distance to the current command. keep the best.
    329         for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group)
     330        for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group)
    330331        {
    331332            if (it_group->first != "")
     
    345346
    346347        // now also iterate through all shortcuts and keep the best if it's better than the one found above.
    347         std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().find("");
    348         if (it_group !=  ConsoleCommand::getCommandsLC().end())
     348        std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().find("");
     349        if (it_group !=  ConsoleCommandManager::getInstance().getCommandsLC().end())
    349350        {
    350351            for (std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name)
  • code/trunk/src/libraries/core/command/CommandExecutor.cc

    r9550 r10624  
    3434#include "CommandExecutor.h"
    3535
    36 #include "ConsoleCommand.h"
     36#include "ConsoleCommandIncludes.h"
    3737#include "TclBind.h"
    3838#include "Shell.h"
     
    155155
    156156        // assign the fallback-command to get hints about the possible commands and groups
    157         evaluation.hintCommand_ = ConsoleCommand::getCommand(__CC_CommandExecutor_name, __CC_autocomplete_name);
     157        evaluation.hintCommand_ = ConsoleCommandManager::getInstance().getCommand(__CC_CommandExecutor_name, __CC_autocomplete_name);
    158158
    159159        // check if there's at least one argument
     
    161161        {
    162162            // try to get a command from the first token
    163             evaluation.execCommand_ = ConsoleCommand::getCommandLC(evaluation.getToken(0));
     163            evaluation.execCommand_ = ConsoleCommandManager::getInstance().getCommandLC(evaluation.getToken(0));
    164164            if (evaluation.execCommand_)
    165165                evaluation.execArgumentsOffset_ = 1;
     
    167167            {
    168168                // try to get a command from the first two tokens
    169                 evaluation.execCommand_ = ConsoleCommand::getCommandLC(evaluation.getToken(0), evaluation.getToken(1));
     169                evaluation.execCommand_ = ConsoleCommandManager::getInstance().getCommandLC(evaluation.getToken(0), evaluation.getToken(1));
    170170                if (evaluation.execCommand_)
    171171                    evaluation.execArgumentsOffset_ = 2;
     
    288288
    289289            // check if the alias already exists - print an error and return if it does
    290             if ((tokens.size() == 1 && ConsoleCommand::getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommand::getCommand(tokens[0], tokens[1])))
     290            if ((tokens.size() == 1 && ConsoleCommandManager::getInstance().getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommandManager::getInstance().getCommand(tokens[0], tokens[1])))
    291291            {
    292292                orxout(user_error) << "A command with name \"" << alias << "\" already exists." << endl;
     
    296296            // create a new console command with the given alias as its name
    297297            if (tokens.size() == 1)
    298                 createConsoleCommand(tokens[0], executor);
     298                ConsoleCommandManager::getInstance().registerCommand(new ConsoleCommand(tokens[0], executor));
    299299            else if (tokens.size() == 2)
    300                 createConsoleCommand(tokens[0], tokens[1], executor);
     300                ConsoleCommandManager::getInstance().registerCommand(new ConsoleCommand(tokens[0], tokens[1], executor));
    301301            else
    302302                orxout(user_error) << "\"" << alias << "\" is not a valid alias name (must have one or two words)." << endl;
  • code/trunk/src/libraries/core/command/ConsoleCommand.cc

    r9348 r10624  
    3535
    3636#include "util/Convert.h"
    37 #include "util/StringUtils.h"
    3837#include "core/Language.h"
    3938#include "core/GameMode.h"
    4039#include "core/input/KeyBinder.h"
    4140#include "core/input/KeyBinderManager.h"
     41#include "ConsoleCommandManager.h"
    4242
    4343namespace orxonox
    4444{
    4545    /**
    46         @brief Constructor: Initializes all values and registers the command.
     46        @brief Constructor: Initializes all values and registers the command (without a group).
     47        @param name The name of the command
     48        @param executor The executor of the command
     49        @param bInitialized If true, the executor is used for both, the definition of the function-header AND to executute the command. If false, the command is inactive and needs to be assigned a function before it can be used.
     50    */
     51    ConsoleCommand::ConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized)
     52    {
     53        this->init("", name, executor, bInitialized);
     54    }
     55
     56    /**
     57        @brief Constructor: Initializes all values and registers the command (with a group).
    4758        @param group The group of the command
    4859        @param name The name of the command
     
    5263    ConsoleCommand::ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized)
    5364    {
     65        this->init(group, name, executor, bInitialized);
     66    }
     67
     68    void ConsoleCommand::init(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized)
     69    {
    5470        this->bActive_ = true;
    5571        this->bHidden_ = false;
     
    6884            this->executor_ = executor;
    6985
    70         ConsoleCommand::registerCommand(group, name, this);
     86        this->names_.push_back(CommandName(group, name));
    7187    }
    7288
     
    7692    ConsoleCommand::~ConsoleCommand()
    7793    {
    78         ConsoleCommand::unregisterCommand(this);
    7994    }
    8095
     
    8499    ConsoleCommand& ConsoleCommand::addShortcut()
    85100    {
    86         ConsoleCommand::registerCommand("", this->baseName_, this);
     101        this->names_.push_back(CommandName("", this->baseName_));
    87102        return *this;
    88103    }
     
    93108    ConsoleCommand& ConsoleCommand::addShortcut(const std::string&  name)
    94109    {
    95         ConsoleCommand::registerCommand("", name, this);
     110        this->names_.push_back(CommandName("", name));
    96111        return *this;
    97112    }
     
    102117    ConsoleCommand& ConsoleCommand::addGroup(const std::string& group)
    103118    {
    104         ConsoleCommand::registerCommand(group, this->baseName_, this);
     119        this->names_.push_back(CommandName(group, this->baseName_));
    105120        return *this;
    106121    }
     
    111126    ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string&  name)
    112127    {
    113         ConsoleCommand::registerCommand(group, name, this);
     128        this->names_.push_back(CommandName(group, name));
    114129        return *this;
    115130    }
     
    587602        return *this;
    588603    }
    589 
    590     /**
    591         @brief Returns the command with given group an name.
    592         @param group The group of the requested command
    593         @param name The group of the requested command
    594         @param bPrintError If true, an error is printed if the command doesn't exist
    595     */
    596     /* static */ ConsoleCommand* ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)
    597     {
    598         // find the group
    599         std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMap().find(group);
    600         if (it_group != ConsoleCommand::getCommandMap().end())
    601         {
    602             // find the name
    603             std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(name);
    604             if (it_name != it_group->second.end())
    605             {
    606                 // return the pointer
    607                 return it_name->second;
    608             }
    609         }
    610         if (bPrintError)
    611         {
    612             if (group == "")
    613                 orxout(internal_error, context::commands) << "Couldn't find console command with shortcut \"" << name << "\"" << endl;
    614             else
    615                 orxout(internal_error, context::commands) << "Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << endl;
    616         }
    617         return 0;
    618     }
    619 
    620     /**
    621         @brief Returns the command with given group an name in lowercase.
    622         @param group The group of the requested command in lowercase
    623         @param name The group of the requested command in lowercase
    624         @param bPrintError If true, an error is printed if the command doesn't exist
    625     */
    626     /* static */ ConsoleCommand* ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError)
    627     {
    628         std::string groupLC = getLowercase(group);
    629         std::string nameLC = getLowercase(name);
    630 
    631         // find the group
    632         std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMapLC().find(groupLC);
    633         if (it_group != ConsoleCommand::getCommandMapLC().end())
    634         {
    635             // find the name
    636             std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(nameLC);
    637             if (it_name != it_group->second.end())
    638             {
    639                 // return the pointer
    640                 return it_name->second;
    641             }
    642         }
    643         if (bPrintError)
    644         {
    645             if (group == "")
    646                 orxout(internal_error, context::commands) << "Couldn't find console command with shortcut \"" << name << "\"" << endl;
    647             else
    648                 orxout(internal_error, context::commands) << "Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << endl;
    649         }
    650         return 0;
    651     }
    652 
    653     /**
    654         @brief Returns the static map that stores all console commands.
    655     */
    656     /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMap()
    657     {
    658         static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMap;
    659         return commandMap;
    660     }
    661 
    662     /**
    663         @brief Returns the static map that stores all console commands in lowercase.
    664     */
    665     /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMapLC()
    666     {
    667         static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMapLC;
    668         return commandMapLC;
    669     }
    670 
    671     /**
    672         @brief Registers a new command with given group an name by adding it to the command map.
    673     */
    674     /* static */ void ConsoleCommand::registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command)
    675     {
    676         if (name == "")
    677             return;
    678 
    679         // check if a command with this name already exists
    680         if (ConsoleCommand::getCommand(group, name) != 0)
    681         {
    682             if (group == "")
    683                 orxout(internal_warning, context::commands) << "A console command with shortcut \"" << name << "\" already exists." << endl;
    684             else
    685                 orxout(internal_warning, context::commands) << "A console command with name \"" << name << "\" already exists in group \"" << group << "\"." << endl;
    686         }
    687         else
    688         {
    689             // add the command to the map
    690             ConsoleCommand::getCommandMap()[group][name] = command;
    691             ConsoleCommand::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command;
    692         }
    693     }
    694 
    695     /**
    696         @brief Removes the command from the command map.
    697     */
    698     /* static */ void ConsoleCommand::unregisterCommand(ConsoleCommand* command)
    699     {
    700         // iterate through all groups
    701         for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMap().begin(); it_group != ConsoleCommand::getCommandMap().end(); )
    702         {
    703             // iterate through all commands of each group
    704             for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )
    705             {
    706                 // erase the command
    707                 if (it_name->second == command)
    708                     it_group->second.erase(it_name++);
    709                 else
    710                     ++it_name;
    711             }
    712 
    713             // erase the group if it is empty now
    714             if (it_group->second.empty())
    715                 ConsoleCommand::getCommandMap().erase(it_group++);
    716             else
    717                 ++it_group;
    718         }
    719 
    720         // now the same for the lowercase-map:
    721 
    722         // iterate through all groups
    723         for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMapLC().begin(); it_group != ConsoleCommand::getCommandMapLC().end(); )
    724         {
    725             // iterate through all commands of each group
    726             for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )
    727             {
    728                 // erase the command
    729                 if (it_name->second == command)
    730                     it_group->second.erase(it_name++);
    731                 else
    732                     ++it_name;
    733             }
    734 
    735             // erase the group if it is empty now
    736             if (it_group->second.empty())
    737                 ConsoleCommand::getCommandMapLC().erase(it_group++);
    738             else
    739                 ++it_group;
    740         }
    741     }
    742 
    743     /**
    744         @brief Deletes all commands
    745     */
    746     /* static */ void ConsoleCommand::destroyAll()
    747     {
    748         // delete entries until the map is empty
    749         while (!ConsoleCommand::getCommandMap().empty() && !ConsoleCommand::getCommandMap().begin()->second.empty())
    750             delete ConsoleCommand::getCommandMap().begin()->second.begin()->second;
    751     }
    752604}
  • code/trunk/src/libraries/core/command/ConsoleCommand.h

    r9983 r10624  
    2828
    2929/**
    30     @defgroup ConsoleCommand Console commands
    31     @ingroup Command
    32 */
    33 
    34 /**
    3530    @file
    3631    @ingroup Command ConsoleCommand
    37     @brief Declaration of the orxonox::ConsoleCommand class and the SetConsoleCommand() macro.
    38 
    39     @anchor ConsoleCommandExample
    40 
    41     Console commands can be used to write scripts, use key-bindings or simply to be
    42     entered into the shell by the user. Instances of orxonox::ConsoleCommand define
    43     the function of a command, and also more information like, for example, if it is
    44     active, default values, and possible arguments.
    45 
    46     Commands need to be registered to the system statically on startup by using the
    47     SetConsoleCommand() or DeclareConsoleCommand() macros outside of a function.
    48     This ensures that commands are known to the system at any time, so they can be
    49     evaluated (see orxonox::CommandExecutor::evaluate()), for example for key-bindings.
    50 
    51     Example:
    52     @code
    53     void myCoutFunction(const std::string& text)        // Define a static function
    54     {
    55         orxout() << "Text: " << text << endl;           // Print the text to the console
    56     }
    57 
    58     SetConsoleCommand("cout", &myCoutFunction);         // Register the function as command with name "cout"
    59     @endcode
    60 
    61     Now you can open the shell and execute the command:
    62     @code
    63     $ cout Hello World
    64     @endcode
    65 
    66     Internally this command is now passed to orxonox::CommandExecutor::execute():
    67     @code
    68     CommandExecutor::execute("cout HelloWorld");
    69     @endcode
    70 
    71     CommandExecutor searches for a command with name "cout" and passes the arguments
    72     "Hello World" to it. Because we registered myCoutFunction() with this command,
    73     as a result the following text will be printed to the console:
    74     @code
    75     Text: Hello World
    76     @endcode
    77 
    78     You can add more attributes to the ConsoleCommand, by using the command-chain feature
    79     of SetConsoleCommand(). For example like this:
    80     @code
    81     SetConsoleCommand("cout", &myCoutFunction)
    82         .addGroup("output", "text")
    83         .accessLevel(AccessLevel::Offline)
    84         .defaultValues("no text");
    85     @endcode
    86 
    87     Open the shell again and try it:
    88     @code
    89     $ cout Hello World
    90     Text: Hello World
    91     $ output text Hello World
    92     Text: Hello World
    93     $ cout
    94     Text: no text
    95     @endcode
    96 
    97     If you execute it online (note: the access level is "Offline"), you will see the
    98     following (or something similar):
    99     @code
    100     $ cout Hello World
    101     Error: Can't execute command "cout", access denied.
    102     @endcode
    103 
    104     If a command is executed, the arguments are passed to an underlying function,
    105     whitch is wrapped by an orxonox::Functor which again is wrapped by an orxonox::Executor.
    106     The Functor contains the function-pointer, as well as the object-pointer in
    107     case of a non-static member-function. The executor stores possible default-values
    108     for each argument of the function.
    109 
    110     The function of a command can be changed at any time. It's possible to just exchange
    111     the function-pointer of the underlying Functor if the headers of the functions are
    112     exactly the same. But you can also exchange the Functor itself or even completely
    113     replace the Executor. Also the other attributes of a ConsoleCommand can be modified
    114     during the game, for example it can be activated or deactivated.
    115 
    116     To do so, the function ModifyConsoleCommand() has to be used. It returns an instance
    117     of orxonox::ConsoleCommand::ConsoleCommandManipulator which has an interface similar to
    118     orxonox::ConsoleCommand, but with slight differences. You can use it the same way like
    119     SetConsoleCommand(), meaning you can use command-chains to change different attributes at
    120     the same time. ModifyConsoleCommand() must not be executed statically, but rather in a
    121     function at some point of the execution of the program.
    122 
    123     Example:
    124     @code
    125     void myOtherCoutFunction(const std::string& text)                       // Define a new static function
    126     {
    127         orxout() << "Uppercase: " << getUppercase(text) << endl;            // Print the text in uppercase to the console
    128     }
    129 
    130     {
    131         // ...                                                              // somewhere in the code
    132 
    133         ModifyConsoleCommand("cout").setFunction(&myOtherCoutFunction);     // Modify the underlying function of the command
    134 
    135         // ...
    136     }
    137     @endcode
    138 
    139     If you now enter the command into the shell, you'll see a different behavior:
    140     @code
    141     $ cout Hello World
    142     Uppercase: HELLO WORLD
    143     $ cout
    144     Uppercase: NO TEXT
    145     @endcode
    146 
    147     A few important notes about changing functions:
    148 
    149     Instead of changing the function with setFunction(), you can also create a command-stack
    150     by using pushFunction() and popFunction(). It's important to note a few things about that,
    151     because the underlying structure of Executor and Functor has a few pitfalls:
    152      - If you push a new function-pointer, the same executor as before will be used (and, if
    153        the headers match, even the same functor can be used, which is very fast)
    154      - If you push a new Functor, the same executor as before will be used
    155      - If you push a new Executor, everything is changed
    156 
    157     Note that the executor contains the @b default @b values, so if you just exchange the
    158     Functor, the default values remain the same. However if you decide to change the default
    159     values at any point of the stack, <b>this will also change the default values on all
    160     other stack-levels</b> that share the same executor. If you don't like this behavior,
    161     you have to explicitly push a new executor before changing the default values, either by
    162     calling pushFunction(executor) or by calling pushFunction(void) which pushes a copy of
    163     the current executor to the stack.
    164 
    165     Another important point are object pointers in case of non-static member-functions.
    166     Whenever you set or push a new function, <b>you must add the object pointer again</b>
    167     because objects are stored in the Functor which is usually exchanged if you change
    168     the function.
    169 
    170     You can also use a stack for objects, but note that this <b>object-stack is different for each
    171     function</b> - so if you set a new function, the object-stack will be cleared. If you push
    172     a new function, the old object-stack is stored in the stack, so it can be restored if
    173     you pop the function.
    174 
    175     %DeclareConsoleCommand():
    176 
    177     Appart from SetConsoleCommand() you can also call DeclareConsoleCommand(). In contrast
    178     to SetConsoleCommand(), this doesn't assign a function to the command. Indeed you have
    179     to pass a function-pointer to DeclareConsoleCommand(), but it is only used to determine
    180     the header of the future command-function. This allows to declare a command statically,
    181     thus it's possible to evaluate key-bindings of this command, but the actual function
    182     can be assigned at a later point.
    183 
    184     Example:
    185     @code
    186     DeclareConsoleCommand("cout", &prototype::void__string);
    187     @endcode
    188 
    189     If you try to execute the command now, you see the following (or something similar):
    190     @code
    191     $ cout Hello World
    192     Error: Can't execute command "cout", command is not active.
    193     @endcode
    194 
    195     You first have to assign a function to use the command:
    196     @code
    197     {
    198         // ...
    199 
    200         ModifyConsoleCommand("cout").setFunction(&myCoutFunction);
    201 
    202         // ...
    203     }
    204     @endcode
    205 
    206     Now you can use it:
    207     @code
    208     $ cout Hello World
    209     Text: Hello World
    210     @endcode
    211 
    212     Note that the initial function prototype::void__string is defined in the namespace
    213     orxonox::prototype. If there's no function with the desired header, you can extend
    214     the collection of functions or simply use another function that has the same header.
     32    @brief Declaration of the orxonox::ConsoleCommand class.
    21533*/
    21634
     
    22341#include <vector>
    22442
    225 #include "util/VA_NARGS.h"
    22643#include "ArgumentCompletionFunctions.h"
    22744#include "Executor.h"
    228 
    229 
    230 /**
    231     @brief Defines a console command. The macro is overloaded for 2-4 parameters.
    232 
    233     This is an overloaded macro. Depending on the number of arguments a different
    234     overloaded implementation of the macro will be chosen.
    235 
    236     Console commands created with SetConsoleCommand() become active immediately and
    237     the given function-pointer (and optionally the object) will be used to execute
    238     the command.
    239 */
    240 #define SetConsoleCommand(...) \
    241     BOOST_PP_EXPAND(BOOST_PP_CAT(SetConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__))
    242 /**
    243     @brief This macro is executed if you call SetConsoleCommand() with 2 arguments.
    244     @param name The name (string) of the console command
    245     @param functionpointer The function-pointer of the corresponding command-function
    246 */
    247 #define SetConsoleCommand2(name, functionpointer) \
    248     SetConsoleCommandGeneric("", name, orxonox::createFunctor(functionpointer))
    249 /**
    250     @brief This macro is executed if you call SetConsoleCommand() with 3 arguments.
    251     @param group The group (string) of the console command
    252     @param name The name (string) of the console command
    253     @param functionpointer The function-pointer of the corresponding command-function
    254 */
    255 #define SetConsoleCommand3(group, name, functionpointer) \
    256     SetConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer))
    257 /**
    258     @brief This macro is executed if you call SetConsoleCommand() with 4 arguments.
    259     @param group The group (string) of the console command
    260     @param name The name (string) of the console command
    261     @param functionpointer The function-pointer of the corresponding command-function
    262     @param object The object that will be assigned to the command. Used for member-functions.
    263 */
    264 #define SetConsoleCommand4(group, name, functionpointer, object) \
    265     SetConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer, object))
    266 
    267 /// Internal macro
    268 #define SetConsoleCommandGeneric(group, name, functor) \
    269     static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) = (*orxonox::createConsoleCommand(group, name, orxonox::createExecutor(functor)))
    270 
    271 
    272 /**
    273     @brief Declares a console command. The macro is overloaded for 2-3 parameters.
    274 
    275     This is an overloaded macro. Depending on the number of arguments a different
    276     overloaded implementation of the macro will be chosen.
    277 
    278     Console commands created with DeclareConsoleCommand() don't use the the given
    279     function-pointer to execute the command, it is only used to define the header
    280     of the future command-function. The command is inactive until you manually
    281     set a function with orxonox::ModifyConsoleCommand(). You can use a different
    282     function-pointer than in the final command, as long as it has the same header.
    283 */
    284 #define DeclareConsoleCommand(...) \
    285     BOOST_PP_EXPAND(BOOST_PP_CAT(DeclareConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__))
    286 /**
    287     @brief This macro is executed if you call DeclareConsoleCommand() with 2 arguments.
    288     @param name The name (string) of the console command
    289     @param functionpointer The function-pointer of an arbitrary function that has the same header as the final function
    290 */
    291 #define DeclareConsoleCommand2(name, functionpointer) \
    292     DeclareConsoleCommandGeneric("", name, orxonox::createFunctor(functionpointer))
    293 /**
    294     @brief This macro is executed if you call DeclareConsoleCommand() with 3 arguments.
    295     @param group The group (string) of the console command
    296     @param name The name (string) of the console command
    297     @param functionpointer The function-pointer of an arbitrary function that has the same header as the final function
    298 */
    299 #define DeclareConsoleCommand3(group, name, functionpointer) \
    300     DeclareConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer))
    301 
    302 /// Internal macro
    303 #define DeclareConsoleCommandGeneric(group, name, functor) \
    304     static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __UNIQUE_NUMBER__) = (*orxonox::createConsoleCommand(group, name, orxonox::createExecutor(functor), false))
    305 
    30645
    30746namespace orxonox
     
    365104
    366105        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
    367116            /**
    368117                @brief Helper class that is used to manipulate console commands.
     
    522271
    523272        public:
     273            ConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true);
    524274            ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true);
    525275            ~ConsoleCommand();
     
    620370                { return this; }
    621371
     372            inline const std::vector<CommandName>& getNames()
     373                { return this->names_; }
     374
    622375        private:
     376            void init(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized);
     377
    623378            bool headersMatch(const FunctorPtr& functor);
    624379            bool headersMatch(const ExecutorPtr& executor);
     
    641396            AccessLevel::Enum accessLevel_;                                 ///< The access level (the state of the game in which you can access the command)
    642397            std::string baseName_;                                          ///< The name that was first assigned to the command
     398            std::vector<CommandName> names_;                                ///< All names and aliases of this command
    643399            FunctorPtr baseFunctor_;                                        ///< The functor that defines the header of the command-function
    644400
     
    655411            LanguageEntryLabel descriptionReturnvalue_;                     ///< A description of the return-value
    656412            LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];    ///< A description for each argument
    657 
    658         public:
    659             /// Returns the map with all groups and commands.
    660             static inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommands()
    661                 { return ConsoleCommand::getCommandMap(); }
    662             /// Returns the map with all groups and commands in lowercase.
    663             static inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandsLC()
    664                 { return ConsoleCommand::getCommandMapLC(); }
    665 
    666             /// Returns a command (shortcut) with given name. @param name The name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist
    667             static inline ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
    668                 { return ConsoleCommand::getCommand("", name, bPrintError); }
    669             /// Returns a command (shortcut) with given name in lowercase. @param name The lowercase name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist
    670             static inline ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false)
    671                 { return ConsoleCommand::getCommandLC("", name, bPrintError); }
    672 
    673             static ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
    674             static ConsoleCommand* getCommandLC(const std::string& group, const std::string& name, bool bPrintError = false);
    675 
    676             static void destroyAll();
    677 
    678         private:
    679             static std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandMap();
    680             static std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandMapLC();
    681 
    682             static void registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command);
    683             static void unregisterCommand(ConsoleCommand* command);
    684413    };
    685 
    686     /**
    687         @brief Creates a new ConsoleCommand.
    688         @param name The name of the command
    689         @param executor The executor of the command
    690         @param bInitialized If true, the command is ready to be executed, otherwise it has to be activated first.
    691     */
    692     inline ConsoleCommand* createConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
    693         { return new ConsoleCommand("", name, executor, bInitialized); }
    694     /**
    695         @brief Creates a new ConsoleCommand.
    696         @param group The group of the command
    697         @param name The name of the command
    698         @param executor The executor of the command
    699         @param bInitialized If true, the command is ready to be executed, otherwise it has to be activated first.
    700     */
    701     inline ConsoleCommand* createConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
    702         { return new ConsoleCommand(group, name, executor, bInitialized); }
    703 
    704 
    705     /**
    706         @brief Returns a manipulator for a command with the given name.
    707 
    708         @note If the command doesn't exist, the manipulator contains a NULL pointer to the command,
    709         but it can still be used without checks, because all functions of ConsoleCommandManipulator
    710         check internally if the command exists.
    711     */
    712     inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& name)
    713         { return ConsoleCommand::getCommand(name, true); }
    714     /**
    715         @brief Returns a manipulator for a command with the given group and name.
    716 
    717         @note If the command doesn't exist, the manipulator contains a NULL pointer to the command,
    718         but it can still be used without checks, because all functions of ConsoleCommandManipulator
    719         check internally if the command exists.
    720     */
    721     inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& group, const std::string& name)
    722         { return ConsoleCommand::getCommand(group, name, true); }
    723414}
    724415
  • code/trunk/src/libraries/core/command/ConsoleCommandCompilation.cc

    r8858 r10624  
    4141#include "util/ExprParser.h"
    4242#include "util/StringUtils.h"
    43 #include "ConsoleCommand.h"
     43#include "ConsoleCommandIncludes.h"
    4444#include "CommandExecutor.h"
    4545
  • code/trunk/src/libraries/core/command/IRC.cc

    r8858 r10624  
    3939#include "util/Exception.h"
    4040#include "util/StringUtils.h"
    41 #include "ConsoleCommand.h"
     41#include "ConsoleCommandIncludes.h"
    4242#include "TclThreadManager.h"
    4343
  • code/trunk/src/libraries/core/command/Shell.cc

    r9667 r10624  
    4242#include "core/config/ConfigFileManager.h"
    4343#include "core/config/ConfigValueIncludes.h"
    44 #include "core/PathConfig.h"
     44#include "core/ApplicationPaths.h"
    4545#include "core/input/InputBuffer.h"
    4646#include "CommandExecutor.h"
     
    8484
    8585        // Choose the default level according to the path Orxonox was started (build directory or not)
    86         OutputLevel defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
     86        OutputLevel defaultDebugLevel = (ApplicationPaths::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
    8787        this->setLevelMax(defaultDebugLevel);
    8888
     
    164164    void Shell::devModeChanged(bool value)
    165165    {
    166         bool isNormal = (value == PathConfig::buildDirectoryRun());
     166        bool isNormal = (value == ApplicationPaths::buildDirectoryRun());
    167167        if (isNormal)
    168168        {
  • code/trunk/src/libraries/core/command/Shell.h

    r9667 r10624  
    4949
    5050#include "util/output/BaseWriter.h"
    51 #include "core/Core.h"
     51#include "core/CoreConfig.h"
    5252
    5353namespace orxonox
  • code/trunk/src/libraries/core/command/TclBind.cc

    r9550 r10624  
    3737#include "util/Exception.h"
    3838#include "util/StringUtils.h"
    39 #include "core/PathConfig.h"
     39#include "core/ApplicationPaths.h"
    4040#include "CommandExecutor.h"
    41 #include "ConsoleCommand.h"
     41#include "ConsoleCommandIncludes.h"
    4242#include "TclThreadManager.h"
    4343
     
    143143    {
    144144#ifdef DEPENDENCY_PACKAGE_ENABLE
    145         if (PathConfig::buildDirectoryRun())
     145        if (ApplicationPaths::buildDirectoryRun())
    146146            return (std::string(specialConfig::dependencyLibraryDirectory) + "/tcl");
    147147        else
    148             return (PathConfig::getRootPathString() + specialConfig::defaultLibraryPath + "/tcl");
     148            return (ApplicationPaths::getRootPathString() + specialConfig::defaultLibraryPath + "/tcl");
    149149#else
    150150        return "";
  • code/trunk/src/libraries/core/command/TclThreadManager.cc

    r8858 r10624  
    4747#include "core/CoreIncludes.h"
    4848#include "CommandExecutor.h"
    49 #include "ConsoleCommand.h"
     49#include "ConsoleCommandIncludes.h"
    5050#include "TclBind.h"
    5151#include "TclThreadList.h"
Note: See TracChangeset for help on using the changeset viewer.