Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more std::string

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