Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5678 was 5642, checked in by bensch, 19 years ago

orxonox/trunk: valgrind sweep

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