Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2008, 1:33:42 AM (16 years ago)
Author:
landauf
Message:

big commit, but not much changes in code:

  • put CommandEvaluation into it's own .cc and .h files
  • put some basic ConsoleCommands into ConsoleCommandCompilation.cc and .h
  • created a new class, ConsoleCommand, inheriting from ExecutorStatic, implementing all command-related features that were located in the Executor until now (at the moment only accessLevel_, but more will come - from reto and me)
  • renamed ConsoleCommand-macros to SetConsoleCommand (all related macros were changed the same way)
  • added a new command named "killdelays", that kills all delayed commands. helpful to stop disco ;)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/CommandExecutor.h

    r1255 r1341  
    3232#include "CorePrereqs.h"
    3333
    34 #include <string>
    3534#include <map>
    36 #include <list>
    3735
    38 #include "util/SubString.h"
    39 #include "util/MultiTypeMath.h"
     36#include "CommandEvaluation.h"
    4037
    4138#define COMMAND_EXECUTOR_CURSOR "$"
     
    4340namespace orxonox
    4441{
    45     enum CommandState
    46     {
    47         CS_Uninitialized,
    48         CS_Empty,
    49         CS_FunctionClass_Or_Shortcut_Or_Keyword,
    50         CS_Shortcut_Params,
    51         CS_Shortcut_Finished,
    52         CS_Function,
    53         CS_Function_Params,
    54         CS_Function_Finished,
    55         CS_ConfigValueClass,
    56         CS_ConfigValue,
    57         CS_ConfigValueType,
    58         CS_ConfigValueFinished,
    59         CS_KeybindKey,
    60         CS_KeybindCommand,
    61         CS_KeybindFinished,
    62         CS_Error
    63     };
    64 
    65     void source(const std::string& filename);
    66     std::string echo(const std::string& text);
    67     void puts(bool newline, const std::string& test);
    68 
    69     void write(const std::string& filename, const std::string& text);
    70     void append(const std::string& filename, const std::string& text);
    71     std::string read(const std::string& filename);
    72 
    73     enum KeybindMode {}; // temporary
    74 
    75     ///////////////////////
    76     // CommandEvaluation //
    77     ///////////////////////
    78     class _CoreExport CommandEvaluation
    79     {
    80         friend class CommandExecutor;
    81 
    82         public:
    83             CommandEvaluation();
    84 
    85             KeybindMode getKeybindMode();
    86             bool isValid() const;
    87 
    88             inline void setAdditionalParameter(const std::string& param)
    89                 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }
    90             inline std::string getAdditionalParameter() const
    91                 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }
    92 
    93             void setEvaluatedParameter(unsigned int index, MultiTypeMath param);
    94             MultiTypeMath getEvaluatedParameter(unsigned int index) const;
    95 
    96             void evaluateParams();
    97 
    98             bool hasReturnvalue() const;
    99             MultiTypeMath getReturnvalue() const;
    100 
    101         private:
    102             std::string processedCommand_;
    103             SubString tokens_;
    104             std::string additionalParameter_;
    105 
    106             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctionClasses_;
    107             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleShortcuts_;
    108             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;
    109             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValueClasses_;
    110             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValues_;
    111             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleKeys_;
    112 
    113             Identifier* functionclass_;
    114             Identifier* configvalueclass_;
    115             ExecutorStatic* shortcut_;
    116             ExecutorStatic* function_;
    117             ConfigValueContainer* configvalue_;
    118             ConfigValueContainer* key_;
    119 
    120             std::string errorMessage_;
    121             CommandState state_;
    122 
    123             bool bEvaluatedParams_;
    124             MultiTypeMath param_[5];
    125             ExecutorStatic* evaluatedExecutor_;
    126     };
    127 
    128     /////////////////////
    129     // CommandExecutor //
    130     /////////////////////
    13142    class _CoreExport CommandExecutor
    13243    {
     
    14556            static const CommandEvaluation& getLastEvaluation();
    14657
    147             static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
    148             static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);
    149             static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);
     58            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command);
     59            static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
     60            static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
    15061
    15162            /** @brief Returns the map that stores all console commands. @return The const_iterator */
    152             static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
     63            static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
    15364            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
    154             static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
     65            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
    15566            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
    156             static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
     67            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
    15768
    15869            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
    159             static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
     70            static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
    16071            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    161             static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
     72            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
    16273            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    163             static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
     74            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
    16475
    16576        private:
     
    191102
    192103            static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
    193             static std::string dump(const ExecutorStatic* executor);
     104            static std::string dump(const ConsoleCommand* command);
    194105            static std::string dump(const ConfigValueContainer* container);
    195106
     
    197108
    198109            static Identifier* getIdentifierOfPossibleFunctionClass(const std::string& name);
    199             static ExecutorStatic* getExecutorOfPossibleShortcut(const std::string& name);
    200             static ExecutorStatic* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier);
     110            static ConsoleCommand* getExecutorOfPossibleShortcut(const std::string& name);
     111            static ConsoleCommand* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier);
    201112            static Identifier* getIdentifierOfPossibleConfigValueClass(const std::string& name);
    202113            static ConfigValueContainer* getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier);
     
    205116            CommandEvaluation evaluation_;
    206117
    207             std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_;
    208             std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_;
     118            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
     119            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
    209120    };
    210121}
Note: See TracChangeset for help on using the changeset viewer.