Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: default Values work, and small fix with unused ShellCommand_Type

File size: 4.7 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
63//! a baseClass for all possible ShellCommands
64class ShellCommand : public BaseObject
65{
66  friend class ShellCommandClass;
67  public:
68    static bool execute (const char* executionString);
69
70    ShellCommand* describe(const char* description);
71    ShellCommand* setAlias(const char* alias);
72    ShellCommand* defaultValues(unsigned int count, ...);
73
74    static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor);
75
76    static void unregisterCommand(const char* commandName, const char* className);
77
78    static void debug();
79
80  protected:
81    ShellCommand(const char* commandName, const char* className, Executor* executor);
82    ~ShellCommand();
83
84    static bool isRegistered(const char* commandName, const char* className, Executor* executor);
85    static const char* paramToString(long parameter);
86
87  protected:
88    void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
89    unsigned int                     paramCount;                           //!< the count of parameters.
90    unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
91    MultiType*                       defaultValue;                         //!< Default Values.
92
93  private:
94    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
95    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
96
97    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
98    Executor*                        executor;
99
100};
101
102//! A Class, that handles aliases.
103class ShellCommandAlias
104{
105  friend class ShellCommand;
106  public:
107    /** @returns the Name of the Alias. */
108    const char* getName() const { return this->aliasName; };
109    /** @returns the Command, this Alias is asociated with */
110    ShellCommand* getCommand() const { return this->command; };
111
112  private:
113    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
114    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
115
116  private:
117    const char*         aliasName;       //!< the name of the Alias
118    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
119};
120
121#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.