Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/lib/shell/shell_command.h @ 6685

Last change on this file since 6685 was 5784, checked in by bensch, 19 years ago

orxonox/trunk: shell without tList now

File size: 4.2 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
18// FORWARD DECLARATION
19class ShellCommandClass;
20class ShellCommandAlias;
21
22/**
23 * an easy to use Macro to create a Command
24 * @param command the name of the command (without "" around the string)
25 * @param class the name of the class to apply this command to (without the "" around the string)
26 * @param function the function to call
27 *
28 * MEANING:
29 *  ShellCommand* someUniqueVarName =
30 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
31 *
32 * In the Shell you would call this Command using:
33 * $ ClassName [ObjectName] commandNameInShell [parameters]
34 */
35//#define SHELL_COMMAND(command, class, function) \
36//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
37#define SHELL_COMMAND(command, class, function) \
38           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
39
40/**
41 * an easy to use Macro to create a Command
42 * @param command the name of the command (without "" around the string)
43 * @param class the name of the class to apply this command to (without the "" around the string)
44 * @param function the function to call
45 *
46 * MEANING:
47 *  ShellCommand* someUniqueVarName =
48 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
49 *
50 * In the Shell you would call this Command using:
51 * $ ClassName [ObjectName] commandNameInShell [parameters]
52 */
53#define SHELL_COMMAND_STATIC(command, class, function) \
54           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
55
56
57
58//! a baseClass for all possible ShellCommands
59class ShellCommand : public BaseObject
60{
61  friend class ShellCommandClass;
62  public:
63    static bool execute (const char* executionString);
64
65    ShellCommand* describe(const char* description);
66    ShellCommand* setAlias(const char* alias);
67    ShellCommand* defaultValues(unsigned int count, ...);
68
69    static ShellCommand* registerCommand(const char* commandName, const char* className, const Executor& executor);
70
71    static void unregisterCommand(const char* commandName, const char* className);
72
73    static void debug();
74
75  protected:
76    ShellCommand(const char* commandName, const char* className, const Executor& executor);
77    ~ShellCommand();
78
79    static bool isRegistered(const char* commandName, const char* className, const Executor& executor);
80    static const char* paramToString(long parameter);
81
82  protected:
83    MultiType*                       defaultValue;                         //!< Default Values.
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    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
90    Executor*                        executor;                             //!< The Executor, that really executes the Function.
91
92};
93
94//! A Class, that handles aliases.
95class ShellCommandAlias
96{
97  friend class ShellCommand;
98  public:
99    /** @returns the Name of the Alias. */
100    const char* getName() const { return this->aliasName; };
101    /** @returns the Command, this Alias is asociated with */
102    ShellCommand* getCommand() const { return this->command; };
103
104  private:
105    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
106    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
107
108  private:
109    const char*     aliasName;       //!< the name of the Alias
110    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
111};
112
113#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.