Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more exists functions to ClassList, and improved shellcompletion

File size: 4.6 KB
Line 
1/*!
2 * @file shell_command.h
3 * Definition of a on-screen-shell
4 */
5
6#ifndef _SHELL_COMMAND_H
7#define _SHELL_COMMAND_H
8
9#include "base_object.h"
10
11#include "executor/executor.h"
12#include <stdarg.h>
13
14#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
15
16
17
18namespace OrxShell
19{
20  // FORWARD DECLARATION
21  class ShellCommandClass;
22  class ShellCommandAlias;
23
24  /**
25   * @brief 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)
39#define SHELL_COMMAND(command, class, function) \
40           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
41
42  /**
43   * @brief 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   */
55#define SHELL_COMMAND_STATIC(command, class, function) \
56           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
57
58
59
60  //! a baseClass for all possible ShellCommands
61  class ShellCommand : public BaseObject
62  {
63    friend class ShellCommandClass;
64  public:
65    static bool execute (const std::string& executionString);
66
67    ShellCommand* describe(const std::string& description);
68    ShellCommand* setAlias(const std::string& alias);
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);
72
73    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, const Executor& executor);
74    static void unregisterCommand(const std::string& commandName, const std::string& className);
75    static bool exists(const std::string& commandName, const std::string& className);
76
77    static void debug();
78
79  protected:
80    ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor);
81    virtual ~ShellCommand();
82
83    static const std::string& paramToString(long parameter);
84
85  private:
86    ShellCommandClass*               shellClass;            //!< A Pointer to the Shell-Class this Command belongs to.
87    ShellCommandAlias*               alias;                 //!< An Alias for the Class.
88
89    std::string                      description;           //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla");
90    Executor*                        executor;              //!< The Executor, that really executes the Function.
91  };
92
93  //! A Class, that handles aliases.
94  class ShellCommandAlias
95  {
96  public:
97    ShellCommandAlias(const std::string& aliasName, ShellCommand* command);
98    ~ShellCommandAlias();
99
100    /** @returns the Name of the Alias. */
101    const std::string& getName() const { return this->aliasName; };
102    /** @returns the Command, this Alias is asociated with */
103    ShellCommand* getCommand() const { return this->command; };
104    static bool getCommandListOfAlias(std::list<std::string>& stringList);
105    static const std::vector<ShellCommandAlias*>& getAliases() { return ShellCommandAlias::aliasList; };
106
107  private:
108    std::string     aliasName;       //!< the name of the Alias
109    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
110
111    static std::vector<ShellCommandAlias*> aliasList; //!< A list of Aliases to A Commands.
112  };
113
114}
115
116#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.