Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: splitted shell_command into shell_command and shell_command_class

File size: 5.1 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 "helper_functions.h"
12#include "multi_type.h"
13#include "substring.h"
14#include "functor_list.h"
15#include "executor/executor.h"
16#include <stdarg.h>
17
18#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
19
20
21
22// FORWARD DECLARATION
23template<class T> class tList;
24class ShellCommandClass;
25class ShellCommandAlias;
26
27/**
28 * an easy to use Macro to create a Command
29 * @param command the name of the command (without "" around the string)
30 * @param class the name of the class to apply this command to (without the "" around the string)
31 * @param function the function to call
32 *
33 * MEANING:
34 *  ShellCommand* someUniqueVarName =
35 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
36 *
37 * In the Shell you would call this Command using:
38 * $ ClassName [ObjectName] commandNameInShell [parameters]
39 */
40//#define SHELL_COMMAND(command, class, function) \
41//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
42#define SHELL_COMMAND(command, class, function) \
43           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function))
44
45/**
46 * an easy to use Macro to create a Command
47 * @param command the name of the command (without "" around the string)
48 * @param class the name of the class to apply this command to (without the "" around the string)
49 * @param function the function to call
50 *
51 * MEANING:
52 *  ShellCommand* someUniqueVarName =
53 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
54 *
55 * In the Shell you would call this Command using:
56 * $ ClassName [ObjectName] commandNameInShell [parameters]
57 */
58#define SHELL_COMMAND_STATIC(command, class, function) \
59           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function))
60
61
62//! an enumerator for the definition of the Type.
63typedef enum {
64  ShellCommand_Objective = 1,
65  ShellCommand_Static    = 2,
66} ShellCommand_Type;
67
68//! a baseClass for all possible ShellCommands
69class ShellCommand : public BaseObject
70{
71  friend class ShellCommandClass;
72  public:
73    static bool execute (const char* executionString);
74
75    ShellCommand* describe(const char* description);
76    ShellCommand* setAlias(const char* alias);
77    ShellCommand* defaultValues(unsigned int count, ...);
78
79    static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor);
80
81    static void unregisterCommand(const char* commandName, const char* className);
82
83    static void debug();
84
85  protected:
86    ShellCommand(const char* commandName, const char* className, Executor* executor);
87    ~ShellCommand();
88
89    /** @returns the Type of this Function (either static or objective) */
90    inline ShellCommand_Type getType() { return this->functorType; };
91
92    static bool isRegistered(const char* commandName, const char* className, Executor* executor);
93    static const char* paramToString(long parameter);
94
95  protected:
96    ShellCommand_Type                functorType;                          //!< The type of Function we've got (either static or objective).
97    void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
98    unsigned int                     paramCount;                           //!< the count of parameters.
99    unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
100    MultiType*                       defaultValue;                         //!< Default Values.
101
102  private:
103    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
104    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
105
106    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
107    Executor*                        executor;
108
109};
110
111//! A Class, that handles aliases.
112class ShellCommandAlias
113{
114  friend class ShellCommand;
115  public:
116    /** @returns the Name of the Alias. */
117    const char* getName() const { return this->aliasName; };
118    /** @returns the Command, this Alias is asociated with */
119    ShellCommand* getCommand() const { return this->command; };
120
121  private:
122    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
123    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
124
125  private:
126    const char*         aliasName;       //!< the name of the Alias
127    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
128};
129
130#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.