Changeset 11071 for code/trunk/src/libraries/core/command
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/command/ArgumentCompletionFunctions.cc
r10624 r11071 77 77 bool groupIsVisible(const std::map<std::string, ConsoleCommand*>& group, bool bOnlyShowHidden) 78 78 { 79 for ( std::map<std::string, ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command)80 if ( it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)79 for (const auto& mapEntry : group) 80 if (mapEntry.second->isActive() && mapEntry.second->hasAccess() && (!mapEntry.second->isHidden())^bOnlyShowHidden) 81 81 return true; 82 82 … … 99 99 100 100 // get all the groups that are visible (except the shortcut group "") 101 const std::map<std::string, std::map<std::string, ConsoleCommand*> 102 for ( std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)103 if (groupIsVisible( it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find(fragmentLC) == 0))104 groupList. push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first)));101 const std::map<std::string, std::map<std::string, ConsoleCommand*>>& commands = ConsoleCommandManager::getInstance().getCommands(); 102 for (const auto& mapEntry : commands) 103 if (groupIsVisible(mapEntry.second, bOnlyShowHidden) && mapEntry.first != "" && (fragmentLC == "" || getLowercase(mapEntry.first).find(fragmentLC) == 0)) 104 groupList.emplace_back(mapEntry.first, getLowercase(mapEntry.first)); 105 105 106 106 // now add all shortcuts (in group "") 107 std::map<std::string, std::map<std::string, ConsoleCommand*> 107 std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = commands.find(""); 108 108 if (it_group != commands.end()) 109 109 { 110 110 // add a line-break if the list isn't empty 111 111 if (!groupList.empty()) 112 groupList. push_back(ArgumentCompletionListElement("", "", "\n"));112 groupList.emplace_back("", "", "\n"); 113 113 114 114 // add the shortcuts 115 for ( std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)116 if ( it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden && (fragmentLC == "" || getLowercase(it_command->first).find(fragmentLC) == 0))117 groupList. push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));115 for (const auto& mapEntry : it_group->second) 116 if (mapEntry.second->isActive() && mapEntry.second->hasAccess() && (!mapEntry.second->isHidden())^bOnlyShowHidden && (fragmentLC == "" || getLowercase(mapEntry.first).find(fragmentLC) == 0)) 117 groupList.emplace_back(mapEntry.first, getLowercase(mapEntry.first)); 118 118 } 119 119 … … 138 138 139 139 // find the iterator of the given group 140 std::map<std::string, std::map<std::string, ConsoleCommand*> 140 std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = ConsoleCommandManager::getInstance().getCommands().begin(); 141 141 for ( ; it_group != ConsoleCommandManager::getInstance().getCommands().end(); ++it_group) 142 142 if (getLowercase(it_group->first) == groupLC) … … 146 146 if (it_group != ConsoleCommandManager::getInstance().getCommands().end()) 147 147 { 148 for ( std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)149 if ( it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)150 commandList. push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));148 for (const auto& mapEntry : it_group->second) 149 if (mapEntry.second->isActive() && mapEntry.second->hasAccess() && (!mapEntry.second->isHidden())^bOnlyShowHidden) 150 commandList.emplace_back(mapEntry.first, getLowercase(mapEntry.first)); 151 151 } 152 152 … … 188 188 { 189 189 ArgumentCompletionList list; 190 list. push_back(ArgumentCompletionListElement("", "", hint));190 list.emplace_back("", "", hint); 191 191 return list; 192 192 } … … 212 212 if (tokens.size() == 1) 213 213 { 214 std::map<std::string, std::map<std::string, ConsoleCommand*> 214 std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = ConsoleCommandManager::getInstance().getCommands().find(tokens[0]); 215 215 if (it_group != ConsoleCommandManager::getInstance().getCommands().end()) 216 216 return detail::_subcommands(fragment, tokens[0], true); … … 261 261 { 262 262 if (boost::filesystem::is_directory(*file)) 263 dirlist. push_back(ArgumentCompletionListElement(file->BF_DICTIONARY_ENTRY_NAME() + '/', getLowercase(file->BF_DICTIONARY_ENTRY_NAME()) + '/', file->BF_LEAF() + '/'));263 dirlist.emplace_back(file->BF_DICTIONARY_ENTRY_NAME() + '/', getLowercase(file->BF_DICTIONARY_ENTRY_NAME()) + '/', file->BF_LEAF() + '/'); 264 264 else 265 filelist. push_back(ArgumentCompletionListElement(file->BF_DICTIONARY_ENTRY_NAME(), getLowercase(file->BF_DICTIONARY_ENTRY_NAME()), file->BF_LEAF()));265 filelist.emplace_back(file->BF_DICTIONARY_ENTRY_NAME(), getLowercase(file->BF_DICTIONARY_ENTRY_NAME()), file->BF_LEAF()); 266 266 ++file; 267 267 } … … 281 281 282 282 const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames(); 283 for ( std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)284 sectionList. push_back(ArgumentCompletionListElement(*it, getLowercase(*it)));283 for (const std::string& name : names) 284 sectionList.emplace_back(name, getLowercase(name)); 285 285 286 286 return sectionList; … … 298 298 SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC); 299 299 for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it) 300 entryList. push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first));300 entryList.emplace_back(it->second.second->getName(), it->second.first); 301 301 302 302 return entryList; … … 319 319 { 320 320 const std::string& valuestring = it->second.second->toString(); 321 oldValue. push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));321 oldValue.emplace_back(valuestring, getLowercase(valuestring), "Old value: " + valuestring); 322 322 } 323 323 } … … 334 334 ArgumentCompletionList threads; 335 335 336 for ( std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it)337 threads. push_back(ArgumentCompletionListElement(multi_cast<std::string>(*it)));336 for (unsigned int threadnumber : threadnumbers) 337 threads.emplace_back(multi_cast<std::string>(threadnumber)); 338 338 339 339 return threads; -
code/trunk/src/libraries/core/command/ArgumentCompletionFunctions.h
r11052 r11071 86 86 { 87 87 for (int month = 1; month <= 12; ++month) 88 list. push_back(ArgumentCompletionListElement(multi_cast<std::string>(month)));88 list.emplace_back(multi_cast<std::string>(month)); 89 89 } 90 90 else 91 91 { 92 list. push_back(ArgumentCompletionListElement("January", "january"));93 list. push_back(ArgumentCompletionListElement("February", "february"));94 list. push_back(ArgumentCompletionListElement("March", "march"));95 list. push_back(ArgumentCompletionListElement("April", "april"));96 list. push_back(ArgumentCompletionListElement("May", "may"));97 list. push_back(ArgumentCompletionListElement("June", "june"));98 list. push_back(ArgumentCompletionListElement("July", "july"));99 list. push_back(ArgumentCompletionListElement("August", "august"));100 list. push_back(ArgumentCompletionListElement("September", "september"));101 list. push_back(ArgumentCompletionListElement("October", "october"));102 list. push_back(ArgumentCompletionListElement("November", "november"));103 list. push_back(ArgumentCompletionListElement("December", "december"));92 list.emplace_back("January", "january"); 93 list.emplace_back("February", "february"); 94 list.emplace_back("March", "march"); 95 list.emplace_back("April", "april"); 96 list.emplace_back("May", "may"); 97 list.emplace_back("June", "june"); 98 list.emplace_back("July", "july"); 99 list.emplace_back("August", "august"); 100 list.emplace_back("September", "september"); 101 list.emplace_back("October", "october"); 102 list.emplace_back("November", "november"); 103 list.emplace_back("December", "december"); 104 104 } 105 105 -
code/trunk/src/libraries/core/command/CommandEvaluation.cc
r10624 r11071 54 54 void CommandEvaluation::initialize(const std::string& command) 55 55 { 56 this->execCommand_ = 0;57 this->hintCommand_ = 0;56 this->execCommand_ = nullptr; 57 this->hintCommand_ = nullptr; 58 58 this->string_ = command; 59 59 this->execArgumentsOffset_ = 0; … … 119 119 /** 120 120 @brief Executes the command which was evaluated by this object and returns its return-value. 121 @param error A pointer to an integer (or NULL) which will be used to write error codes to (see @ref CommandExecutorErrorCodes "CommandExecutor error codes")121 @param error A pointer to an integer (or nullptr) which will be used to write error codes to (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 122 122 @return Returns the result of the command (or MultiType::Null if there is no return value) 123 123 */ … … 306 306 // the user typed 1-2 arguments, check what he tried to type and print a suitable error 307 307 std::string groupLC = getLowercase(this->getToken(0)); 308 for ( std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group)309 if ( it_group->first == groupLC)308 for (const auto& mapEntry : ConsoleCommandManager::getInstance().getCommandsLC()) 309 if (mapEntry.first == groupLC) 310 310 return std::string("Error: There is no command in group \"") + this->getToken(0) + "\" starting with \"" + this->getToken(1) + "\"."; 311 311 … … 328 328 329 329 // iterate through all groups and their commands and calculate the distance to the current command. keep the best. 330 for ( std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group)331 { 332 if ( it_group->first != "")333 { 334 for ( std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name)335 { 336 std::string command = it_group->first + " " + it_name->first;330 for (const auto& mapEntryGroup : ConsoleCommandManager::getInstance().getCommandsLC()) 331 { 332 if (mapEntryGroup.first != "") 333 { 334 for (const auto& mapEntryName : mapEntryGroup.second) 335 { 336 std::string command = mapEntryGroup.first + " " + mapEntryName.first; 337 337 unsigned int distance = getLevenshteinDistance(command, token0_LC + " " + token1_LC); 338 338 if (distance < nearestDistance) … … 346 346 347 347 // now also iterate through all shortcuts and keep the best if it's better than the one found above. 348 std::map<std::string, std::map<std::string, ConsoleCommand*> 348 std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().find(""); 349 349 if (it_group != ConsoleCommandManager::getInstance().getCommandsLC().end()) 350 350 { 351 for ( std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name)352 { 353 std::string command = it_name->first;351 for (const auto& mapEntry : it_group->second) 352 { 353 std::string command = mapEntry.first; 354 354 unsigned int distance = getLevenshteinDistance(command, token0_LC); 355 355 if (distance < nearestDistance) … … 429 429 { 430 430 size_t count = 0; 431 for ( ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)432 if ( it->getComparable() != "")431 for (const ArgumentCompletionListElement& element : list) 432 if (element.getComparable() != "") 433 433 ++count; 434 434 return count; … … 495 495 { 496 496 // only one (non-empty) value in the list - search it and return it 497 for ( ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)498 { 499 if ( it->getComparable() != "")497 for (const ArgumentCompletionListElement& element : list) 498 { 499 if (element.getComparable() != "") 500 500 { 501 501 // arguments that have a separate string to be displayed need a little more care - just return them without modification. add a space character to the others. 502 if ( it->hasDisplay())503 return ( it->getString());502 if (element.hasDisplay()) 503 return (element.getString()); 504 504 else 505 return ( it->getString() + ' ');505 return (element.getString() + ' '); 506 506 } 507 507 } … … 517 517 char tempComparable = '\0'; 518 518 char temp = '\0'; 519 for ( ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)520 { 521 const std::string& argumentComparable = it->getComparable();522 const std::string& argument = it->getString();519 for (const ArgumentCompletionListElement& element : list) 520 { 521 const std::string& argumentComparable = element.getComparable(); 522 const std::string& argument = element.getString(); 523 523 524 524 // ignore empty arguments … … 560 560 { 561 561 std::string output; 562 for ( ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)563 { 564 output += it->getDisplay();562 for (const ArgumentCompletionListElement& element : list) 563 { 564 output += element.getDisplay(); 565 565 566 566 // add a space character between two elements for all non-empty arguments 567 if ( it->getComparable() != "")567 if (element.getComparable() != "") 568 568 output += ' '; 569 569 } -
code/trunk/src/libraries/core/command/CommandEvaluation.h
r8079 r11071 86 86 87 87 int execute(); 88 MultiType query(int* error = 0);88 MultiType query(int* error = nullptr); 89 89 90 90 std::string complete(); … … 97 97 /// Returns true if the command evaluation contains a valid command that can be executed. 98 98 inline bool isValid() const 99 { return (this->execCommand_ != 0); }99 { return (this->execCommand_ != nullptr); } 100 100 101 101 /// Returns the console command that was evaluated by this object. … … 137 137 static std::string getCommonBegin(const ArgumentCompletionList& list); 138 138 139 const ConsoleCommand* execCommand_; ///< The command that will be executed (can be NULLif the command is not valid)139 const ConsoleCommand* execCommand_; ///< The command that will be executed (can be nullptr if the command is not valid) 140 140 const ConsoleCommand* hintCommand_; ///< The command that is used to display hints and argument lists (can be different to execCommand_ in some cases) 141 141 SubString tokens_; ///< The single words of the command string, split into tokens -
code/trunk/src/libraries/core/command/CommandExecutor.cc
r10624 r11071 81 81 @brief Executes a command and returns its return-value. 82 82 @param command A string containing the command 83 @param error A pointer to a value (or NULL) where the error-code should be written to (see @ref CommandExecutorErrorCodes "error codes")83 @param error A pointer to a value (or nullptr) where the error-code should be written to (see @ref CommandExecutorErrorCodes "error codes") 84 84 @param useTcl If true, the command is passed to tcl (see TclBind) 85 85 @return Returns the return-value of the command (if any - MultiType::Null otherwise) … … 127 127 @brief Executes a command and returns its return-value as string. 128 128 @param command A string containing the command 129 @param error A pointer to a value (or NULL) where the error-code should be written to (see @ref CommandExecutorErrorCodes "error codes")129 @param error A pointer to a value (or nullptr) where the error-code should be written to (see @ref CommandExecutorErrorCodes "error codes") 130 130 @param useTcl If true, the command is passed to tcl (see TclBind) 131 131 @return Returns the return-value of the command converted to a string (or "" if there's no return value) … … 275 275 { 276 276 // it is valid - copy the executor of this command 277 ExecutorPtr executor = new Executor(*evaluation.getConsoleCommand()->getExecutor().get());277 ExecutorPtr executor = std::make_shared<Executor>(*evaluation.getConsoleCommand()->getExecutor().get()); 278 278 279 279 // evaluate the arguments and if this returns no error, store them as default values -
code/trunk/src/libraries/core/command/CommandExecutor.h
r8858 r11071 113 113 static int execute(const std::string& command, bool useTcl = true, bool printErrors = true); // tolua_export 114 114 115 static MultiType queryMT(const std::string& command, int* error = 0, bool useTcl = true);116 static std::string query(const std::string& command, int* error = 0, bool useTcl = true); // tolua_export115 static MultiType queryMT(const std::string& command, int* error = nullptr, bool useTcl = true); 116 static std::string query(const std::string& command, int* error = NULL, bool useTcl = true); // tolua_export 117 117 118 118 static CommandEvaluation evaluate(const std::string& command); 119 119 120 static const int Success = 0; ///< Error code for "success" (or no error)121 static const int Inexistent = 1; ///< Error code if the command doesn't exist122 static const int Incomplete = 2; ///< Error code if the command needs more arguments123 static const int Deactivated = 3; ///< Error code if the command is not active124 static const int Denied = 4; ///< Error code if the command needs a different access level125 static const int Error = 5; ///< Error code if the command returned an error120 static constexpr int Success = 0; ///< Error code for "success" (or no error) 121 static constexpr int Inexistent = 1; ///< Error code if the command doesn't exist 122 static constexpr int Incomplete = 2; ///< Error code if the command needs more arguments 123 static constexpr int Deactivated = 3; ///< Error code if the command is not active 124 static constexpr int Denied = 4; ///< Error code if the command needs a different access level 125 static constexpr int Error = 5; ///< Error code if the command returned an error 126 126 127 127 static std::string getErrorDescription(int error); … … 132 132 133 133 private: 134 CommandExecutor() {} ///< Empty constructor 135 CommandExecutor(const CommandExecutor& other); ///< Not implemented copy-constructor 136 ~CommandExecutor() {} ///< Empty destructor 134 CommandExecutor() = default; ///< Empty constructor 135 ~CommandExecutor() = default; ///< Empty destructor 136 137 // non-copyable: 138 CommandExecutor(const CommandExecutor&) = delete; 139 CommandExecutor& operator=(const CommandExecutor&) = delete; 137 140 138 141 static CommandExecutor& getInstance(); -
code/trunk/src/libraries/core/command/ConsoleCommand.cc
r10624 r11071 50 50 */ 51 51 ConsoleCommand::ConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized) 52 {53 this->init("", name, executor, bInitialized);52 : ConsoleCommand("", name, executor, bInitialized) 53 { 54 54 } 55 55 … … 75 75 this->baseFunctor_ = executor->getFunctor(); 76 76 77 for ( size_t i = 0; i < MAX_FUNCTOR_ARGUMENTS; ++i)78 this->argumentCompleter_[i] = 0;77 for (ArgumentCompleter*& completer : this->argumentCompleter_) 78 completer = nullptr; 79 79 80 80 this->keybindMode_ = KeybindMode::OnPress; … … 84 84 this->executor_ = executor; 85 85 86 this->names_. push_back(CommandName(group, name));86 this->names_.emplace_back(group, name); 87 87 } 88 88 … … 99 99 ConsoleCommand& ConsoleCommand::addShortcut() 100 100 { 101 this->names_. push_back(CommandName("", this->baseName_));101 this->names_.emplace_back("", this->baseName_); 102 102 return *this; 103 103 } … … 108 108 ConsoleCommand& ConsoleCommand::addShortcut(const std::string& name) 109 109 { 110 this->names_. push_back(CommandName("", name));110 this->names_.emplace_back("", name); 111 111 return *this; 112 112 } … … 117 117 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group) 118 118 { 119 this->names_. push_back(CommandName(group, this->baseName_));119 this->names_.emplace_back(group, this->baseName_); 120 120 return *this; 121 121 } … … 126 126 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string& name) 127 127 { 128 this->names_. push_back(CommandName(group, name));128 this->names_.emplace_back(group, name); 129 129 return *this; 130 130 } … … 320 320 { 321 321 if (this->executor_) 322 this->pushFunction( new Executor(*this->executor_.get()));322 this->pushFunction(std::make_shared<Executor>(*this->executor_.get())); 323 323 else 324 324 orxout(internal_error, context::commands) << "Couldn't push copy of executor in console command \"" << this->baseName_ << "\", no executor set." << endl; … … 348 348 349 349 /** 350 @brief Sets the functor to NULL(which also deactivates the command).350 @brief Sets the functor to nullptr (which also deactivates the command). 351 351 */ 352 352 void ConsoleCommand::resetFunction() 353 353 { 354 354 if (this->executor_) 355 this->executor_->setFunctor( 0);355 this->executor_->setFunctor(nullptr); 356 356 this->objectStack_.clear(); 357 357 } … … 405 405 void ConsoleCommand::popObject() 406 406 { 407 void* newobject = 0;407 void* newobject = nullptr; 408 408 if (!this->objectStack_.empty()) 409 409 { … … 422 422 return this->executor_->getFunctor()->getRawObjectPointer(); 423 423 else 424 return 0;424 return nullptr; 425 425 } 426 426 … … 528 528 return this->argumentCompleter_[index]; 529 529 else 530 return 0;530 return nullptr; 531 531 } 532 532 -
code/trunk/src/libraries/core/command/ConsoleCommand.h
r10624 r11071 60 60 } 61 61 62 namespace AccessLevel 62 /** 63 @brief Possible access levels: A command can only be executed if the program is in the state which is requested by the access level. 64 */ 65 enum class AccessLevel 63 66 { 64 /** 65 @brief Possible access levels: A command can only be executed if the program is in the state which is requested by the access level. 66 */ 67 enum Enum 68 { 69 All, 70 Standalone, 71 Master, 72 Server, 73 Client, 74 Online, 75 Offline, 76 None 77 }; 78 } 67 All, 68 Standalone, 69 Master, 70 Server, 71 Client, 72 Online, 73 Offline, 74 None 75 }; 79 76 80 77 /** … … 195 192 { if (this->command_) { this->command_->popFunction(); } return *this; } 196 193 197 /// Sets the current function-pointer to NULL, which also deactivates the command.194 /// Sets the current function-pointer to nullptr, which also deactivates the command. 198 195 inline ConsoleCommandManipulator& resetFunction() 199 196 { if (this->command_) { this->command_->resetFunction(); } return *this; } … … 205 202 inline ConsoleCommandManipulator& pushObject(void* object) 206 203 { if (this->command_) { this->command_->pushObject(object); } return *this; } 207 /// Removes the current object from the object-stack and restores the old object (or NULLif there's no object left on the stack).204 /// Removes the current object from the object-stack and restores the old object (or nullptr if there's no object left on the stack). 208 205 inline ConsoleCommandManipulator& popObject() 209 206 { if (this->command_) { this->command_->popObject(); } return *this; } … … 249 246 250 247 /// Changes the access level of the command. 251 inline ConsoleCommandManipulator& accessLevel(AccessLevel ::Enumlevel)248 inline ConsoleCommandManipulator& accessLevel(AccessLevel level) 252 249 { if (this->command_) { this->command_->accessLevel(level); } return *this; } 253 250 … … 332 329 333 330 /// Changes the access level of the command. 334 inline ConsoleCommand& accessLevel(AccessLevel ::Enumlevel)331 inline ConsoleCommand& accessLevel(AccessLevel level) 335 332 { this->accessLevel_ = level; return *this; } 336 333 /// Returns the access level of the command. 337 inline AccessLevel ::EnumgetAccessLevel() const334 inline AccessLevel getAccessLevel() const 338 335 { return this->accessLevel_; } 339 336 … … 394 391 bool bActive_; ///< True if the command should be active (it can still be inactive, for example if the function is missing) 395 392 bool bHidden_; ///< True if the command is hidden (it is still executable, but not visible in the list of available commands) 396 AccessLevel ::Enum accessLevel_;///< The access level (the state of the game in which you can access the command)393 AccessLevel accessLevel_; ///< The access level (the state of the game in which you can access the command) 397 394 std::string baseName_; ///< The name that was first assigned to the command 398 395 std::vector<CommandName> names_; ///< All names and aliases of this command -
code/trunk/src/libraries/core/command/ConsoleCommandIncludes.h
r10624 r11071 316 316 ~StaticallyInitializedConsoleCommand() { delete command_; } 317 317 318 virtual void load() ;319 virtual void unload() ;318 virtual void load() override; 319 virtual void unload() override; 320 320 321 321 inline ConsoleCommand& getCommand() … … 331 331 @brief Returns a manipulator for a command with the given name. 332 332 333 @note If the command doesn't exist, the manipulator contains a NULL pointer to the command,333 @note If the command doesn't exist, the manipulator contains a nullptr to the command, 334 334 but it can still be used without checks, because all functions of ConsoleCommandManipulator 335 335 check internally if the command exists. … … 340 340 @brief Returns a manipulator for a command with the given group and name. 341 341 342 @note If the command doesn't exist, the manipulator contains a NULL pointer to the command,342 @note If the command doesn't exist, the manipulator contains a nullptr to the command, 343 343 but it can still be used without checks, because all functions of ConsoleCommandManipulator 344 344 check internally if the command exists. -
code/trunk/src/libraries/core/command/ConsoleCommandManager.cc
r11052 r11071 39 39 namespace orxonox 40 40 { 41 ConsoleCommandManager* ConsoleCommandManager::singletonPtr_s = 0;41 ConsoleCommandManager* ConsoleCommandManager::singletonPtr_s = nullptr; 42 42 43 43 /** … … 50 50 { 51 51 // find the group 52 std::map<std::string, std::map<std::string, ConsoleCommand*> 52 std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = this->commandMap_.find(group); 53 53 if (it_group != this->commandMap_.end()) 54 54 { … … 68 68 orxout(internal_error, context::commands) << "Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << endl; 69 69 } 70 return 0;70 return nullptr; 71 71 } 72 72 … … 83 83 84 84 // find the group 85 std::map<std::string, std::map<std::string, ConsoleCommand*> 85 std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = this->commandMapLC_.find(groupLC); 86 86 if (it_group != this->commandMapLC_.end()) 87 87 { … … 101 101 orxout(internal_error, context::commands) << "Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << endl; 102 102 } 103 return 0;103 return nullptr; 104 104 } 105 105 … … 125 125 126 126 // check if a command with this name already exists 127 if (this->getCommand(group, name) != 0)127 if (this->getCommand(group, name) != nullptr) 128 128 { 129 129 if (group == "") … … 146 146 { 147 147 // iterate through all groups 148 for (std::map<std::string, std::map<std::string, ConsoleCommand*> 148 for (std::map<std::string, std::map<std::string, ConsoleCommand*>>::iterator it_group = this->commandMap_.begin(); it_group != this->commandMap_.end(); ) 149 149 { 150 150 // iterate through all commands of each group … … 168 168 169 169 // iterate through all groups 170 for (std::map<std::string, std::map<std::string, ConsoleCommand*> 170 for (std::map<std::string, std::map<std::string, ConsoleCommand*>>::iterator it_group = this->commandMapLC_.begin(); it_group != this->commandMapLC_.end(); ) 171 171 { 172 172 // iterate through all commands of each group -
code/trunk/src/libraries/core/command/ConsoleCommandManager.h
r10624 r11071 39 39 #include "util/Singleton.h" 40 40 41 #include <map> 42 41 43 namespace orxonox 42 44 { … … 54 56 55 57 /// Returns the map with all groups and commands. 56 inline const std::map<std::string, std::map<std::string, ConsoleCommand*> 58 inline const std::map<std::string, std::map<std::string, ConsoleCommand*>>& getCommands() 57 59 { return this->commandMap_; } 58 60 /// Returns the map with all groups and commands in lowercase. 59 inline const std::map<std::string, std::map<std::string, ConsoleCommand*> 61 inline const std::map<std::string, std::map<std::string, ConsoleCommand*>>& getCommandsLC() 60 62 { return this->commandMapLC_; } 61 63 … … 71 73 72 74 private: 73 std::map<std::string, std::map<std::string, ConsoleCommand*> 74 std::map<std::string, std::map<std::string, ConsoleCommand*> 75 std::map<std::string, std::map<std::string, ConsoleCommand*>> commandMap_; 76 std::map<std::string, std::map<std::string, ConsoleCommand*>> commandMapLC_; 75 77 76 78 static ConsoleCommandManager* singletonPtr_s; -
code/trunk/src/libraries/core/command/Executor.cc
r9550 r11071 67 67 68 68 /** 69 @brief Destructor70 */71 Executor::~Executor()72 {73 }74 75 /**76 69 @brief Calls the wrapped function with arguments that are passed in a string. 77 70 @param arguments The arguments that should be passed to the function, separated by @a delimiter 78 @param error A pointer to a variable (or NULL) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes")71 @param error A pointer to a variable (or nullptr) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 79 72 @param delimiter The delimiter that is used to separate the arguments in the string @a arguments 80 73 @param bPrintError If true, errors are printed to the console if the function couldn't be executed with the given arguments … … 89 82 @brief Calls the wrapped function with arguments that are passed as tokens in a SubString 90 83 @param arguments The arguments that should be passed to the function 91 @param error A pointer to a variable (or NULL) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes")84 @param error A pointer to a variable (or nullptr) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 92 85 @param delimiter The delimiter that was used to separate the arguments in the SubString @a arguments (used to join the surplus arguments) 93 86 @param bPrintError If true, errors are printed to the console if the function couldn't be executed with the given arguments … … 127 120 @param arguments The arguments that should be converted 128 121 @param arg An array of MultiType where the converted arguments will be stored 129 @param error A pointer to a variable (or NULL) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes")122 @param error A pointer to a variable (or nullptr) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 130 123 @param delimiter The delimiter that was used to separate the arguments in the SubString @a arguments (used to join the surplus arguments) 131 124 @return Returns the number of evaluated arguments -
code/trunk/src/libraries/core/command/Executor.h
r9550 r11071 42 42 orxonox::Executor is used to wrap an orxonox::Functor and to store default values for 43 43 its parameters. Usually one uses the function createExecutor() to create a new executor. 44 This function returns an orxonox::ExecutorPtr which is a typedef of @ref orxonox::SharedPtr45 "SharedPtr<Executor>",used to manage the pointer to the executor.44 This function returns an orxonox::ExecutorPtr which is a typedef of "std::shared_ptr<Executor>", 45 used to manage the pointer to the executor. 46 46 47 47 Executors are mostly used to execute callbacks. Because some callback functions need arguments, … … 74 74 @endcode 75 75 76 Because executors that were created with createExecutor() are managed by an orxonox::SharedPtr,77 they don't need to be deleted after usage.76 Executors don't need to be deleted after usage normally because they are managed by an 77 std::shared_ptr when they were created with createExecutor(). 78 78 */ 79 79 … … 100 100 Executor(const FunctorPtr& functor, const std::string& name = ""); 101 101 Executor(const Executor& other); 102 virtual ~Executor() ;102 virtual ~Executor() = default; 103 103 104 104 /// Calls the wrapped function with 0 arguments. If the function needs more arguments, the executor's default values are used. … … 121 121 { return (*this->functor_)(arg1, arg2, arg3, arg4, arg5); } 122 122 123 MultiType parse(const std::string& arguments, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const;124 MultiType parse(const SubString& arguments, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const;125 126 int evaluateArguments(const SubString& arguments, MultiType arg[MAX_FUNCTOR_ARGUMENTS], int* error = 0, const std::string& delimiter = " ") const;123 MultiType parse(const std::string& arguments, int* error = nullptr, const std::string& delimiter = " ", bool bPrintError = false) const; 124 MultiType parse(const SubString& arguments, int* error = nullptr, const std::string& delimiter = " ", bool bPrintError = false) const; 125 126 int evaluateArguments(const SubString& arguments, MultiType arg[MAX_FUNCTOR_ARGUMENTS], int* error = nullptr, const std::string& delimiter = " ") const; 127 127 128 128 /// Changes the functor. … … 147 147 { return this->functor_->hasReturnvalue(); } 148 148 /// Returns the type of the wrapped function (static or member). 149 inline Functor::Type ::EnumgetType() const149 inline Functor::Type getType() const 150 150 { return this->functor_->getType(); } 151 151 /// Returns the name of the type of a parameter with given index (the first parameter has index 0). … … 249 249 250 250 /// Overloads Executor::parse() with an additional object-pointer. 251 MultiType parse(T* object, const std::string& arguments, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const251 MultiType parse(T* object, const std::string& arguments, int* error = nullptr, const std::string& delimiter = " ", bool bPrintError = false) const 252 252 { 253 253 T* oldobject = this->functorMember_->getObject(); … … 267 267 inline ExecutorPtr createExecutor(const FunctorPtr& functor, const std::string& name = "") 268 268 { 269 return new Executor(functor, name);269 return std::make_shared<Executor>(functor, name); 270 270 } 271 271 … … 274 274 inline ExecutorMemberPtr<T> createExecutor(const FunctorMemberPtr<T>& functor, const std::string& name = "") 275 275 { 276 return new ExecutorMember<T>(functor, name);276 return std::make_shared<ExecutorMember<T>>(functor, name); 277 277 } 278 278 … … 280 280 inline ExecutorStaticPtr createExecutor(const FunctorStaticPtr& functor, const std::string& name = "") 281 281 { 282 return new ExecutorStatic(functor, name);282 return std::make_shared<ExecutorStatic>(functor, name); 283 283 } 284 284 } -
code/trunk/src/libraries/core/command/ExecutorPtr.h
r7401 r11071 32 32 @brief Typedefs and definitions of ExecutorPtr, ExecutorStaticPtr, and ExecutorMemberPtr 33 33 34 Instances of orxonox::Executor are usually managed by an orxonox::SharedPtr. This ensures34 Instances of orxonox::Executor are usually managed by an std::shared_ptr. This ensures 35 35 that Executors will be destroyed after usage. To make things easier, there's a typedef 36 that defines ExecutorPtr as SharedPtr<Executor>.36 that defines ExecutorPtr as std::shared_ptr<Executor>. 37 37 38 38 Because there's not only orxonox::Executor, but also orxonox::ExecutorStatic, and … … 49 49 50 50 #include "core/CorePrereqs.h" 51 #include "util/SharedPtr.h"51 #include <memory> 52 52 53 53 namespace orxonox 54 54 { 55 /// ExecutorPtr is just a typedef of SharedPtr 56 typedef SharedPtr<Executor> ExecutorPtr; 57 58 /// ExecutorStaticPtr is just a typedef of SharedChildPtr 59 typedef SharedChildPtr<ExecutorStatic, ExecutorPtr> ExecutorStaticPtr; 60 61 /// It's not possible to use a typedef for ExecutorMemberPtr<T>, so we have to create a child-class instead. It inherits all functions from SharedChildPtr, but needs to (re-)implement some constructors. 55 using ExecutorPtr = std::shared_ptr<Executor>; 56 using ExecutorStaticPtr = std::shared_ptr<ExecutorStatic>; 62 57 template <class T> 63 class ExecutorMemberPtr : public SharedChildPtr<ExecutorMember<T>, ExecutorPtr> 64 { 65 public: 66 inline ExecutorMemberPtr() : SharedChildPtr<ExecutorMember<T>, ExecutorPtr>() {} 67 inline ExecutorMemberPtr(ExecutorMember<T>* pointer) : SharedChildPtr<ExecutorMember<T>, ExecutorPtr>(pointer) {} 68 inline ExecutorMemberPtr(const SharedPtr<ExecutorMember<T> >& other) : SharedChildPtr<ExecutorMember<T>, ExecutorPtr>(other) {} 69 }; 58 using ExecutorMemberPtr = std::shared_ptr<ExecutorMember<T>>; 70 59 } 71 60 -
code/trunk/src/libraries/core/command/Functor.h
r9667 r11071 40 40 41 41 To create a Functor, the helper function createFunctor() is used. It returns an instance 42 of orxonox::FunctorPtr which is simply a typedef of @ref orxonox::SharedPtr "SharedPtr<Functor>".43 Thismeans you don't have to delete the Functor after using it, because it is managed44 by the SharedPtr.42 of orxonox::FunctorPtr which is simply a typedef of "std::shared_ptr<Functor>". This 43 means you don't have to delete the Functor after using it, because it is managed 44 by the std::shared_ptr. 45 45 46 46 Example: … … 176 176 { 177 177 public: 178 struct Type 179 { 180 /// Defines the type of a function (static or member) 181 enum Enum 182 { 183 Static, 184 Member 185 }; 178 /// Defines the type of a function (static or member) 179 enum class Type 180 { 181 Static, 182 Member 186 183 }; 187 184 188 185 public: 189 virtual ~Functor() {}186 virtual ~Functor() = default; 190 187 191 188 /// Calls the function-pointer with up to five arguments. In case of a member-function, the assigned object-pointer is used to call the function. @return Returns the return-value of the function (if any; MultiType::Null otherwise) … … 196 193 197 194 /// Returns the type of the function: static or member. 198 virtual Type ::EnumgetType() const = 0;195 virtual Type getType() const = 0; 199 196 /// Returns the number of parameters of the function. 200 197 virtual unsigned int getParamCount() const = 0; … … 215 212 virtual void* getRawObjectPointer() const = 0; 216 213 217 /// Enables or disables the safe mode which causes the functor to change the object pointer to NULLif the object is deleted (only member functors).214 /// Enables or disables the safe mode which causes the functor to change the object pointer to nullptr if the object is deleted (only member functors). 218 215 virtual void setSafeMode(bool bSafeMode) = 0; 219 216 … … 242 239 public: 243 240 /// Constructor: Stores the object-pointer. 244 FunctorMember(O* object = 0) : object_(object), bSafeMode_(false) {}241 FunctorMember(O* object = nullptr) : object_(object), bSafeMode_(false) {} 245 242 virtual ~FunctorMember() { if (this->bSafeMode_) { this->unregisterObject(this->object_); } } 246 243 247 /// Calls the function-pointer with up to five arguments and an object. In case of a static-function, the object can be NULL. @return Returns the return-value of the function (if any; MultiType::Null otherwise)244 /// Calls the function-pointer with up to five arguments and an object. In case of a static-function, the object can be nullptr. @return Returns the return-value of the function (if any; MultiType::Null otherwise) 248 245 virtual MultiType operator()(O* object, const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null) = 0; 249 246 250 247 // see Functor::operator()() 251 MultiType operator()(const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null)248 virtual MultiType operator()(const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null) override 252 249 { 253 250 // call the function if an object was assigned … … 262 259 263 260 // see Functor::getType() 264 inline Functor::Type::Enum getType() const261 virtual inline Functor::Type getType() const override 265 262 { return Functor::Type::Member; } 266 263 … … 280 277 281 278 // see Functor::setRawObjectPointer() 282 inline void setRawObjectPointer(void* object)279 virtual inline void setRawObjectPointer(void* object) override 283 280 { this->setObject((O*)object); } 284 281 // see Functor::getRawObjectPointer() 285 inline void* getRawObjectPointer() const282 virtual inline void* getRawObjectPointer() const override 286 283 { return this->object_; } 287 284 288 285 // see Functor::setSafeMode() 289 inline void setSafeMode(bool bSafeMode)286 virtual inline void setSafeMode(bool bSafeMode) override 290 287 { 291 288 if (bSafeMode == this->bSafeMode_) … … 301 298 302 299 protected: 303 /// Casts the object and registers as destruction listener. 304 inline void registerObject(O* object) 305 { Destroyable* base = dynamic_cast<Destroyable*>(object); if (base) { this->registerAsDestructionListener(base); } } 306 /// Casts the object and unregisters as destruction listener. 307 inline void unregisterObject(O* object) 308 { Destroyable* base = dynamic_cast<Destroyable*>(object); if (base) { this->unregisterAsDestructionListener(base); } } 309 310 /// Will be called by Destroyable::~Destroyable() if the stored object is deleted and the Functor is in safe mode. 311 inline void objectDeleted() 312 { this->object_ = 0; } 313 314 O* object_; ///< The stored object-pointer, used to execute a member-function (or NULL for static functions) 315 bool bSafeMode_; ///< If true, the functor is in safe mode and registers itself as listener at the object and changes the pointer to NULL if the object is deleted 300 /// Casts the object and registers as destruction listener if the object is a Destroyable. 301 inline void registerObject(Destroyable* object) 302 { this->registerAsDestructionListener(object); } 303 304 inline void registerObject(void* object) {} 305 306 /// Casts the object and unregisters as destruction listener if the object is a Destroyable. 307 inline void unregisterObject(Destroyable* object) 308 { this->unregisterAsDestructionListener(object); } 309 310 inline void unregisterObject(void* object) {} 311 312 /// Will be called by Destroyable::~Destroyable() if the stored object is a Destroyable and deleted and the Functor is in safe mode. 313 virtual inline void objectDeleted() override 314 { this->object_ = nullptr; } 315 316 O* object_; ///< The stored object-pointer, used to execute a member-function (or nullptr for static functions) 317 bool bSafeMode_; ///< If true, the functor is in safe mode and registers itself as listener at the object and changes the pointer to nullptr if the object is deleted 316 318 }; 317 319 … … 322 324 public: 323 325 /// Constructor: Stores the object-pointer. 324 FunctorMember(void* object = 0) {}325 326 /// Calls the function-pointer with up to five arguments and an object. In case of a static-function, the object can be NULL. @return Returns the return-value of the function (if any; MultiType::Null otherwise)326 FunctorMember(void* object = nullptr) {} 327 328 /// Calls the function-pointer with up to five arguments and an object. In case of a static-function, the object can be nullptr. @return Returns the return-value of the function (if any; MultiType::Null otherwise) 327 329 virtual MultiType operator()(void* object, const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null) = 0; 328 330 329 331 // see Functor::operator()() 330 MultiType operator()(const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null)331 { 332 return (*this)((void*) 0, param1, param2, param3, param4, param5);332 virtual MultiType operator()(const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null) override 333 { 334 return (*this)((void*)nullptr, param1, param2, param3, param4, param5); 333 335 } 334 336 335 337 // see Functor::getType() 336 inline Functor::Type::Enum getType() const338 virtual inline Functor::Type getType() const override 337 339 { return Functor::Type::Static; } 338 340 339 341 // see Functor::setRawObjectPointer() 340 inline void setRawObjectPointer(void*)342 virtual inline void setRawObjectPointer(void*) override 341 343 { orxout(internal_warning) << "Can't assign an object pointer to a static functor" << endl; } 342 344 // see Functor::getRawObjectPointer() 343 inline void* getRawObjectPointer() const344 { return 0; }345 virtual inline void* getRawObjectPointer() const override 346 { return nullptr; } 345 347 346 348 // see Functor::setSafeMode() 347 inline void setSafeMode(bool){}349 virtual inline void setSafeMode(bool) override {} 348 350 }; 349 351 … … 352 354 353 355 /** 354 @brief FunctorPointer is a child class of FunctorMember and ex pands it with a function-pointer.355 @param F The type of the function-pointer 356 @param O The type of the function's class (or void if it's a static function )356 @brief FunctorPointer is a child class of FunctorMember and extends it with a function-pointer (or a function-object). 357 @param F The type of the function-pointer (or the function-object) 358 @param O The type of the function's class (or void if it's a static function or a function-object) 357 359 358 360 The template FunctorPointer has an additional template parameter that defines the type 359 of the function-pointer . This can be handy if you want to get or set the function-pointer.360 You can then use a static_cast to cast a Functor to FunctorPointer if you know the type361 of the function-pointer.361 of the function-pointer (or the function-object). This can be handy if you want to get 362 or set the function-pointer (or the function-object). You can then use a static_cast 363 to cast a Functor to FunctorPointer if you know the type of the function. 362 364 363 365 However FunctorPointer is not aware of the types of the different parameters or the … … 369 371 public: 370 372 /// Constructor: Initializes the base class and stores the function-pointer. 371 FunctorPointer(F functionPointer, O* object = 0) : FunctorMember<O>(object), functionPointer_(functionPointer) {}373 FunctorPointer(F functionPointer, O* object = nullptr) : FunctorMember<O>(object), functionPointer_(functionPointer) {} 372 374 373 375 /// Changes the function-pointer. … … 378 380 { return this->functionPointer_; } 379 381 380 // see Functor::getFullIdentifier()381 const std::type_info& getFullIdentifier() const382 { return typeid(F); }383 384 382 protected: 385 383 F functionPointer_; ///< The stored function-pointer … … 388 386 namespace detail 389 387 { 390 // Helper class to get the type of the function pointer with the given class, parameters, return-value, and constness 391 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer { typedef R (O::*Type)(P1, P2, P3, P4, P5); }; 392 template <class R, class O, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer<R, O, false, P1, P2, P3, P4, P5> { typedef R (O::*Type)(P1, P2, P3, P4, P5); }; 393 template <class R, class O, class P1, class P2, class P3, class P4> struct FunctionPointer<R, O, false, P1, P2, P3, P4, void> { typedef R (O::*Type)(P1, P2, P3, P4); }; 394 template <class R, class O, class P1, class P2, class P3> struct FunctionPointer<R, O, false, P1, P2, P3, void, void> { typedef R (O::*Type)(P1, P2, P3); }; 395 template <class R, class O, class P1, class P2> struct FunctionPointer<R, O, false, P1, P2, void, void, void> { typedef R (O::*Type)(P1, P2); }; 396 template <class R, class O, class P1> struct FunctionPointer<R, O, false, P1, void, void, void, void> { typedef R (O::*Type)(P1); }; 397 template <class R, class O> struct FunctionPointer<R, O, false, void, void, void, void, void> { typedef R (O::*Type)(); }; 398 template <class R, class O, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer<R, O, true, P1, P2, P3, P4, P5> { typedef R (O::*Type)(P1, P2, P3, P4, P5) const; }; 399 template <class R, class O, class P1, class P2, class P3, class P4> struct FunctionPointer<R, O, true, P1, P2, P3, P4, void> { typedef R (O::*Type)(P1, P2, P3, P4) const; }; 400 template <class R, class O, class P1, class P2, class P3> struct FunctionPointer<R, O, true, P1, P2, P3, void, void> { typedef R (O::*Type)(P1, P2, P3) const; }; 401 template <class R, class O, class P1, class P2> struct FunctionPointer<R, O, true, P1, P2, void, void, void> { typedef R (O::*Type)(P1, P2) const; }; 402 template <class R, class O, class P1> struct FunctionPointer<R, O, true, P1, void, void, void, void> { typedef R (O::*Type)(P1) const; }; 403 template <class R, class O> struct FunctionPointer<R, O, true, void, void, void, void, void> { typedef R (O::*Type)() const; }; 404 template <class R, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer<R, void, false, P1, P2, P3, P4, P5> { typedef R (*Type)(P1, P2, P3, P4, P5); }; 405 template <class R, class P1, class P2, class P3, class P4> struct FunctionPointer<R, void, false, P1, P2, P3, P4, void> { typedef R (*Type)(P1, P2, P3, P4); }; 406 template <class R, class P1, class P2, class P3> struct FunctionPointer<R, void, false, P1, P2, P3, void, void> { typedef R (*Type)(P1, P2, P3); }; 407 template <class R, class P1, class P2> struct FunctionPointer<R, void, false, P1, P2, void, void, void> { typedef R (*Type)(P1, P2); }; 408 template <class R, class P1> struct FunctionPointer<R, void, false, P1, void, void, void, void> { typedef R (*Type)(P1); }; 409 template <class R> struct FunctionPointer<R, void, false, void, void, void, void, void> { typedef R (*Type)(); }; 410 411 // Helper class, used to call a function-pointer with a given object and parameters and to return its return-value (if available) 412 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1, param2, param3, param4, param5); } }; 413 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<R, O, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType&) { return (object->*functionPointer)(param1, param2, param3, param4); } }; 414 template <class R, class O, bool isconst, class P1, class P2, class P3> struct FunctorCaller<R, O, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType&, const MultiType&) { return (object->*functionPointer)(param1, param2, param3); } }; 415 template <class R, class O, bool isconst, class P1, class P2> struct FunctorCaller<R, O, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType&, const MultiType&, const MultiType&) { return (object->*functionPointer)(param1, param2); } }; 416 template <class R, class O, bool isconst, class P1> struct FunctorCaller<R, O, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, void, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { return (object->*functionPointer)(param1); } }; 417 template <class R, class O, bool isconst> struct FunctorCaller<R, O, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, void, void, void, void, void>::Type functionPointer, O* object, const MultiType&, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { return (object->*functionPointer)(); } }; 418 template <class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller<void, O, isconst, P1, P2, P3, P4, P5> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (object->*functionPointer)(param1, param2, param3, param4, param5); return MultiType::Null; } }; 419 template <class O, bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<void, O, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, P3, P4, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType&) { (object->*functionPointer)(param1, param2, param3, param4); return MultiType::Null; } }; 420 template <class O, bool isconst, class P1, class P2, class P3> struct FunctorCaller<void, O, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, P3, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType&, const MultiType&) { (object->*functionPointer)(param1, param2, param3); return MultiType::Null; } }; 421 template <class O, bool isconst, class P1, class P2> struct FunctorCaller<void, O, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, P2, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType&, const MultiType&, const MultiType&) { (object->*functionPointer)(param1, param2); return MultiType::Null; } }; 422 template <class O, bool isconst, class P1> struct FunctorCaller<void, O, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, P1, void, void, void, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { (object->*functionPointer)(param1); return MultiType::Null; } }; 423 template <class O, bool isconst> struct FunctorCaller<void, O, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, void, void, void, void, void>::Type functionPointer, O* object, const MultiType&, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { (object->*functionPointer)(); return MultiType::Null; } }; 424 template <class R, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller<R, void, isconst, P1, P2, P3, P4, P5> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, P3, P4, P5>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (*functionPointer)(param1, param2, param3, param4, param5); } }; 425 template <class R, bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<R, void, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, P3, P4, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType&) { return (*functionPointer)(param1, param2, param3, param4); } }; 426 template <class R, bool isconst, class P1, class P2, class P3> struct FunctorCaller<R, void, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, P3, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType&, const MultiType&) { return (*functionPointer)(param1, param2, param3); } }; 427 template <class R, bool isconst, class P1, class P2> struct FunctorCaller<R, void, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, P2, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType&, const MultiType&, const MultiType&) { return (*functionPointer)(param1, param2); } }; 428 template <class R, bool isconst, class P1> struct FunctorCaller<R, void, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, P1, void, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { return (*functionPointer)(param1); } }; 429 template <class R, bool isconst> struct FunctorCaller<R, void, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, void, void, void, void, void>::Type functionPointer, void*, const MultiType&, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { return (*functionPointer)(); } }; 430 template <bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller<void, void, isconst, P1, P2, P3, P4, P5> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, P3, P4, P5>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(param1, param2, param3, param4, param5); return MultiType::Null; } }; 431 template <bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<void, void, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, P3, P4, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType&) { (*functionPointer)(param1, param2, param3, param4); return MultiType::Null; } }; 432 template <bool isconst, class P1, class P2, class P3> struct FunctorCaller<void, void, isconst, P1, P2, P3, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, P3, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType&, const MultiType&) { (*functionPointer)(param1, param2, param3); return MultiType::Null; } }; 433 template <bool isconst, class P1, class P2> struct FunctorCaller<void, void, isconst, P1, P2, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, P2, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType&, const MultiType&, const MultiType&) { (*functionPointer)(param1, param2); return MultiType::Null; } }; 434 template <bool isconst, class P1> struct FunctorCaller<void, void, isconst, P1, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, P1, void, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { (*functionPointer)(param1); return MultiType::Null; } }; 435 template <bool isconst> struct FunctorCaller<void, void, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, void, void, void, void, void>::Type functionPointer, void*, const MultiType&, const MultiType&, const MultiType&, const MultiType&, const MultiType&) { (*functionPointer)(); return MultiType::Null; } }; 436 437 // Helper class, used to identify the header of a function-pointer (independent of its class) 438 template <class R, class P1, class P2, class P3, class P4, class P5> 439 struct FunctorHeaderIdentifier 440 {}; 388 // Helper class to get the type of the function-pointer (or the function-object) with the given class, parameters, return-value, and constness 389 template <class F, class R, class O, bool isconst, class... Params> struct FunctionType /* generic type is undefined */; 390 template < class R, class O, class... Params> struct FunctionType<void, R, O, false, Params...> { typedef R (O::*Type)(Params...); }; // spezialization: non-const member function 391 template < class R, class O, class... Params> struct FunctionType<void, R, O, true, Params...> { typedef R (O::*Type)(Params...) const; }; // spezialization: const member function 392 template < class R, class... Params> struct FunctionType<void, R, void, false, Params...> { typedef R (*Type)(Params...); }; // spezialization: static function 393 template <class F, class R, class... Params> struct FunctionType<F, R, void, false, Params...> { typedef F Type; }; // spezialization: function object 394 395 // Helper class, used to call a function with a given object and parameters and to return its return-value (if available) 396 template <class F, class R, class O, bool isconst, class... Params> struct FunctorCaller /* generic type is undefined */; 397 template < class R, class O, bool isconst, class... Params> struct FunctorCaller<void, R, O, isconst, Params...> { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionType<void, R, O, isconst, Params...>::Type functionPointer, O* object, const Params&... parameters, const UnusedParams&...) { return (object->*functionPointer)(parameters...); } }; // spezialization: member function with return value 398 template < class O, bool isconst, class... Params> struct FunctorCaller<void, void, O, isconst, Params...> { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionType<void, void, O, isconst, Params...>::Type functionPointer, O* object, const Params&... parameters, const UnusedParams&...) { (object->*functionPointer)(parameters...); return MultiType::Null; } }; // spezialization: member function without return value 399 template < class R, class... Params> struct FunctorCaller<void, R, void, false, Params...> { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionType<void, R, void, false, Params...>::Type functionPointer, void*, const Params&... parameters, const UnusedParams&...) { return (*functionPointer)(parameters...); } }; // spezialization: static function with return value 400 template < class... Params> struct FunctorCaller<void, void, void, false, Params...> { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionType<void, void, void, false, Params...>::Type functionPointer, void*, const Params&... parameters, const UnusedParams&...) { (*functionPointer)(parameters...); return MultiType::Null; } }; // spezialization: static function without return value 401 template <class F, class R, class... Params> struct FunctorCaller<F, R, void, false, Params...> { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionType<F, R, void, false, Params...>::Type functor, void*, const Params&... parameters, const UnusedParams&...) { return functor(parameters...); } }; // spezialization: function object with return value 402 template <class F, class... Params> struct FunctorCaller<F, void, void, false, Params...> { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionType<F, void, void, false, Params...>::Type functor, void*, const Params&... parameters, const UnusedParams&...) { functor(parameters...); return MultiType::Null; } }; // spezialization: function object without return value 441 403 442 404 // Helper class to determine if a function has a returnvalue … … 448 410 { enum { result = false }; }; 449 411 450 // Helper class to count the number of parameters 451 template <class P1, class P2, class P3, class P4, class P5> 452 struct FunctorParamCount 453 { enum { result = 5 }; }; 454 template <class P1, class P2, class P3, class P4> 455 struct FunctorParamCount<P1, P2, P3, P4, void> 456 { enum { result = 4 }; }; 457 template <class P1, class P2, class P3> 458 struct FunctorParamCount<P1, P2, P3, void, void> 459 { enum { result = 3 }; }; 460 template <class P1, class P2> 461 struct FunctorParamCount<P1, P2, void, void, void> 462 { enum { result = 2 }; }; 463 template <class P1> 464 struct FunctorParamCount<P1, void, void, void, void> 465 { enum { result = 1 }; }; 412 // Helper class to determine the N-th parameter of a variadic template (with 0 being the index of the first parameter) 413 template <int n, typename T = void, typename... Other> 414 struct GetNthParamType 415 { typedef typename GetNthParamType<n - 1, Other...>::Type Type; }; 416 template <typename T, typename... Other> 417 struct GetNthParamType<0, T, Other...> 418 { typedef T Type; }; 419 420 // Helper structs to deduce the first N types of a parameter pack 421 template<class... Types> struct type_list {}; 422 423 template <class T1, class... AllTypes> 424 struct make_type_list_helper 425 { 426 template <std::size_t N, class... Types> 427 struct make_type_list_impl : make_type_list_helper<AllTypes...>::template make_type_list_impl<N - 1, Types..., T1> {}; 428 429 template <class... Types> 430 struct make_type_list_impl<1u, Types...> : type_list<Types..., T1> {}; 431 }; 432 433 template <class T1> 434 struct make_type_list_helper<T1> 435 { 436 template <std::size_t N, class... Types> 437 struct make_type_list_impl : type_list<Types..., T1> {}; 438 }; 439 440 template <std::size_t N, class... Types> 441 struct make_type_list : make_type_list_helper<Types...>::template make_type_list_impl<N> {}; 442 443 template <class... Types> 444 struct make_type_list<0u, Types...> : type_list<> {}; 445 446 template <std::size_t N> 447 struct make_type_list<N> : type_list<> {}; 448 466 449 template <> 467 struct FunctorParamCount<void, void, void, void, void> 468 { enum { result = 0 }; }; 450 struct make_type_list<0u> : type_list<> {}; 469 451 } 470 452 … … 473 455 that need to know the exact types of the parameters, return-value, and class. 474 456 457 @param F the type of the function-object (or void if a function-pointer is used). 475 458 @param R The type of the return-value of the function 476 459 @param O The class of the function 477 460 @param isconst True if the function is a const member-function 478 @param P1 The type of the first parameter 479 @param P2 The type of the second parameter 480 @param P3 The type of the third parameter 481 @param P4 The type of the fourth parameter 482 @param P5 The type of the fifth parameter 461 @param Params The types of the parameters 483 462 484 463 This template has many parameters and is usually not used directly. It is created by … … 489 468 All template arguments can be void. 490 469 */ 491 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> 492 class FunctorTemplate : public FunctorPointer<typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type, O> 493 { 470 template <class F, class R, class O, bool isconst, class... Params> 471 class FunctorTemplate : public FunctorPointer<typename detail::FunctionType<F, R, O, isconst, Params...>::Type, O> 472 { 473 static_assert(sizeof...(Params) <= 5, "Only up to 5 parameters are supported"); 474 494 475 public: 495 476 /// Constructor: Initializes the base class. 496 FunctorTemplate(typename detail::Function Pointer<R, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object = 0) : FunctorPointer<typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type, O>(functionPointer, object) {}477 FunctorTemplate(typename detail::FunctionType<F, R, O, isconst, Params...>::Type functionPointer, O* object = nullptr) : FunctorPointer<typename detail::FunctionType<F, R, O, isconst, Params...>::Type, O>(functionPointer, object) {} 497 478 498 479 // see FunctorMember::operator()() 499 MultiType operator()(O* object, const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null)500 { 501 return detail::FunctorCaller< R, O, isconst, P1, P2, P3, P4, P5>::call(this->functionPointer_, object, param1, param2, param3, param4, param5);480 virtual MultiType operator()(O* object, const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null) override 481 { 482 return detail::FunctorCaller<F, R, O, isconst, Params...>::call(this->functionPointer_, object, param1, param2, param3, param4, param5); 502 483 } 503 484 504 485 // see Functor::clone() 505 FunctorPtr clone()506 { 507 return new FunctorTemplate(*this);486 virtual FunctorPtr clone() override 487 { 488 return std::make_shared<FunctorTemplate>(*this); 508 489 } 509 490 510 491 // see Functor::evaluateArgument() 511 v oid evaluateArgument(unsigned int index, MultiType& argument) const492 virtual void evaluateArgument(unsigned int index, MultiType& argument) const override 512 493 { 513 494 switch (index) 514 495 { 515 case 0: argument.convert< P1>(); break;516 case 1: argument.convert< P2>(); break;517 case 2: argument.convert< P3>(); break;518 case 3: argument.convert< P4>(); break;519 case 4: argument.convert< P5>(); break;496 case 0: argument.convert<typename detail::GetNthParamType<0, Params...>::Type>(); break; 497 case 1: argument.convert<typename detail::GetNthParamType<1, Params...>::Type>(); break; 498 case 2: argument.convert<typename detail::GetNthParamType<2, Params...>::Type>(); break; 499 case 3: argument.convert<typename detail::GetNthParamType<3, Params...>::Type>(); break; 500 case 4: argument.convert<typename detail::GetNthParamType<4, Params...>::Type>(); break; 520 501 } 521 502 } 522 503 523 504 // see Functor::getParamCount() 524 unsigned int getParamCount() const525 { 526 return detail::FunctorParamCount<P1, P2, P3, P4, P5>::result;505 virtual unsigned int getParamCount() const override 506 { 507 return sizeof...(Params); 527 508 } 528 509 529 510 // see Functor::hasReturnvalue() 530 bool hasReturnvalue() const511 virtual bool hasReturnvalue() const override 531 512 { 532 513 return detail::FunctorHasReturnvalue<R>::result; … … 534 515 535 516 // see Functor::getTypenameParam() 536 std::string getTypenameParam(unsigned int index) const517 virtual std::string getTypenameParam(unsigned int index) const override 537 518 { 538 519 switch (index) 539 520 { 540 case 0: return typeToString< P1>();541 case 1: return typeToString< P2>();542 case 2: return typeToString< P3>();543 case 3: return typeToString< P4>();544 case 4: return typeToString< P5>();521 case 0: return typeToString<typename detail::GetNthParamType<0, Params...>::Type>(); 522 case 1: return typeToString<typename detail::GetNthParamType<1, Params...>::Type>(); 523 case 2: return typeToString<typename detail::GetNthParamType<2, Params...>::Type>(); 524 case 3: return typeToString<typename detail::GetNthParamType<3, Params...>::Type>(); 525 case 4: return typeToString<typename detail::GetNthParamType<4, Params...>::Type>(); 545 526 default: return ""; 546 527 } … … 548 529 549 530 // see Functor::getTypenameReturnvalue() 550 std::string getTypenameReturnvalue() const531 virtual std::string getTypenameReturnvalue() const override 551 532 { 552 533 return typeToString<R>(); 553 534 } 554 535 536 // see Functor::getFullIdentifier() 537 virtual const std::type_info& getFullIdentifier() const override 538 { 539 return typeid(typename detail::FunctionType<void, R, O, isconst, Params...>::Type); 540 } 541 555 542 // see Functor::getHeaderIdentifier() 556 const std::type_info& getHeaderIdentifier() const557 { 558 return typeid( detail::FunctorHeaderIdentifier<R, P1, P2, P3, P4, P5>);543 virtual const std::type_info& getHeaderIdentifier() const override 544 { 545 return typeid(typename detail::FunctionType<void, R, void, false, Params...>::Type); 559 546 } 560 547 561 548 // see Functor::getHeaderIdentifier(unsigned int) 562 const std::type_info& getHeaderIdentifier(unsigned int params) const549 virtual const std::type_info& getHeaderIdentifier(unsigned int params) const override 563 550 { 564 551 switch (params) 565 552 { 566 case 0: return t ypeid(detail::FunctorHeaderIdentifier<R, void, void, void, void, void>);567 case 1: return t ypeid(detail::FunctorHeaderIdentifier<R, P1, void, void, void, void>);568 case 2: return t ypeid(detail::FunctorHeaderIdentifier<R, P1, P2, void, void, void>);569 case 3: return t ypeid(detail::FunctorHeaderIdentifier<R, P1, P2, P3, void, void>);570 case 4: return t ypeid(detail::FunctorHeaderIdentifier<R, P1, P2, P3, P4, void>);571 default: return t ypeid(detail::FunctorHeaderIdentifier<R, P1, P2, P3, P4, P5>);553 case 0: return this->getTypelistIdentifier(detail::make_type_list<0, Params...>{}); 554 case 1: return this->getTypelistIdentifier(detail::make_type_list<1, Params...>{}); 555 case 2: return this->getTypelistIdentifier(detail::make_type_list<2, Params...>{}); 556 case 3: return this->getTypelistIdentifier(detail::make_type_list<3, Params...>{}); 557 case 4: return this->getTypelistIdentifier(detail::make_type_list<4, Params...>{}); 558 default: return this->getTypelistIdentifier(detail::make_type_list<5, Params...>{}); 572 559 } 573 560 } 561 562 private: 563 /// Helper function that deduces a parameter pack of types and returns the corresponding identifier 564 template<class... Types> 565 const std::type_info& getTypelistIdentifier(detail::type_list<Types...>) const 566 { 567 return typeid(typename detail::FunctionType<void, R, void, false, Types...>::Type); 568 } 574 569 }; 575 570 576 template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 577 template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 578 template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 579 template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 580 template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1), OO* object) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 581 template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(), OO* object) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 582 template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 583 template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 584 template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 585 template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 586 template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const, OO* object) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 587 template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const, OO* object) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 588 589 template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 590 template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 591 template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 592 template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2)) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 593 template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1)) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 594 template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)()) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 595 template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 596 template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 597 template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 598 template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 599 template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 600 template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 601 602 template <class R, class P1, class P2, class P3, class P4, class P5> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, P5>(functionPointer); } ///< Creates a new Functor with the given function-pointer 603 template <class R, class P1, class P2, class P3, class P4> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 604 template <class R, class P1, class P2, class P3> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, void, false, P1, P2, P3, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 605 template <class R, class P1, class P2> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2)) { return new FunctorTemplate<R, void, false, P1, P2, void, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 606 template <class R, class P1> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1)) { return new FunctorTemplate<R, void, false, P1, void, void, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 607 template <class R> inline FunctorStaticPtr createFunctor(R (*functionPointer)()) { return new FunctorTemplate<R, void, false, void, void, void, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 571 572 namespace detail 573 { 574 // Helper functions to deduce types and constness of operator() and return the correct FunctorTemplate 575 template <class F> 576 struct CallableHelper 577 { 578 template <class R, class... Params> static inline FunctorStaticPtr create(const F& functionObject, R(F::*)(Params...)) { return std::make_shared<FunctorTemplate<F, R, void, false, Params...>>(functionObject); } 579 template <class R, class... Params> static inline FunctorStaticPtr create(const F& functionObject, R(F::*)(Params...) const) { return std::make_shared<FunctorTemplate<F, R, void, false, Params...>>(functionObject); } // note: both const and non-const function-objects are treated as static functors with isconst=false. 580 }; 581 } 582 583 template <class R, class O, class OO, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...), OO* object) { return std::make_shared<FunctorTemplate<void, R, O, false, Params...>>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 584 template <class R, class O, class OO, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...) const, OO* object) { return std::make_shared<FunctorTemplate<void, R, O, true, Params...>>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 585 586 template <class R, class O, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...)) { return std::make_shared<FunctorTemplate<void, R, O, false, Params...>>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 587 template <class R, class O, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...) const) { return std::make_shared<FunctorTemplate<void, R, O, true, Params...>>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 588 589 template <class R, class... Params> inline FunctorStaticPtr createFunctor(R (*functionPointer)(Params...)) { return std::make_shared<FunctorTemplate<void, R, void, false, Params...>>(functionPointer); } ///< Creates a new FunctorStatic with the given function-pointer 590 591 /** Take care that this functor does not outlive objects that have been captured by reference in a lambda. */ 592 template <class F> inline FunctorStaticPtr createFunctor(const F& functionObject) { return detail::CallableHelper<F>::create(functionObject, &F::operator()); } ///< Creates a new Functor with a callable object 608 593 } 609 594 -
code/trunk/src/libraries/core/command/FunctorPtr.h
r7401 r11071 32 32 @brief Typedefs and definitions of FunctorPtr, FunctorMemberPtr, FunctorStaticPtr, and FunctorPointerPtr 33 33 34 Instances of orxonox::Functor are usually managed by an orxonox::SharedPtr. This ensures34 Instances of orxonox::Functor are usually managed by an std::shared_ptr. This ensures 35 35 that Functors will be destroyed after usage. To make things easier, there's a typedef 36 that defines FunctorPtr as SharedPtr<Functor>.36 that defines FunctorPtr as std::shared_ptr<Functor>. 37 37 38 38 Because there's not only orxonox::Functor, but also orxonox::FunctorStatic, and … … 51 51 52 52 #include "core/CorePrereqs.h" 53 #include "util/SharedPtr.h"53 #include <memory> 54 54 55 55 namespace orxonox 56 56 { 57 /// FunctorPtr is just a typedef of SharedPtr 58 typedef SharedPtr<Functor> FunctorPtr; 59 60 /// It's not possible to use a typedef for FunctorMemberPtr<T>, so we have to create a child-class instead. It inherits all functions from SharedChildPtr, but needs to (re-)implement some constructors. 57 using FunctorPtr = std::shared_ptr<Functor>; 61 58 template <class T> 62 class FunctorMemberPtr : public SharedChildPtr<FunctorMember<T>, FunctorPtr> 63 { 64 public: 65 inline FunctorMemberPtr() : SharedChildPtr<FunctorMember<T>, FunctorPtr>() {} 66 inline FunctorMemberPtr(FunctorMember<T>* pointer) : SharedChildPtr<FunctorMember<T>, FunctorPtr>(pointer) {} 67 inline FunctorMemberPtr(const SharedPtr<FunctorMember<T> >& other) : SharedChildPtr<FunctorMember<T>, FunctorPtr>(other) {} 68 }; 69 70 /// FunctorStaticPtr is just FunctorMemberPtr with @a T = void 71 typedef FunctorMemberPtr<void> FunctorStaticPtr; 72 73 /// It's not possible to use a typedef for FunctorPointerPtr<T>, so we have to create a child-class instead. It inherits all functions from SharedChildPtr, but needs to (re-)implement some constructors. 59 using FunctorMemberPtr = std::shared_ptr<FunctorMember<T>>; 60 using FunctorStaticPtr = std::shared_ptr<FunctorMember<void>>; 74 61 template <class F, class T> 75 class FunctorPointerPtr : public SharedChildPtr<FunctorPointer<F, T>, FunctorMemberPtr<T> > 76 { 77 public: 78 inline FunctorPointerPtr() : SharedChildPtr<FunctorPointer<F, T>, FunctorMemberPtr<T> >() {} 79 inline FunctorPointerPtr(FunctorPointer<F, T>* pointer) : SharedChildPtr<FunctorPointer<F, T>, FunctorMemberPtr<T> >(pointer) {} 80 inline FunctorPointerPtr(const SharedPtr<FunctorPointer<F, T> >& other) : SharedChildPtr<FunctorPointer<F, T>, FunctorMemberPtr<T> >(other) {} 81 }; 62 using FunctorPointerPtr = std::shared_ptr<FunctorPointer<F, T>>; 82 63 } 83 64 -
code/trunk/src/libraries/core/command/IOConsolePOSIX.cc
r9667 r11071 44 44 namespace orxonox 45 45 { 46 IOConsole* IOConsole::singletonPtr_s = NULL; 47 48 namespace EscapeMode 49 { 50 enum Value 51 { 52 None, 53 First, 54 Second 55 }; 56 } 46 IOConsole* IOConsole::singletonPtr_s = nullptr; 47 48 enum class EscapeMode 49 { 50 None, 51 First, 52 Second 53 }; 57 54 58 55 IOConsole::IOConsole() … … 62 59 , promptString_("orxonox # ") 63 60 , bStatusPrinted_(false) 64 , originalTerminalSettings_( 0)61 , originalTerminalSettings_(nullptr) 65 62 { 66 63 this->setTerminalMode(); … … 90 87 std::cout.flush(); 91 88 if (!this->origCout_.str().empty()) 92 this->shell_->addOutput(this->origCout_.str(), Shell:: Cout);89 this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout); 93 90 // Erase input and status lines 94 91 this->cout_ << "\033[1G\033[J"; … … 111 108 unsigned char c; 112 109 std::string escapeSequence; 113 EscapeMode ::ValueescapeMode = EscapeMode::None;110 EscapeMode escapeMode = EscapeMode::None; 114 111 while (std::cin.good()) 115 112 { … … 231 228 if (!this->origCout_.str().empty()) 232 229 { 233 this->shell_->addOutput(this->origCout_.str(), Shell:: Cout);230 this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout); 234 231 this->origCout_.str(""); 235 232 } … … 241 238 switch (type) 242 239 { 243 case Shell:: Message:244 case Shell:: DebugOutput: this->cout_ << "\033[0m"; break;245 246 case Shell:: UserError: this->cout_ << "\033[91m"; break;247 case Shell:: UserWarning: this->cout_ << "\033[93m"; break;248 case Shell:: UserStatus: this->cout_ << "\033[92m"; break;249 case Shell:: UserInfo: this->cout_ << "\033[96m"; break;250 251 case Shell:: InternalError: this->cout_ << "\033[31m"; break;252 case Shell:: InternalWarning: this->cout_ << "\033[33m"; break;253 case Shell:: InternalStatus: this->cout_ << "\033[32m"; break;254 case Shell:: InternalInfo: this->cout_ << "\033[36m"; break;255 256 case Shell:: Verbose: this->cout_ << "\033[94m"; break;257 case Shell:: VerboseMore: this->cout_ << "\033[34m"; break;258 case Shell:: VerboseUltra: this->cout_ << "\033[34m"; break;259 260 case Shell:: Command: this->cout_ << "\033[95m"; break;261 case Shell:: Hint: this->cout_ << "\033[35m"; break;262 263 default: this->cout_ << "\033[37m"; break;240 case Shell::LineType::Message: 241 case Shell::LineType::DebugOutput: this->cout_ << "\033[0m"; break; 242 243 case Shell::LineType::UserError: this->cout_ << "\033[91m"; break; 244 case Shell::LineType::UserWarning: this->cout_ << "\033[93m"; break; 245 case Shell::LineType::UserStatus: this->cout_ << "\033[92m"; break; 246 case Shell::LineType::UserInfo: this->cout_ << "\033[96m"; break; 247 248 case Shell::LineType::InternalError: this->cout_ << "\033[31m"; break; 249 case Shell::LineType::InternalWarning: this->cout_ << "\033[33m"; break; 250 case Shell::LineType::InternalStatus: this->cout_ << "\033[32m"; break; 251 case Shell::LineType::InternalInfo: this->cout_ << "\033[36m"; break; 252 253 case Shell::LineType::Verbose: this->cout_ << "\033[94m"; break; 254 case Shell::LineType::VerboseMore: this->cout_ << "\033[34m"; break; 255 case Shell::LineType::VerboseUltra: this->cout_ << "\033[34m"; break; 256 257 case Shell::LineType::Command: this->cout_ << "\033[95m"; break; 258 case Shell::LineType::Hint: this->cout_ << "\033[35m"; break; 259 260 default: this->cout_ << "\033[37m"; break; 264 261 } 265 262 … … 326 323 tcsetattr(0, TCSANOW, IOConsole::singletonPtr_s->originalTerminalSettings_); 327 324 delete IOConsole::singletonPtr_s->originalTerminalSettings_; 328 IOConsole::singletonPtr_s->originalTerminalSettings_ = 0;325 IOConsole::singletonPtr_s->originalTerminalSettings_ = nullptr; 329 326 } 330 327 } … … 353 350 const char* s; 354 351 if (!this->terminalWidth_ && (s = getenv("COLUMNS"))) 355 this->terminalWidth_ = strtol(s, NULL, 10);352 this->terminalWidth_ = strtol(s, nullptr, 10); 356 353 if (!this->terminalWidth_) 357 354 this->terminalWidth_ = 80; 358 355 if (!this->terminalHeight_ && (s = getenv("LINES"))) 359 this->terminalHeight_ = strtol(s, NULL, 10);356 this->terminalHeight_ = strtol(s, nullptr, 10); 360 357 if (!this->terminalHeight_) 361 358 this->terminalHeight_ = 24; … … 384 381 void IOConsole::executed() 385 382 { 386 this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell:: Command);383 this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell::LineType::Command); 387 384 } 388 385 -
code/trunk/src/libraries/core/command/IOConsolePOSIX.h
r8858 r11071 65 65 66 66 // Methods from ShellListener 67 v oid linesChanged();68 v oid lineAdded();69 v oid inputChanged();70 v oid cursorChanged();71 v oid executed();72 v oid exit();67 virtual void linesChanged() override; 68 virtual void lineAdded() override; 69 virtual void inputChanged() override; 70 virtual void cursorChanged() override; 71 virtual void executed() override; 72 virtual void exit() override; 73 73 74 74 bool willPrintStatusLines(); -
code/trunk/src/libraries/core/command/IOConsoleWindows.cc
r9676 r11071 41 41 namespace orxonox 42 42 { 43 IOConsole* IOConsole::singletonPtr_s = NULL;43 IOConsole* IOConsole::singletonPtr_s = nullptr; 44 44 45 45 //! Redirects std::cout, creates the corresponding Shell and changes the terminal mode … … 97 97 std::cout.flush(); 98 98 if (!this->origCout_.str().empty()) 99 this->shell_->addOutput(this->origCout_.str(), Shell:: Cout);99 this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout); 100 100 101 101 this->shell_->unregisterListener(this); … … 190 190 if (!this->origCout_.str().empty()) 191 191 { 192 this->shell_->addOutput(this->origCout_.str(), Shell:: Cout);192 this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout); 193 193 this->origCout_.str(""); 194 194 } … … 202 202 switch (type) 203 203 { 204 case Shell:: Message:205 case Shell:: DebugOutput: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;206 207 case Shell:: UserError: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0 | 0 ; break;208 case Shell:: UserWarning: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | 0 ; break;209 case Shell:: UserStatus: colour = FOREGROUND_INTENSITY | 0 | FOREGROUND_GREEN | 0 ; break;210 case Shell:: UserInfo: colour = FOREGROUND_INTENSITY | 0 | FOREGROUND_GREEN | FOREGROUND_BLUE; break;211 212 case Shell:: InternalError: colour = 0 | FOREGROUND_RED | 0 | 0 ; break;213 case Shell:: InternalWarning: colour = 0 | FOREGROUND_RED | FOREGROUND_GREEN | 0 ; break;214 case Shell:: InternalStatus: colour = 0 | 0 | FOREGROUND_GREEN | 0 ; break;215 case Shell:: InternalInfo: colour = 0 | 0 | FOREGROUND_GREEN | FOREGROUND_BLUE; break;216 217 case Shell:: Verbose: colour = FOREGROUND_INTENSITY | 0 | 0 | FOREGROUND_BLUE; break;218 case Shell:: VerboseMore: colour = FOREGROUND_INTENSITY | 0 | 0 | FOREGROUND_BLUE; break;219 case Shell:: VerboseUltra: colour = FOREGROUND_INTENSITY | 0 | 0 | FOREGROUND_BLUE; break;220 221 case Shell:: Command: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0 | FOREGROUND_BLUE; break;222 case Shell:: Hint: colour = 0 | FOREGROUND_RED | 0 | FOREGROUND_BLUE; break;223 224 default: colour = 0 | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;204 case Shell::LineType::Message: 205 case Shell::LineType::DebugOutput: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break; 206 207 case Shell::LineType::UserError: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0 | 0 ; break; 208 case Shell::LineType::UserWarning: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | 0 ; break; 209 case Shell::LineType::UserStatus: colour = FOREGROUND_INTENSITY | 0 | FOREGROUND_GREEN | 0 ; break; 210 case Shell::LineType::UserInfo: colour = FOREGROUND_INTENSITY | 0 | FOREGROUND_GREEN | FOREGROUND_BLUE; break; 211 212 case Shell::LineType::InternalError: colour = 0 | FOREGROUND_RED | 0 | 0 ; break; 213 case Shell::LineType::InternalWarning: colour = 0 | FOREGROUND_RED | FOREGROUND_GREEN | 0 ; break; 214 case Shell::LineType::InternalStatus: colour = 0 | 0 | FOREGROUND_GREEN | 0 ; break; 215 case Shell::LineType::InternalInfo: colour = 0 | 0 | FOREGROUND_GREEN | FOREGROUND_BLUE; break; 216 217 case Shell::LineType::Verbose: colour = FOREGROUND_INTENSITY | 0 | 0 | FOREGROUND_BLUE; break; 218 case Shell::LineType::VerboseMore: colour = FOREGROUND_INTENSITY | 0 | 0 | FOREGROUND_BLUE; break; 219 case Shell::LineType::VerboseUltra: colour = FOREGROUND_INTENSITY | 0 | 0 | FOREGROUND_BLUE; break; 220 221 case Shell::LineType::Command: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0 | FOREGROUND_BLUE; break; 222 case Shell::LineType::Hint: colour = 0 | FOREGROUND_RED | 0 | FOREGROUND_BLUE; break; 223 224 default: colour = 0 | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break; 225 225 } 226 226 … … 300 300 this->terminalWidth_ - 1, this->inputLineRow_ + this->inputLineHeight_ + this->statusLines_ - 1); 301 301 this->inputLineRow_ += linesDown; 302 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, NULL, makeCOORD(0, this->inputLineRow_), &fillChar);302 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, nullptr, makeCOORD(0, this->inputLineRow_), &fillChar); 303 303 // Move cursor down to the new bottom so the user can see the status lines 304 304 COORD pos = makeCOORD(0, this->inputLineRow_ + this->inputLineHeight_ - 1 + this->statusLines_); … … 312 312 // Scroll output up 313 313 SMALL_RECT oldRect = makeSMALL_RECT(0, lines - linesDown, this->terminalWidth_ - 1, this->inputLineRow_ - 1); 314 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, NULL, makeCOORD(0, 0), &fillChar);314 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, nullptr, makeCOORD(0, 0), &fillChar); 315 315 } 316 316 } … … 331 331 void IOConsole::executed() 332 332 { 333 this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell:: Command);333 this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell::LineType::Command); 334 334 } 335 335 … … 360 360 SMALL_RECT oldRect = makeSMALL_RECT(0, statusLineRow, this->terminalWidth_ - 1, statusLineRow + this->statusLines_); 361 361 CHAR_INFO fillChar = {{' '}, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED}; 362 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, NULL, makeCOORD(0, statusLineRow + newLines), &fillChar);362 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, nullptr, makeCOORD(0, statusLineRow + newLines), &fillChar); 363 363 // Clear potential leftovers 364 364 if (-newLines - this->statusLines_ > 0) -
code/trunk/src/libraries/core/command/IOConsoleWindows.h
r9676 r11071 67 67 68 68 // Methods from ShellListener 69 v oid linesChanged();70 v oid lineAdded();71 v oid inputChanged();72 v oid cursorChanged();73 v oid executed();74 v oid exit();69 virtual void linesChanged() override; 70 virtual void lineAdded() override; 71 virtual void inputChanged() override; 72 virtual void cursorChanged() override; 73 virtual void executed() override; 74 virtual void exit() override; 75 75 76 76 void resetTerminalMode(); -
code/trunk/src/libraries/core/command/IRC.cc
r10624 r11071 44 44 namespace orxonox 45 45 { 46 static const unsigned int IRC_TCL_THREADID = 1421421421; ///< The ID of the thread in TclThreadManager that is used for the IRC connection46 static constexpr unsigned int IRC_TCL_THREADID = 1421421421; ///< The ID of the thread in TclThreadManager that is used for the IRC connection 47 47 48 48 SetConsoleCommand("IRC", "say", &IRC::say); … … 66 66 IRC::IRC() 67 67 { 68 this->interpreter_ = 0;68 this->interpreter_ = nullptr; 69 69 } 70 70 -
code/trunk/src/libraries/core/command/IRC.h
r7401 r11071 65 65 66 66 IRC(); 67 IRC(const IRC& other); ///< Copy-constructor: Not implemented 68 ~IRC() {} ///< Destructor 67 ~IRC() = default; 68 69 // non-copyable: 70 IRC(const IRC&) = delete; 71 IRC& operator=(const IRC&) = delete; 69 72 70 73 Tcl::interpreter* interpreter_; ///< The Tcl interpreter that is used for the IRC connection -
code/trunk/src/libraries/core/command/Shell.cc
r10624 r11071 258 258 vectorize(text, '\n', &lines); 259 259 260 for ( size_t i = 0; i < lines.size(); ++i)261 this->addLine(line s[i], type);260 for (const std::string& line : lines) 261 this->addLine(line, type); 262 262 } 263 263 … … 268 268 { 269 269 // yes it was - push the new line to the list 270 this->outputLines_.push_front(std::make_pair(line, static_cast<LineType>(type)));270 this->outputLines_.push_front(std::make_pair(line, type)); 271 271 272 272 // adjust the scroll position if needed … … 381 381 const std::string& result = CommandExecutor::query(this->inputBuffer_->get(), &error); 382 382 if (error) 383 this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", " + CommandExecutor::getErrorDescription(error) + ". (Shell)", UserError);383 this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", " + CommandExecutor::getErrorDescription(error) + ". (Shell)", LineType::UserError); 384 384 else if (result != "") 385 this->addOutput(result, Result);385 this->addOutput(result, LineType::Result); 386 386 387 387 this->clearInput(); … … 392 392 { 393 393 this->inputBuffer_->set(CommandExecutor::evaluate(this->inputBuffer_->get()).complete()); 394 this->addOutput(CommandExecutor::evaluate(this->inputBuffer_->get()).hint(), Hint);394 this->addOutput(CommandExecutor::evaluate(this->inputBuffer_->get()).hint(), LineType::Hint); 395 395 396 396 this->inputChanged(); -
code/trunk/src/libraries/core/command/Shell.h
r10624 r11071 61 61 62 62 public: 63 virtual ~ShellListener() {} 63 ShellListener() = default; 64 virtual ~ShellListener() = default; 64 65 65 66 private: … … 87 88 public: 88 89 /// Defines the type of a line of text in the Shell - some types depend on the output level, others are of internal use. 89 enum LineType90 enum class LineType 90 91 { 91 92 DebugOutput = debug_output, … … 128 129 const std::string& getInput() const; 129 130 130 typedef std::list<std::pair<std::string, LineType> 131 typedef std::list<std::pair<std::string, LineType>> LineList; 131 132 LineList::const_iterator getNewestLineIterator() const; 132 133 LineList::const_iterator getEndIterator() const; 133 134 134 void addOutput(const std::string& text, LineType type = DebugOutput);135 void addLine(const std::string& line, LineType type = DebugOutput);135 void addOutput(const std::string& text, LineType type = LineType::DebugOutput); 136 void addLine(const std::string& line, LineType type = LineType::DebugOutput); 136 137 void clearOutput(); 137 138 … … 148 149 149 150 private: 150 Shell(const Shell& other); 151 // non-copyable: 152 Shell(const Shell&) = delete; 153 Shell& operator=(const Shell&) = delete; 151 154 152 155 // DevModeListener 153 v oid devModeChanged(bool value);156 virtual void devModeChanged(bool value) override; 154 157 155 158 void addToHistory(const std::string& command); … … 157 160 void clearInput(); 158 161 // BaseWriter 159 virtual void printLine(const std::string& line, OutputLevel level) ;162 virtual void printLine(const std::string& line, OutputLevel level) override; 160 163 161 164 void configureInputBuffer(); -
code/trunk/src/libraries/core/command/TclBind.cc
r10624 r11071 47 47 SetConsoleCommand("bgerror", &TclBind::bgerror).hide(); 48 48 49 TclBind* TclBind::singletonPtr_s = 0;49 TclBind* TclBind::singletonPtr_s = nullptr; 50 50 51 51 /** … … 55 55 TclBind::TclBind(const std::string& datapath) 56 56 { 57 this->interpreter_ = 0;57 this->interpreter_ = nullptr; 58 58 this->bSetTclDataPath_ = false; 59 59 this->setDataPath(datapath); … … 228 228 @brief Executes Tcl-code and returns the return-value. 229 229 @param tclcode A string that contains Tcl-code 230 @param error A pointer to an integer (or NULL) that is used to write an error-code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes")230 @param error A pointer to an integer (or nullptr) that is used to write an error-code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 231 231 @return Returns the return-value of the executed code (or an empty string if there's no return-value) 232 232 */ -
code/trunk/src/libraries/core/command/TclBind.h
r8079 r11071 121 121 static void tcl_execute(Tcl::object const &args); 122 122 123 static std::string eval(const std::string& tclcode, int* error = 0);123 static std::string eval(const std::string& tclcode, int* error = nullptr); 124 124 125 125 private: 126 TclBind(const TclBind& other); ///< Copy-constructor, not implemented 126 // non-copyable: 127 TclBind(const TclBind&) = delete; 128 TclBind& operator=(const TclBind&) = delete; 127 129 128 130 static std::string tcl_helper(Tcl::object const &args, bool bQuery); -
code/trunk/src/libraries/core/command/TclThreadList.h
r7401 r11071 262 262 boost::shared_lock<boost::shared_mutex> lock(this->mutex_); 263 263 264 for ( typename std::list<T>::const_iterator it = this->list_.begin(); it != this->list_.end(); ++it)265 if ( *it == value)264 for (const T& element : this->list_) 265 if (element == value) 266 266 return true; 267 267 -
code/trunk/src/libraries/core/command/TclThreadManager.cc
r10624 r11071 34 34 #include "TclThreadManager.h" 35 35 36 #include < boost/bind.hpp>36 #include <functional> 37 37 #include <boost/thread/thread.hpp> 38 38 #include <boost/thread/locks.hpp> … … 86 86 }; 87 87 88 TclThreadManager* TclThreadManager::singletonPtr_s = 0;88 TclThreadManager* TclThreadManager::singletonPtr_s = nullptr; 89 89 90 90 /** … … 145 145 { 146 146 boost::shared_lock<boost::shared_mutex> lock(*this->interpreterBundlesMutex_); 147 for ( std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)147 for (const auto& mapEntry : this->interpreterBundles_) 148 148 { 149 if ( it->first == 0)149 if (mapEntry.first == 0) 150 150 continue; // We'll handle the default interpreter later (and without threads of course) 151 151 152 TclInterpreterBundle* bundle = it->second;152 TclInterpreterBundle* bundle = mapEntry.second; 153 153 if (!bundle->queue_.empty()) 154 154 { … … 163 163 { 164 164 // Start a thread to execute the command 165 boost::thread( boost::bind(&tclThread, bundle, command));165 boost::thread(std::bind(&tclThread, bundle, command)); 166 166 } 167 167 else … … 289 289 catch (const Tcl::tcl_error& e) 290 290 { 291 bundle->interpreter_ = 0;291 bundle->interpreter_ = nullptr; 292 292 orxout(user_error, context::tcl) << "Tcl error while creating Tcl-interpreter (" << id_string << "): " << e.what() << endl; 293 293 } … … 488 488 void TclThreadManager::source(const std::string& file) 489 489 { 490 boost::thread( boost::bind(&sourceThread, file));490 boost::thread(std::bind(&sourceThread, file)); 491 491 } 492 492 … … 521 521 { 522 522 TclThreadManager::error("No Tcl-interpreter with ID " + multi_cast<std::string>(id) + " existing."); 523 return 0;523 return nullptr; 524 524 } 525 525 } … … 551 551 552 552 std::list<unsigned int> threads; 553 for ( std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)554 if ( it->first > 0 && it->first <= this->numInterpreterBundles_) // only list autonumbered interpreters (created with create()) - exclude the default interpreter 0 and all manually numbered interpreters)555 threads.push_back( it->first);553 for (const auto& mapEntry : this->interpreterBundles_) 554 if (mapEntry.first > 0 && mapEntry.first <= this->numInterpreterBundles_) // only list autonumbered interpreters (created with create()) - exclude the default interpreter 0 and all manually numbered interpreters) 555 threads.push_back(mapEntry.first); 556 556 return threads; 557 557 }
Note: See TracChangeset
for help on using the changeset viewer.