Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: parameters of Executor are const void* instead of const char*

File size: 4.3 KB
RevLine 
[4838]1/*!
[5129]2 * @file shell_command.h
[5068]3 * Definition of a on-screen-shell
[5391]4 */
[1853]5
[5129]6#ifndef _SHELL_COMMAND_H
7#define _SHELL_COMMAND_H
[1853]8
[5129]9#include "base_object.h"
[1853]10
[5636]11#include "executor/executor.h"
[5068]12#include <stdarg.h>
13
[5166]14#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
[5130]15
[5127]16
[5130]17
[4838]18// FORWARD DECLARATION
[5068]19template<class T> class tList;
[5639]20class ShellCommandClass;
21class ShellCommandAlias;
[3543]22
[5166]23/**
24 * an easy to use Macro to create a Command
25 * @param command the name of the command (without "" around the string)
26 * @param class the name of the class to apply this command to (without the "" around the string)
27 * @param function the function to call
[5179]28 *
29 * MEANING:
[5636]30 *  ShellCommand* someUniqueVarName =
[5179]31 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
32 *
33 * In the Shell you would call this Command using:
34 * $ ClassName [ObjectName] commandNameInShell [parameters]
[5166]35 */
[5636]36//#define SHELL_COMMAND(command, class, function) \
37//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
[5162]38#define SHELL_COMMAND(command, class, function) \
[5641]39           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
[5636]40
[5329]41/**
42 * an easy to use Macro to create a Command
43 * @param command the name of the command (without "" around the string)
44 * @param class the name of the class to apply this command to (without the "" around the string)
45 * @param function the function to call
46 *
47 * MEANING:
[5636]48 *  ShellCommand* someUniqueVarName =
[5329]49 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
50 *
51 * In the Shell you would call this Command using:
52 * $ ClassName [ObjectName] commandNameInShell [parameters]
53 */
54#define SHELL_COMMAND_STATIC(command, class, function) \
[5641]55           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
[5135]56
[5162]57
[5328]58
[5161]59//! a baseClass for all possible ShellCommands
[5636]60class ShellCommand : public BaseObject
[5161]61{
[5170]62  friend class ShellCommandClass;
[5161]63  public:
64    static bool execute (const char* executionString);
65
[5636]66    ShellCommand* describe(const char* description);
67    ShellCommand* setAlias(const char* alias);
68    ShellCommand* defaultValues(unsigned int count, ...);
[5164]69
[5641]70    static ShellCommand* registerCommand(const char* commandName, const char* className, const Executor& executor);
[5636]71
[5166]72    static void unregisterCommand(const char* commandName, const char* className);
[5161]73
74    static void debug();
75
76  protected:
[5641]77    ShellCommand(const char* commandName, const char* className, const Executor& executor);
[5636]78    ~ShellCommand();
[5161]79
[5641]80    static bool isRegistered(const char* commandName, const char* className, const Executor& executor);
[5161]81    static const char* paramToString(long parameter);
82
83  protected:
[5552]84    MultiType*                       defaultValue;                         //!< Default Values.
[5161]85
86  private:
[5170]87    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
[5196]88    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
[5161]89
[5166]90    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
[5642]91    Executor*                        executor;                             //!< The Executor, that really executes the Function.
[5161]92
[5129]93};
[5113]94
[5197]95//! A Class, that handles aliases.
[5190]96class ShellCommandAlias
97{
[5636]98  friend class ShellCommand;
[5190]99  public:
[5197]100    /** @returns the Name of the Alias. */
[5195]101    const char* getName() const { return this->aliasName; };
[5197]102    /** @returns the Command, this Alias is asociated with */
[5636]103    ShellCommand* getCommand() const { return this->command; };
[5196]104
[5190]105  private:
[5197]106    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
[5636]107    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
[5196]108
109  private:
[5197]110    const char*         aliasName;       //!< the name of the Alias
[5636]111    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[5190]112};
113
[5129]114#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.