Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7368 was 7368, checked in by bensch, 18 years ago

orxonox/trunk: some renamings, and GameWorldData now has lists for what EntityLists should be drawed/ticked/collided(not yet implemented).

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