Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell_command.h @ 7389

Last change on this file since 7389 was 7389, checked in by bensch, 18 years ago

orxonox/trunk: new and improved ShellCommandAlias

File size: 4.7 KB
RevLine 
[4838]1/*!
[5129]2 * @file shell_command.h
[5068]3 * Definition of a on-screen-shell
[5391]4 */
[1853]5
[5129]6#ifndef _SHELL_COMMAND_H
7#define _SHELL_COMMAND_H
[1853]8
[5129]9#include "base_object.h"
[1853]10
[5636]11#include "executor/executor.h"
[5068]12#include <stdarg.h>
13
[5166]14#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
[5130]15
[5127]16
[5130]17
[7374]18namespace OrxShell
19{
20  // FORWARD DECLARATION
21  class ShellCommandClass;
22  class ShellCommandAlias;
[3543]23
[7374]24  /**
25   * an easy to use Macro to create a Command
26   * @param command the name of the command (without "" around the string)
27   * @param class the name of the class to apply this command to (without the "" around the string)
28   * @param function the function to call
29   *
30   * MEANING:
31   *  ShellCommand* someUniqueVarName =
32   *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
33   *
34   * In the Shell you would call this Command using:
35   * $ ClassName [ObjectName] commandNameInShell [parameters]
36   */
37  //#define SHELL_COMMAND(command, class, function) \
38  //        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
[5162]39#define SHELL_COMMAND(command, class, function) \
[7374]40           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
[5636]41
[7374]42  /**
43   * an easy to use Macro to create a Command
44   * @param command the name of the command (without "" around the string)
45   * @param class the name of the class to apply this command to (without the "" around the string)
46   * @param function the function to call
47   *
48   * MEANING:
49   *  ShellCommand* someUniqueVarName =
50   *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
51   *
52   * In the Shell you would call this Command using:
53   * $ ClassName [ObjectName] commandNameInShell [parameters]
54   */
[5329]55#define SHELL_COMMAND_STATIC(command, class, function) \
[7374]56           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
[5135]57
[5162]58
[5328]59
[7374]60  //! a baseClass for all possible ShellCommands
61  class ShellCommand : public BaseObject
62  {
63    friend class ShellCommandClass;
[5161]64  public:
[7221]65    static bool execute (const std::string& executionString);
[5161]66
[7221]67    ShellCommand* describe(const std::string& description);
[7225]68    ShellCommand* setAlias(const std::string& alias);
[7198]69    ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
70                                const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
71                                const MultiType& value4 = MT_NULL);
[5164]72
[7225]73    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, const Executor& executor);
[5636]74
[7225]75    static void unregisterCommand(const std::string& commandName, const std::string& className);
[5161]76
77    static void debug();
78
79  protected:
[7225]80    ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor);
[7386]81    virtual ~ShellCommand();
[5161]82
[7225]83    static bool isRegistered(const std::string& commandName, const std::string& className);
[5161]84    static const char* paramToString(long parameter);
85
86  private:
[5170]87    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
[5196]88    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
[5161]89
[7388]90    std::string                      description;                          //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla");
[5642]91    Executor*                        executor;                             //!< The Executor, that really executes the Function.
[7374]92  };
[5113]93
[7374]94  //! A Class, that handles aliases.
95  class ShellCommandAlias
96  {
97    friend class ShellCommand;
[5190]98  public:
[5197]99    /** @returns the Name of the Alias. */
[7221]100    const std::string& getName() const { return this->aliasName; };
[5197]101    /** @returns the Command, this Alias is asociated with */
[5636]102    ShellCommand* getCommand() const { return this->command; };
[7389]103    static bool getCommandListOfAlias(std::list<std::string>& stringList);
[5196]104
[5190]105  private:
[5197]106    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
[7389]107    ShellCommandAlias(const std::string& aliasName, ShellCommand* command);
108    ~ShellCommandAlias();
[5196]109  private:
[7221]110    std::string     aliasName;       //!< the name of the Alias
[5636]111    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[7389]112
113    static std::vector<ShellCommandAlias*> aliasList; //!< A list of Aliases to A Commands.
[7374]114  };
[5190]115
[7374]116}
117
[5129]118#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.