Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/collision_detection/src/lib/shell/shell_command.h @ 6776

Last change on this file since 6776 was 5690, checked in by bensch, 19 years ago

orxonox/trunk: parameters of Executor are const void* instead of const char*

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