Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6451 was 5784, checked in by bensch, 19 years ago

orxonox/trunk: shell without tList now

File size: 4.2 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
[5639]19class ShellCommandClass;
20class ShellCommandAlias;
[3543]21
[5166]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
[5179]27 *
28 * MEANING:
[5636]29 *  ShellCommand* someUniqueVarName =
[5179]30 *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
31 *
32 * In the Shell you would call this Command using:
33 * $ ClassName [ObjectName] commandNameInShell [parameters]
[5166]34 */
[5636]35//#define SHELL_COMMAND(command, class, function) \
36//        ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
[5162]37#define SHELL_COMMAND(command, class, function) \
[5641]38           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorObjective<class>(&class::function))
[5636]39
[5329]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:
[5636]47 *  ShellCommand* someUniqueVarName =
[5329]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) \
[5641]54           ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, ExecutorStatic<class>(function))
[5135]55
[5162]56
[5328]57
[5161]58//! a baseClass for all possible ShellCommands
[5636]59class ShellCommand : public BaseObject
[5161]60{
[5170]61  friend class ShellCommandClass;
[5161]62  public:
63    static bool execute (const char* executionString);
64
[5636]65    ShellCommand* describe(const char* description);
66    ShellCommand* setAlias(const char* alias);
67    ShellCommand* defaultValues(unsigned int count, ...);
[5164]68
[5641]69    static ShellCommand* registerCommand(const char* commandName, const char* className, const Executor& executor);
[5636]70
[5166]71    static void unregisterCommand(const char* commandName, const char* className);
[5161]72
73    static void debug();
74
75  protected:
[5641]76    ShellCommand(const char* commandName, const char* className, const Executor& executor);
[5636]77    ~ShellCommand();
[5161]78
[5641]79    static bool isRegistered(const char* commandName, const char* className, const Executor& executor);
[5161]80    static const char* paramToString(long parameter);
81
82  protected:
[5552]83    MultiType*                       defaultValue;                         //!< Default Values.
[5161]84
85  private:
[5170]86    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
[5196]87    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
[5161]88
[5166]89    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
[5642]90    Executor*                        executor;                             //!< The Executor, that really executes the Function.
[5161]91
[5129]92};
[5113]93
[5197]94//! A Class, that handles aliases.
[5190]95class ShellCommandAlias
96{
[5636]97  friend class ShellCommand;
[5190]98  public:
[5197]99    /** @returns the Name of the Alias. */
[5195]100    const char* getName() const { return this->aliasName; };
[5197]101    /** @returns the Command, this Alias is asociated with */
[5636]102    ShellCommand* getCommand() const { return this->command; };
[5196]103
[5190]104  private:
[5197]105    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
[5636]106    ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
[5196]107
108  private:
[5779]109    const char*     aliasName;       //!< the name of the Alias
[5636]110    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[5190]111};
112
[5129]113#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.