Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 5.9 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
[9869]11/// THIS IS USED TO LOAD CONSTANT AND STATIC FUNCTIONS EASILY.
12#include "executor/executor_substring.h"
13#include "executor/functor_member.h"
14#include "executor/functor_const_member.h"
15#include "executor/functor_static.h"
16
[7407]17#include "shell_completion_plugin.h"
[5068]18
[5166]19#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
[5130]20
[7374]21namespace OrxShell
22{
23  // FORWARD DECLARATION
24  class ShellCommandClass;
25  class ShellCommandAlias;
[7407]26  class CompletorPlugin;
[3543]27
[7374]28  /**
[7398]29   * @brief an easy to use Macro to create a Command
[7374]30   * @param command the name of the command (without "" around the string)
31   * @param class the name of the class to apply this command to (without the "" around the string)
32   * @param function the function to call
33   *
34   * MEANING:
35   *  ShellCommand* someUniqueVarName =
36   *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
37   *
38   * In the Shell you would call this Command using:
39   * $ ClassName [ObjectName] commandNameInShell [parameters]
40   */
[5162]41#define SHELL_COMMAND(command, class, function) \
[9869]42           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(&class::function))
[5636]43
[7374]44  /**
[7398]45   * @brief an easy to use Macro to create a Command
[7374]46   * @param command the name of the command (without "" around the string)
47   * @param class the name of the class to apply this command to (without the "" around the string)
48   * @param function the function to call
49   *
50   * MEANING:
51   *  ShellCommand* someUniqueVarName =
52   *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
53   *
54   * In the Shell you would call this Command using:
55   * $ ClassName [ObjectName] commandNameInShell [parameters]
56   */
[5329]57#define SHELL_COMMAND_STATIC(command, class, function) \
[9869]58           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(function))
[5135]59
[5162]60
[5328]61
[7374]62  //! a baseClass for all possible ShellCommands
63  class ShellCommand : public BaseObject
64  {
[9869]65    ObjectListDeclaration(ShellCommand);
66
[7374]67    friend class ShellCommandClass;
[5161]68  public:
[7221]69    static bool execute (const std::string& executionString);
[5161]70
[7221]71    ShellCommand* describe(const std::string& description);
[7225]72    ShellCommand* setAlias(const std::string& alias);
[7198]73    ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
74                                const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
75                                const MultiType& value4 = MT_NULL);
[7412]76    ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin);
[5164]77
[9869]78    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor);
[7225]79    static void unregisterCommand(const std::string& commandName, const std::string& className);
[7408]80    static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className);
[7413]81    static const ShellCommand* const getCommand(const std::string& commandName, const ShellCommandClass* cmdClass);
[7403]82    static bool exists(const std::string& commandName, const std::string& className);
[7417]83    static const ShellCommand* const getCommandFromInput(const std::string& inputLine, unsigned int& paramBegin, std::vector<BaseObject*>* boList = NULL);
84    static const ShellCommand* const getCommandFromInput(const SubString& strings, unsigned int& paramBegin, std::vector<BaseObject*>* boList = NULL);
[5161]85
[7409]86    const ShellCommandClass* const getCommandClass() const { return this->shellClass; };
87    const ShellCommandAlias* const getAlias() const { return this->alias; }
[7407]88    unsigned int getParamCount() const { return this->executor->getParamCount(); }
89    const CompletorPlugin* const getCompletorPlugin(unsigned int i) const { return this->completors[i]; };
90
[7742]91    void help() const;
[5161]92
93  protected:
[9869]94    ShellCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor);
[7386]95    virtual ~ShellCommand();
[5161]96
[7418]97    static bool fillObjectList(const std::string& objectDescriptor, const ShellCommand* cmd, std::vector<BaseObject*>* boList);
[7401]98    static const std::string& paramToString(long parameter);
[5161]99
100  private:
[7397]101    ShellCommandClass*               shellClass;            //!< A Pointer to the Shell-Class this Command belongs to.
102    ShellCommandAlias*               alias;                 //!< An Alias for the Class.
[5161]103
[7397]104    std::string                      description;           //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla");
[7407]105    std::vector<CompletorPlugin*>    completors;            //!< Completors for the Parameters
[9869]106    Executor<const SubString>*       executor;              //!< The Executor, that really executes the Function.
[7374]107  };
[5113]108
[7374]109  //! A Class, that handles aliases.
110  class ShellCommandAlias
111  {
[5190]112  public:
[7397]113    ShellCommandAlias(const std::string& aliasName, ShellCommand* command);
114    ~ShellCommandAlias();
115
[5197]116    /** @returns the Name of the Alias. */
[7221]117    const std::string& getName() const { return this->aliasName; };
[5197]118    /** @returns the Command, this Alias is asociated with */
[5636]119    ShellCommand* getCommand() const { return this->command; };
[7389]120    static bool getCommandListOfAlias(std::list<std::string>& stringList);
[7397]121    static const std::vector<ShellCommandAlias*>& getAliases() { return ShellCommandAlias::aliasList; };
[5196]122
[5190]123  private:
[7221]124    std::string     aliasName;       //!< the name of the Alias
[5636]125    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
[7389]126
127    static std::vector<ShellCommandAlias*> aliasList; //!< A list of Aliases to A Commands.
[7374]128  };
[5190]129
[7374]130}
131
[5129]132#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.