Changeset 7229 for code/branches
- Timestamp:
- Aug 27, 2010, 2:53:06 PM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries/core/command
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
r7228 r7229 61 61 return TclBind::eval(command, error); 62 62 else 63 return CommandExecutor::evaluate(command).query(error); 63 { 64 CommandEvaluation evaluation; 65 if (!CommandExecutor::getInstance().getCached(command, evaluation)) 66 { 67 COUT(0) << "evaluate" << std::endl; 68 evaluation = CommandExecutor::evaluate(command); 69 CommandExecutor::getInstance().cache(command, evaluation); 70 } 71 else 72 { 73 COUT(0) << "cached" << std::endl; 74 } 75 76 return evaluation.query(error); 77 } 64 78 } 65 79 … … 97 111 return evaluation; 98 112 } 113 114 bool CommandExecutor::getCached(const std::string& command, CommandEvaluation& evaluation) 115 { 116 if (Shell::getCacheSize() == 0) 117 return false; 118 119 std::map<std::string, CacheEntry>::iterator it = this->cache_.find(command); 120 if (it != this->cache_.end()) 121 { 122 // update ordered list of cached commands (move it to the front) 123 this->cachelist_.erase(it->second.iterator_); 124 this->cachelist_.push_front(command); 125 it->second.iterator_ = this->cachelist_.begin(); 126 127 // assign the cached evaluation 128 evaluation = it->second.evaluation_; 129 return true; 130 } 131 return false; 132 } 133 134 void CommandExecutor::cache(const std::string& command, const CommandEvaluation& evaluation) 135 { 136 if (Shell::getCacheSize() == 0) 137 return; 138 139 // push command to the front of the ordered list 140 this->cachelist_.push_front(command); 141 142 // create a cache entry and store it in the cache 143 CacheEntry entry; 144 entry.evaluation_ = evaluation; 145 entry.iterator_ = this->cachelist_.begin(); 146 this->cache_[command] = entry; 147 148 // remove the last command in the ordered list from the cache if it exceeds the maximum size of the cache 149 if (this->cachelist_.size() > Shell::getCacheSize()) 150 { 151 this->cache_.erase(this->cachelist_.back()); 152 this->cachelist_.pop_back(); 153 } 154 } 99 155 } -
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
r7228 r7229 32 32 #include "core/CorePrereqs.h" 33 33 34 #include <map> 35 #include <list> 34 36 #include <string> 35 37 … … 65 67 66 68 static CommandExecutor& getInstance(); 69 70 bool getCached(const std::string& command, CommandEvaluation& evaluation); 71 void cache(const std::string& command, const CommandEvaluation& evaluation); 72 73 struct CacheEntry 74 { 75 CommandEvaluation evaluation_; 76 std::list<std::string>::iterator iterator_; 77 }; 78 79 std::map<std::string, CacheEntry> cache_; 80 std::list<std::string> cachelist_; 67 81 }; // tolua_export 68 82 } // tolua_export -
code/branches/consolecommands3/src/libraries/core/command/Shell.cc
r7228 r7229 46 46 _SetConsoleCommand("debug", OutputHandler::debug ); 47 47 48 unsigned int Shell::cacheSize_s; 49 48 50 Shell::Shell(const std::string& consoleName, bool bScrollable) 49 51 : OutputListener(consoleName) … … 99 101 .callback(this, &Shell::commandHistoryOffsetChanged); 100 102 setConfigValueGeneric(this, &commandHistory_, ConfigFileType::CommandHistory, "Shell", "commandHistory_", std::vector<std::string>()); 103 SetConfigValue(cacheSize_s, 32); 101 104 102 105 #ifdef ORXONOX_RELEASE -
code/branches/consolecommands3/src/libraries/core/command/Shell.h
r7203 r7229 113 113 void setPromptPrefix(const std::string& str); 114 114 115 static inline unsigned int getCacheSize() 116 { return Shell::cacheSize_s; } 117 115 118 private: 116 119 Shell(const Shell& other); … … 167 170 std::vector<std::string> commandHistory_; 168 171 int softDebugLevel_; 172 static unsigned int cacheSize_s; 169 173 }; 170 174 }
Note: See TracChangeset
for help on using the changeset viewer.