Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/shared_lib/src/lib/shell/shell_command.h @ 9722

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

this really should compile and link (not at runtime) on windows

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