Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: valgrind sweep

File size: 4.4 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, 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, 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, const 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, const Executor& executor);
82    ~ShellCommand();
83
84    static bool isRegistered(const char* commandName, const char* className, const Executor& executor);
85    static const char* paramToString(long parameter);
86
87  protected:
88    MultiType*                       defaultValue;                         //!< Default Values.
89
90  private:
91    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
92    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
93
94    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
95    Executor*                        executor;                             //!< The Executor, that really executes the Function.
96
97};
98
99//! A Class, that handles aliases.
100class ShellCommandAlias
101{
102  friend class ShellCommand;
103  public:
104    /** @returns the Name of the Alias. */
105    const char* getName() const { return this->aliasName; };
106    /** @returns the Command, this Alias is asociated with */
107    ShellCommand* getCommand() const { return this->command; };
108
109  private:
110    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
111    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
112
113  private:
114    const char*         aliasName;       //!< the name of the Alias
115    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
116};
117
118#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.