Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1341 for code


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 ;)
Location:
code/branches/console/src
Files:
4 added
22 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/CMakeLists.txt

    r1313 r1341  
    1717  OutputBuffer.cc
    1818  InputBuffer.cc
     19  Shell.cc
    1920  CommandExecutor.cc
    20   Shell.cc
     21  CommandEvaluation.cc
     22  ConsoleCommandCompilation.cc
    2123  Language.cc
    2224  ClassTreeMask.cc
  • code/branches/console/src/core/CommandExecutor.cc

    r1276 r1341  
    4444namespace orxonox
    4545{
    46     ConsoleCommandShortcutGeneric(keyword1, createExecutor((FunctorStatic*)0, "set", AccessLevel::User));
    47     ConsoleCommandShortcutGeneric(keyword2, createExecutor((FunctorStatic*)0, "tset", AccessLevel::User));
    48     ConsoleCommandShortcutGeneric(keyword3, createExecutor((FunctorStatic*)0, "bind", AccessLevel::User));
    49 
    50     ConsoleCommandShortcutExtern(source, AccessLevel::None);
    51     ConsoleCommandShortcutExtern(echo, AccessLevel::None);
    52     ConsoleCommandShortcutExtern(puts, AccessLevel::None);
    53 
    54     ConsoleCommandShortcutExtern(read, AccessLevel::None);
    55     ConsoleCommandShortcutExtern(append, AccessLevel::None);
    56     ConsoleCommandShortcutExtern(write, AccessLevel::None);
    57 
    58     void source(const std::string& filename)
    59     {
    60         static std::set<std::string> executingFiles;
    61 
    62         std::set<std::string>::const_iterator it = executingFiles.find(filename);
    63         if (it != executingFiles.end())
    64         {
    65             COUT(1) << "Error: Recurring source command in \"" << filename << "\". Stopped execution." << std::endl;
    66             return;
    67         }
    68 
    69         // Open the file
    70         std::ifstream file;
    71         file.open(filename.c_str(), std::fstream::in);
    72 
    73         if (!file.is_open())
    74         {
    75             COUT(1) << "Error: Couldn't open file \"" << filename << "\"." << std::endl;
    76             return;
    77         }
    78 
    79         executingFiles.insert(filename);
    80 
    81         // Iterate through the file and put the lines into the CommandExecutor
    82         char line[1024];
    83         while (file.good() && !file.eof())
    84         {
    85             file.getline(line, 1024);
    86             CommandExecutor::execute(line);
    87         }
    88 
    89         executingFiles.erase(filename);
    90         file.close();
    91     }
    92 
    93     std::string echo(const std::string& text)
    94     {
    95         std::cout << text << std::endl;
    96         return text;
    97     }
    98 
    99     void puts(bool newline, const std::string& text)
    100     {
    101         if (newline)
    102             COUT(0) << text << std::endl;
    103         else
    104             COUT(0) << text;
    105     }
    106 
    107     void write(const std::string& filename, const std::string& text)
    108     {
    109         std::ofstream file;
    110         file.open(filename.c_str(), std::fstream::out);
    111 
    112         if (!file.is_open())
    113         {
    114             COUT(1) << "Error: Couldn't write to file \"" << filename << "\"." << std::endl;
    115             return;
    116         }
    117 
    118         file << text << std::endl;
    119         file.close();
    120     }
    121 
    122     void append(const std::string& filename, const std::string& text)
    123     {
    124         std::ofstream file;
    125         file.open(filename.c_str(), std::fstream::app);
    126 
    127         if (!file.is_open())
    128         {
    129             COUT(1) << "Error: Couldn't append to file \"" << filename << "\"." << std::endl;
    130             return;
    131         }
    132 
    133         file << text << std::endl;
    134         file.close();
    135     }
    136 
    137     std::string read(const std::string& filename)
    138     {
    139         std::ifstream file;
    140         file.open(filename.c_str(), std::fstream::in);
    141 
    142         if (!file.is_open())
    143         {
    144             COUT(1) << "Error: Couldn't read from file \"" << filename << "\"." << std::endl;
    145             return "";
    146         }
    147 
    148         std::string output = "";
    149         char line[1024];
    150         while (file.good() && !file.eof())
    151         {
    152             file.getline(line, 1024);
    153             output += line;
    154             output += "\n";
    155         }
    156 
    157         file.close();
    158 
    159         return output;
    160     }
    161 
    162 
    163     ///////////////////////
    164     // CommandEvaluation //
    165     ///////////////////////
    166     CommandEvaluation::CommandEvaluation()
    167     {
    168         this->processedCommand_ = "";
    169         this->additionalParameter_ = "";
    170 
    171         this->functionclass_ = 0;
    172         this->configvalueclass_ = 0;
    173         this->shortcut_ = 0;
    174         this->function_ = 0;
    175         this->configvalue_ = 0;
    176         this->key_ = 0;
    177 
    178         this->errorMessage_ = "";
    179         this->state_ = CS_Uninitialized;
    180 
    181         this->bEvaluatedParams_ = false;
    182         this->evaluatedExecutor_ = 0;
    183     }
    184 
    185     KeybindMode CommandEvaluation::getKeybindMode()
    186     {
    187         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    188         {
    189 //            if (this->shortcut_ != 0)
    190 //                return this->shortcut_->getKeybindMode();
    191         }
    192         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    193         {
    194 //            if (this->function_ != 0)
    195 //                return this->function_->getKeybindMode();
    196         }
    197         else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
    198         {
    199 //            return KeybindMode::onPress;
    200         }
    201         else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
    202         {
    203 //            return KeybindMode::onPress;
    204         }
    205         else
    206         {
    207 //            return KeybindMode::onPress;
    208         }
    209         // FIXME: Had to insert a return statement
    210         return (KeybindMode)0;
    211     }
    212 
    213     bool CommandEvaluation::isValid() const
    214     {
    215         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    216         {
    217             return this->shortcut_;
    218         }
    219         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    220         {
    221             return (this->functionclass_ && this->function_);
    222         }
    223         else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
    224         {
    225             return (this->configvalueclass_ && this->configvalue_);
    226         }
    227         else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
    228         {
    229             return this->key_;
    230         }
    231         else
    232         {
    233             return false;
    234         }
    235     }
    236 
    237     void CommandEvaluation::evaluateParams()
    238     {
    239         this->bEvaluatedParams_ = false;
    240         this->evaluatedExecutor_ = 0;
    241 
    242         for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++)
    243             this->param_[i] = MT_null;
    244 
    245         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    246         {
    247             if (this->shortcut_)
    248             {
    249                 if (this->tokens_.size() <= 1)
    250                 {
    251                     if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " "))
    252                     {
    253                         this->bEvaluatedParams_ = true;
    254                         this->evaluatedExecutor_ = this->shortcut_;
    255                     }
    256                 }
    257                 else if (this->tokens_.size() > 1)
    258                 {
    259                     if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " "))
    260                     {
    261                         this->bEvaluatedParams_ = true;
    262                         this->evaluatedExecutor_ = this->shortcut_;
    263                     }
    264                 }
    265             }
    266         }
    267         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    268         {
    269             if (this->function_)
    270             {
    271                 if (this->tokens_.size() <= 2)
    272                 {
    273                     if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))
    274                     {
    275                         this->bEvaluatedParams_ = true;
    276                         this->evaluatedExecutor_ = this->function_;
    277                     }
    278                 }
    279                 else if (this->tokens_.size() > 2)
    280                 {
    281                     if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " "))
    282                     {
    283                         this->bEvaluatedParams_ = true;
    284                         this->evaluatedExecutor_ = this->function_;
    285                     }
    286                 }
    287             }
    288         }
    289     }
    290 
    291     void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param)
    292     {
    293         if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
    294             this->param_[index] = param;
    295     }
    296 
    297     MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const
    298     {
    299         if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
    300             return this->param_[index];
    301 
    302         return MT_null;
    303     }
    304 
    305     bool CommandEvaluation::hasReturnvalue() const
    306     {
    307         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    308         {
    309             if (this->shortcut_)
    310                 return this->shortcut_->hasReturnvalue();
    311         }
    312         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    313         {
    314             if (this->function_)
    315                 return this->function_->hasReturnvalue();
    316         }
    317 
    318         return MT_null;
    319     }
    320 
    321     MultiTypeMath CommandEvaluation::getReturnvalue() const
    322     {
    323         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    324         {
    325             if (this->shortcut_)
    326                 return this->shortcut_->getReturnvalue();
    327         }
    328         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    329         {
    330             if (this->function_)
    331                 return this->function_->getReturnvalue();
    332         }
    333 
    334         return MT_null;
    335     }
    336 
    337 
    338     /////////////////////
    339     // CommandExecutor //
    340     /////////////////////
     46    SetConsoleCommandShortcutGeneric(keyword1, createExecutor((FunctorStatic*)0, "set")).setAccessLevel(AccessLevel::User);
     47    SetConsoleCommandShortcutGeneric(keyword2, createExecutor((FunctorStatic*)0, "tset")).setAccessLevel(AccessLevel::User);
     48    SetConsoleCommandShortcutGeneric(keyword3, createExecutor((FunctorStatic*)0, "bind")).setAccessLevel(AccessLevel::User);
     49
    34150    CommandExecutor& CommandExecutor::getInstance()
    34251    {
     
    35564    }
    35665
    357     Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
    358     {
    359         CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor;
    360         CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor;
    361         return (*executor);
     66    ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command)
     67    {
     68        CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
     69        CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(command->getName())] = command;
     70        return (*command);
    36271    }
    36372
     
    36776        @return The executor of the requested console command shortcut
    36877    */
    369     ExecutorStatic* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
    370     {
    371         std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
     78    ConsoleCommand* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
     79    {
     80        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
    37281        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
    37382            return (*it).second;
     
    38190        @return The executor of the requested console command shortcut
    38291    */
    383     ExecutorStatic* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
    384     {
    385         std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
     92    ConsoleCommand* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
     93    {
     94        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
    38695        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end())
    38796            return (*it).second;
     
    1187896    void CommandExecutor::createListOfPossibleShortcuts(const std::string& fragment)
    1188897    {
    1189         for (std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
     898        for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
    1190899        {
    1191900            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
     
    1200909    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
    1201910    {
    1202         for (std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
     911        for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
    1203912        {
    1204913            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
     
    1261970    }
    1262971
    1263     ExecutorStatic* CommandExecutor::getExecutorOfPossibleShortcut(const std::string& name)
    1264     {
    1265         std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name));
     972    ConsoleCommand* CommandExecutor::getExecutorOfPossibleShortcut(const std::string& name)
     973    {
     974        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name));
    1266975        if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
    1267976            return (*it).second;
     
    1270979    }
    1271980
    1272     ExecutorStatic* CommandExecutor::getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier)
    1273     {
    1274         std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name));
     981    ConsoleCommand* CommandExecutor::getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier)
     982    {
     983        std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name));
    1275984        if (it != identifier->getLowercaseConsoleCommandMapEnd())
    1276985            return (*it).second;
     
    13191028    }
    13201029
    1321     std::string CommandExecutor::dump(const ExecutorStatic* executor)
     1030    std::string CommandExecutor::dump(const ConsoleCommand* command)
    13221031    {
    13231032        std::string output = "";
    1324         for (unsigned int i = 0; i < executor->getParamCount(); i++)
     1033        for (unsigned int i = 0; i < command->getParamCount(); i++)
    13251034        {
    13261035            if (i != 0)
    13271036                output += " ";
    13281037
    1329             if (executor->defaultValueSet(i))
     1038            if (command->defaultValueSet(i))
    13301039                output += "[";
    13311040            else
    13321041                output += "{";
    13331042
    1334             output += executor->getTypenameParam(i);
    1335 
    1336             if (executor->defaultValueSet(i))
    1337                 output += "=" + executor->getDefaultValue(i).toString() + "]";
     1043            output += command->getTypenameParam(i);
     1044
     1045            if (command->defaultValueSet(i))
     1046                output += "=" + command->getDefaultValue(i).toString() + "]";
    13381047            else
    13391048                output += "}";
  • 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}
  • code/branches/console/src/core/ConfigFileManager.cc

    r1056 r1341  
    3838namespace orxonox
    3939{
    40     ConsoleCommandShortcutExtern(reloadConfig, AccessLevel::None);
    41     ConsoleCommandShortcutExtern(cleanConfig, AccessLevel::None);
    42     ConsoleCommandShortcutExtern(loadSettings, AccessLevel::None);
    43     ConsoleCommandShortcutExtern(loadKeybindings, AccessLevel::None);
     40    SetConsoleCommandShortcutExtern(reloadConfig);
     41    SetConsoleCommandShortcutExtern(cleanConfig);
     42    SetConsoleCommandShortcutExtern(loadSettings);
     43    SetConsoleCommandShortcutExtern(loadKeybindings);
    4444
    4545    void reloadConfig()
  • code/branches/console/src/core/ConsoleCommand.h

    r1062 r1341  
    3838
    3939
     40#define SetConsoleCommand(classname, function,  bCreateShortcut) \
     41    SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut)
    4042
    41 #define ConsoleCommand(classname, function, accesslevel, bCreateShortcut) \
    42     ConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel), bCreateShortcut)
    43 
    44 #define ConsoleCommandGeneric(fakevariable, classname, executor, bCreateShortcut) \
    45     Executor& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ExecutorStatic*)executor, bCreateShortcut)
     43#define SetConsoleCommandGeneric(fakevariable, classname, executor, bCreateShortcut) \
     44    Executor& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ConsoleCommand*)executor, bCreateShortcut)
    4645
    4746
    48 #define ConsoleCommandShortcut(classname, function, accesslevel) \
    49     ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel))
     47#define SetConsoleCommandShortcut(classname, function) \
     48    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function))
    5049
    51 #define ConsoleCommandShortcutExtern(function, accesslevel) \
    52     ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&function), #function, accesslevel))
     50#define SetConsoleCommandShortcutExtern(function) \
     51    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function))
    5352
    54 #define ConsoleCommandShortcutGeneric(fakevariable, executor) \
    55     Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)
     53#define SetConsoleCommandShortcutGeneric(fakevariable, executor) \
     54    Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ConsoleCommand*)executor)
    5655
    5756
     57namespace orxonox
     58{
     59    namespace AccessLevel
     60    {
     61        enum Level
     62        {
     63            None,
     64            User,
     65            Admin,
     66            Offline,
     67            Debug,
     68            Disabled
     69        };
     70    }
     71
     72    class _CoreExport ConsoleCommand : public ExecutorStatic
     73    {
     74        public:
     75            ConsoleCommand(FunctorStatic* functor, const std::string& name = "") : ExecutorStatic(functor, name), accessLevel_(AccessLevel::None) {}
     76
     77            inline ConsoleCommand& setDescription(const std::string& description)
     78                { this->ExecutorStatic::setDescription(description); return (*this); }
     79            inline ConsoleCommand& setDescriptionParam(int param, const std::string& description)
     80                { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); }
     81            inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description)
     82                { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); }
     83            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1)
     84                { this->ExecutorStatic::setDefaultValues(param1); return (*this); }
     85            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
     86                { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); }
     87            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
     88                { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); }
     89            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
     90                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); }
     91            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
     92                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
     93            inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param)
     94                { this->ExecutorStatic::setDefaultValue(index, param); return (*this); }
     95
     96            inline ConsoleCommand& setAccessLevel(AccessLevel::Level level)
     97                { this->accessLevel_ = level; return (*this); }
     98            inline AccessLevel::Level getAccessLevel() const
     99                { return this->accessLevel_; }
     100
     101        private:
     102            AccessLevel::Level accessLevel_;
     103    };
     104
     105    inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "")
     106    {
     107        return new ConsoleCommand(functor, name);
     108    }
     109}
     110
    58111#endif /* _ConsoleCommand_H__ */
  • code/branches/console/src/core/CorePrereqs.h

    r1313 r1341  
    6666namespace orxonox
    6767{
    68 #ifndef _XMLPort_Mode__
    69 #define _XMLPort_Mode__
    7068  namespace XMLPort
    7169  {
     
    7674    };
    7775  }
    78 #endif
    7976
    8077  typedef std::string LanguageEntryLabel;
     
    10198  class ConfigFileSection;
    10299  class ConfigValueContainer;
     100  class ConsoleCommand;
    103101  class CoreSettings;
    104102  class Error;
  • code/branches/console/src/core/Executor.cc

    r1062 r1341  
    3434namespace orxonox
    3535{
    36     Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level)
     36    Executor::Executor(Functor* functor, const std::string& name)
    3737    {
    3838        this->functor_ = functor;
    3939        this->name_ = name;
    40         this->accessLevel_ = level;
    4140
    4241        this->bAddedDescription_ = false;
  • code/branches/console/src/core/Executor.h

    r1247 r1341  
    135135    return true
    136136
    137 namespace AccessLevel
    138 {
    139     enum Level
    140     {
    141         None,
    142         User,
    143         Admin,
    144         Offline,
    145         Debug,
    146         Disabled
    147     };
    148 }
    149 
    150137namespace orxonox
    151138{
     
    153140    {
    154141        public:
    155             Executor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None);
     142            Executor(Functor* functor, const std::string& name = "");
    156143            virtual ~Executor();
    157144
     
    182169            const std::string& getDescriptionReturnvalue(int param) const;
    183170
     171            inline Functor* getFunctor() const
     172                { return this->functor_; }
    184173            inline unsigned int getParamCount() const
    185174                { return this->functor_->getParamCount(); }
     
    200189                { return this->name_; }
    201190
    202             inline void setAccessLevel(AccessLevel::Level level)
    203                 { this->accessLevel_ = level; }
    204             inline AccessLevel::Level getAccessLevel() const
    205                 { return this->accessLevel_; }
    206 
    207191            Executor& setDefaultValues(const MultiTypeMath& param1);
    208192            Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2);
     
    243227            bool bAddedDescriptionReturnvalue_;
    244228            bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS];
    245 
    246             AccessLevel::Level accessLevel_;
    247229    };
    248230
     
    250232    {
    251233        public:
    252             ExecutorStatic(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}
     234            ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {}
    253235            virtual ~ExecutorStatic() {}
    254236    };
     
    258240    {
    259241        public:
    260             ExecutorMember(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}
     242            ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {}
    261243            virtual ~ExecutorMember() {}
    262244
     
    304286    };
    305287
    306     inline Executor* createExecutor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None)
    307     {
    308         return new Executor(functor, name, level);
     288    inline Executor* createExecutor(Functor* functor, const std::string& name = "")
     289    {
     290        return new Executor(functor, name);
    309291    }
    310292
    311293    template <class T>
    312     inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None)
    313     {
    314         return new ExecutorMember<T>(functor, name, level);
     294    inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "")
     295    {
     296        return new ExecutorMember<T>(functor, name);
    315297    }
    316298
    317     inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None)
    318     {
    319         return new ExecutorStatic(functor, name, level);
     299    inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "")
     300    {
     301        return new ExecutorStatic(functor, name);
    320302    }
    321303}
  • code/branches/console/src/core/IRC.cc

    r1276 r1341  
    3939namespace orxonox
    4040{
    41     ConsoleCommand(IRC, say,  AccessLevel::User, true);
    42     ConsoleCommand(IRC, msg,  AccessLevel::User, false);
    43     ConsoleCommand(IRC, nick, AccessLevel::User, false);
     41    SetConsoleCommand(IRC, say,  true).setAccessLevel(AccessLevel::User);
     42    SetConsoleCommand(IRC, msg,  false).setAccessLevel(AccessLevel::User);
     43    SetConsoleCommand(IRC, nick, false).setAccessLevel(AccessLevel::User);
    4444
    4545    IRC* instance_irc = &IRC::getInstance();
  • code/branches/console/src/core/Identifier.cc

    r1062 r1341  
    3737
    3838#include "Factory.h"
    39 #include "Executor.h"
     39#include "ConsoleCommand.h"
    4040#include "CommandExecutor.h"
    4141
     
    270270        @return The executor of the command
    271271    */
    272     ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut)
     272    ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut)
    273273    {
    274274        this->bHasConsoleCommands_ = true;
    275         this->consoleCommands_[executor->getName()] = executor;
    276         this->consoleCommands_LC_[getLowercase(executor->getName())] = executor;
     275        this->consoleCommands_[command->getName()] = command;
     276        this->consoleCommands_LC_[getLowercase(command->getName())] = command;
    277277
    278278        if (bCreateShortcut)
    279             CommandExecutor::addConsoleCommandShortcut(executor);
    280 
    281         return (*executor);
     279            CommandExecutor::addConsoleCommandShortcut(command);
     280
     281        return (*command);
    282282    }
    283283
     
    287287        @return The executor of the requested console command
    288288    */
    289     ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const
    290     {
    291         std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name);
     289    ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const
     290    {
     291        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name);
    292292        if (it != this->consoleCommands_.end())
    293293            return (*it).second;
     
    301301        @return The executor of the requested console command
    302302    */
    303     ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const
    304     {
    305         std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name);
     303    ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const
     304    {
     305        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name);
    306306        if (it != this->consoleCommands_LC_.end())
    307307            return (*it).second;
  • code/branches/console/src/core/Identifier.h

    r1313 r1341  
    176176
    177177            /** @brief Returns the map that stores all console commands. @return The const_iterator */
    178             inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; }
     178            inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandMap() const { return this->consoleCommands_; }
    179179            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
    180             inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }
     180            inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }
    181181            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
    182             inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }
     182            inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }
    183183
    184184            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
    185             inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }
     185            inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }
    186186            /** @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 */
    187             inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }
     187            inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }
    188188            /** @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 */
    189             inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
     189            inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
    190190
    191191
     
    214214            virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
    215215
    216             ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut);
    217             ExecutorStatic* getConsoleCommand(const std::string& name) const;
    218             ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const;
     216            ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
     217            ConsoleCommand* getConsoleCommand(const std::string& name) const;
     218            ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
    219219
    220220        protected:
     
    271271
    272272            bool bHasConsoleCommands_;                                     //!< True if this class has at least one assigned console command
    273             std::map<std::string, ExecutorStatic*> consoleCommands_;       //!< All console commands of this class
    274             std::map<std::string, ExecutorStatic*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
     273            std::map<std::string, ConsoleCommand*> consoleCommands_;       //!< All console commands of this class
     274            std::map<std::string, ConsoleCommand*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
    275275    };
    276276
  • code/branches/console/src/core/InputManager.cc

    r1322 r1341  
    4343namespace orxonox
    4444{
    45   ConsoleCommand(InputManager, setInputMode, AccessLevel::Admin, true).setDefaultValue(0, IM_INGAME);
     45  SetConsoleCommand(InputManager, setInputMode, true).setDefaultValue(0, IM_INGAME);
    4646
    4747  /**
  • code/branches/console/src/core/OutputHandler.cc

    r1322 r1341  
    3838namespace orxonox
    3939{
    40     ConsoleCommandShortcutGeneric(log,     createExecutor(createFunctor(&OutputHandler::log),     "log",     AccessLevel::None));
    41     ConsoleCommandShortcutGeneric(error,   createExecutor(createFunctor(&OutputHandler::error),   "error",   AccessLevel::None));
    42     ConsoleCommandShortcutGeneric(warning, createExecutor(createFunctor(&OutputHandler::warning), "warning", AccessLevel::None));
    43     ConsoleCommandShortcutGeneric(info,    createExecutor(createFunctor(&OutputHandler::info),    "info",    AccessLevel::None));
    44     ConsoleCommandShortcutGeneric(debug,   createExecutor(createFunctor(&OutputHandler::debug),   "debug",   AccessLevel::None));
     40    SetConsoleCommandShortcutGeneric(log,     createExecutor(createFunctor(&OutputHandler::log),     "log"    ));
     41    SetConsoleCommandShortcutGeneric(error,   createExecutor(createFunctor(&OutputHandler::error),   "error"  ));
     42    SetConsoleCommandShortcutGeneric(warning, createExecutor(createFunctor(&OutputHandler::warning), "warning"));
     43    SetConsoleCommandShortcutGeneric(info,    createExecutor(createFunctor(&OutputHandler::info),    "info"   ));
     44    SetConsoleCommandShortcutGeneric(debug,   createExecutor(createFunctor(&OutputHandler::debug),   "debug"  ));
    4545
    4646    /**
  • code/branches/console/src/core/TclBind.cc

    r1276 r1341  
    3939namespace orxonox
    4040{
    41     ConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl", AccessLevel::None));
    42     ConsoleCommandShortcutGeneric(bgerror, createExecutor(createFunctor(&TclBind::bgerror), "bgerror", AccessLevel::None));
     41    SetConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl"));
     42    SetConsoleCommandShortcutGeneric(bgerror, createExecutor(createFunctor(&TclBind::bgerror), "bgerror"));
    4343
    4444    TclBind::TclBind()
  • code/branches/console/src/core/TclThreadManager.cc

    r1337 r1341  
    4848namespace orxonox
    4949{
    50     ConsoleCommandShortcutGeneric(tclexecute, createExecutor(createFunctor(&TclThreadManager::execute), "tclexecute", AccessLevel::None));
    51     ConsoleCommandShortcutGeneric(tclquery,   createExecutor(createFunctor(&TclThreadManager::query),   "tclquery",   AccessLevel::None));
    52     ConsoleCommand(TclThreadManager, create,    AccessLevel::None, false);
    53     ConsoleCommand(TclThreadManager, destroy,   AccessLevel::None, false);
    54     ConsoleCommand(TclThreadManager, execute,   AccessLevel::None, false);
    55     ConsoleCommand(TclThreadManager, query,     AccessLevel::None, false);
    56     ConsoleCommand(TclThreadManager, status,    AccessLevel::None, false);
    57     ConsoleCommand(TclThreadManager, dump,      AccessLevel::None, false);
    58     ConsoleCommand(TclThreadManager, flush,     AccessLevel::None, false);
     50    SetConsoleCommandShortcutGeneric(tclexecute, createExecutor(createFunctor(&TclThreadManager::execute), "tclexecute"));
     51    SetConsoleCommandShortcutGeneric(tclquery,   createExecutor(createFunctor(&TclThreadManager::query),   "tclquery"  ));
     52    SetConsoleCommand(TclThreadManager, create, false);
     53    SetConsoleCommand(TclThreadManager, destroy, false);
     54    SetConsoleCommand(TclThreadManager, execute, false);
     55    SetConsoleCommand(TclThreadManager, query,  false);
     56    SetConsoleCommand(TclThreadManager, status, false);
     57    SetConsoleCommand(TclThreadManager, dump,    false);
     58    SetConsoleCommand(TclThreadManager, flush,  false);
    5959
    6060    TclThreadManager* instance_tclthreadmanager = &TclThreadManager::getInstance();
  • code/branches/console/src/core/XMLPort.h

    r1062 r1341  
    7878namespace orxonox
    7979{
    80 
    81 #ifndef _XMLPort_Mode__
    82 #define _XMLPort_Mode__
    83     namespace XMLPort
    84     {
    85         enum Mode
    86         {
    87             LoadObject,
    88             SaveObject
    89         };
    90     }
    91 #endif
    92 
    9380    // ###############################
    9481    // ###  XMLPortParamContainer  ###
  • code/branches/console/src/orxonox/Orxonox.cc

    r1334 r1341  
    5454//#include "util/Sleep.h"
    5555#include "util/ArgReader.h"
    56 #include "util/ExprParser.h"
    5756
    5857// core
     
    6059#include "core/ConsoleCommand.h"
    6160#include "core/Debug.h"
    62 #include "core/Factory.h"
    6361#include "core/Loader.h"
    6462#include "core/Tickable.h"
    65 #include "core/InputBuffer.h"
    6663#include "core/InputManager.h"
    6764
     
    7471
    7572// objects and tools
    76 #include "tools/Timer.h"
    7773#include "hud/HUD.h"
    7874//#include "console/InGameConsole.h"
     
    8581namespace orxonox
    8682{
    87   ConsoleCommand(Orxonox, exit, AccessLevel::None, true);
    88   ConsoleCommand(Orxonox, slomo, AccessLevel::Offline, true).setDefaultValue(0, 1.0);
    89   ConsoleCommand(Orxonox, setTimeFactor, AccessLevel::Offline, false).setDefaultValue(0, 1.0);
    90 
    91   class Calculator
    92   {
    93   public:
    94     static float calculate(const std::string& calculation)
    95     {
    96       ExprParser expr(calculation);
    97       if (expr.getSuccess())
    98       {
    99         if (expr.getResult() == 42.0)
    100           std::cout << "Greetings from the restaurant at the end of the universe." << std::endl;
    101         // FIXME: insert modifier to display in full precision
    102         std::cout << "Result is: " << expr.getResult() << std::endl;
    103         if (expr.getRemains() != "")
    104           std::cout << "Warning: Expression could not be parsed to the end! Remains: '"
    105               << expr.getRemains() << "'" << std::endl;
    106         return expr.getResult();
    107       }
    108       else
    109       {
    110         std::cout << "Cannot calculate expression: Parse error" << std::endl;
    111         return 0;
    112       }
    113     }
    114   };
    115   ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None);
     83  SetConsoleCommand(Orxonox, exit, true);
     84  SetConsoleCommand(Orxonox, slomo, true).setDefaultValue(0, 1.0).setAccessLevel(AccessLevel::Offline);
     85  SetConsoleCommand(Orxonox, setTimeFactor, false).setDefaultValue(0, 1.0).setAccessLevel(AccessLevel::Offline);
    11686
    11787  /**
  • code/branches/console/src/orxonox/console/InGameConsole.cc

    r1338 r1341  
    4949namespace orxonox
    5050{
    51     ConsoleCommand(InGameConsole, openConsole, AccessLevel::None, true);
    52     ConsoleCommand(InGameConsole, closeConsole, AccessLevel::None, true);
     51    SetConsoleCommand(InGameConsole, openConsole, true);
     52    SetConsoleCommand(InGameConsole, closeConsole, true);
    5353
    5454    using namespace Ogre;
  • code/branches/console/src/orxonox/objects/Ambient.cc

    r1064 r1341  
    4747namespace orxonox
    4848{
    49     ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));
     49    SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline);
    5050
    5151    CreateFactory(Ambient);
  • code/branches/console/src/orxonox/objects/SpaceShip.cc

    r1064 r1341  
    5353namespace orxonox
    5454{
    55     ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);
    56     ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);
    57     ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);
    58     ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);
     55    SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug);
     56    SetConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);
     57    SetConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);
     58    SetConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);
    5959
    6060    CreateFactory(SpaceShip);
  • code/branches/console/src/orxonox/tools/Timer.cc

    r1063 r1341  
    2727 */
    2828
     29#include <set>
     30
    2931#include "OrxonoxStableHeaders.h"
    3032#include "Timer.h"
     
    3739namespace orxonox
    3840{
    39     ConsoleCommandShortcutExtern(delay, AccessLevel::None);
     41    SetConsoleCommandShortcutExtern(delay);
     42    SetConsoleCommandShortcutExtern(killdelays);
     43
     44    static std::set<StaticTimer*> delaytimerset;
    4045
    4146    /**
     
    4752    {
    4853        StaticTimer *delaytimer = new StaticTimer();
     54        delaytimerset.insert(delaytimer);
     55
    4956        ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand));
    5057        delayexecutor->setDefaultValues(delaytimer, command);
     
    6168        CommandExecutor::execute(command);
    6269        delete timer;
     70        delaytimerset.erase(timer);
     71    }
     72
     73    /**
     74        @brief Kills all delayed commands.
     75    */
     76    void killdelays()
     77    {
     78        for (std::set<StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it)
     79            delete (*it);
     80
     81        delaytimerset.clear();
    6382    }
    6483
  • code/branches/console/src/orxonox/tools/Timer.h

    r1056 r1341  
    6969    class StaticTimer;
    7070    void delay(float delay, const std::string& command);
     71    void killdelays();
    7172    void executeDelayedCommand(StaticTimer* timer, const std::string& command);
    7273
Note: See TracChangeset for help on using the changeset viewer.