Changeset 9550 for code/trunk/src
- Timestamp:
- Mar 12, 2013, 11:13:03 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 52 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/testing (added) merged: 9015,9017,9020-9022,9025-9026,9047,9076-9078,9114-9115,9221-9226,9356,9473-9480,9524,9529-9531,9533-9545,9547-9549
- Property svn:mergeinfo changed
-
code/trunk/src/CMakeLists.txt
r8729 r9550 28 28 INCLUDE(TargetUtilities) 29 29 30 INCLUDE(SourceConfig.cmake) 31 30 32 # Configure the two headers and set some options 31 33 INCLUDE(OrxonoxConfig.cmake) 32 33 ####### Library Behaviour (dependencies) ########34 35 # Disable auto linking completely for Boost and POCO36 ADD_COMPILER_FLAGS("-DBOOST_ALL_NO_LIB")37 ADD_COMPILER_FLAGS("-DPOCO_NO_AUTOMATIC_LIBS")38 39 IF(WIN32)40 # If no defines are specified, these libs get linked statically41 ADD_COMPILER_FLAGS("-DBOOST_ALL_DYN_LINK" LINK_BOOST_DYNAMIC)42 #ADD_COMPILER_FLAGS("-DENET_DLL" LINK_ENET_DYNAMIC)43 ADD_COMPILER_FLAGS("-DLUA_BUILD_AS_DLL" LINK_LUA5.1_DYNAMIC)44 # If no defines are specified, these libs get linked dynamically45 ADD_COMPILER_FLAGS("-DCEGUI_STATIC -DTOLUA_STATIC" NOT LINK_CEGUI_DYNAMIC)46 ADD_COMPILER_FLAGS("-DOGRE_STATIC_LIB" NOT LINK_OGRE_DYNAMIC)47 ADD_COMPILER_FLAGS("-DSTATIC_BUILD" NOT LINK_TCL_DYNAMIC)48 49 # Target Windows XP as minimum Windows version50 # And try to catch all the different macro defines for that...51 ADD_COMPILER_FLAGS("-D_WIN32_WINNT=0x0501")52 ADD_COMPILER_FLAGS("-D_WIN32_WINDOWS=0x0501")53 ADD_COMPILER_FLAGS("-DWINVER=0x0501")54 ADD_COMPILER_FLAGS("-DNTDDI_VERSION=0x05010000")55 ENDIF(WIN32)56 57 # Visual Leak Dectector configuration58 IF(MSVC AND VLD_FOUND)59 OPTION(VISUAL_LEAK_DETECTOR_ENABLE "Memory leak detector" OFF)60 IF(VISUAL_LEAK_DETECTOR_ENABLE)61 # Force library linking by forcing the inclusion of a symbol62 ADD_LINKER_FLAGS("-INCLUDE:__imp_?vld@@3VVisualLeakDetector@@A" Debug)63 IF(MSVC90)64 # VS 2008 incremental linker crashes with /INCLUDE most of the time65 REMOVE_LINKER_FLAGS("-INCREMENTAL:YES" Debug)66 ADD_LINKER_FLAGS ("-INCREMENTAL:NO" Debug)67 ENDIF()68 ENDIF()69 ENDIF()70 71 ######### Library Behaviour (external) ##########72 73 # Use TinyXML++74 ADD_COMPILER_FLAGS("-DTIXML_USE_TICPP")75 76 # Default linking for externals77 IF(CMAKE_BUILD_TYPE MATCHES "(Debug|RelForDevs)")78 SET(_default_link_mode "SHARED")79 ELSE()80 SET(_default_link_mode "STATIC")81 ENDIF()82 SET(_message "Link mode for external libraries that we build ourselves.83 MSVC Note: certain libraries will not be linked shared.")84 SET(ORXONOX_EXTERNAL_LINK_MODE "${_default_link_mode}" CACHE STRING "${_message}")85 86 IF(ORXONOX_EXTERNAL_LINK_MODE STREQUAL "SHARED")87 SET(_external_shared_link TRUE)88 ELSE()89 SET(_external_shared_link FALSE)90 ENDIF()91 # If no defines are specified, these libs get linked dynamically92 ADD_COMPILER_FLAGS("-DENET_DLL" WIN32 _external_shared_link)93 ADD_COMPILER_FLAGS("-DOGRE_GUIRENDERER_STATIC_LIB" WIN32 NOT _external_shared_link)94 ADD_COMPILER_FLAGS("-DOIS_STATIC_LIB" WIN32 NOT _external_shared_link)95 96 ############## Include Directories ##############97 98 # Set the search paths for include files99 INCLUDE_DIRECTORIES(100 # OrxonoxConfig.h101 ${CMAKE_CURRENT_BINARY_DIR}102 103 # All includes in "externals" should be prefixed with the path104 # relative to "external" to avoid conflicts105 ${CMAKE_CURRENT_SOURCE_DIR}/external106 # Include directories needed even if only included by Orxonox107 ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet108 ${CMAKE_CURRENT_SOURCE_DIR}/external/ois109 110 # External111 ${OGRE_INCLUDE_DIR}112 ${CEGUI_INCLUDE_DIR}113 ${CEGUI_TOLUA_INCLUDE_DIR}114 #${ENET_INCLUDE_DIR}115 ${Boost_INCLUDE_DIRS}116 ${POCO_INCLUDE_DIR}117 ${OPENAL_INCLUDE_DIRS}118 ${ALUT_INCLUDE_DIR}119 ${VORBIS_INCLUDE_DIR}120 ${OGG_INCLUDE_DIR}121 ${LUA5.1_INCLUDE_DIR}122 ${TCL_INCLUDE_PATH}123 ${DIRECTX_INCLUDE_DIR}124 ${ZLIB_INCLUDE_DIR}125 )126 127 IF(CEGUI_OLD_VERSION)128 INCLUDE_DIRECTORIES(${CEGUILUA_INCLUDE_DIR})129 ENDIF()130 131 IF (DBGHELP_FOUND)132 INCLUDE_DIRECTORIES(${DBGHELP_INCLUDE_DIR})133 ENDIF()134 135 IF(VISUAL_LEAK_DETECTOR_ENABLE)136 INCLUDE_DIRECTORIES(${VLD_INCLUDE_DIR})137 ENDIF()138 139 ############## CEGUI OGRE Renderer ##############140 141 IF(CEGUI_OGRE_RENDERER_BUILD_REQUIRED)142 SET(CEGUI_OGRE_RENDERER_LIBRARY ogreceguirenderer_orxonox)143 ENDIF()144 145 ################### Tolua Bind ##################146 147 # Add hook script to the lua code that generates the bindings148 SET(TOLUA_PARSER_HOOK_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/libraries/core/ToluaInterfaceHook.lua)149 SET(TOLUA_PARSER_DEPENDENCIES ${TOLUA_PARSER_DEPENDENCIES} ${TOLUA_PARSER_HOOK_SCRIPT})150 34 151 35 ################ Sub Directories ################ … … 194 78 195 79 196 # When using Visual Studio we want to use the output directory as working197 # directory and we also want to specify where the external dlls198 # (lua, ogre, etc.) are. The problem hereby is that these information cannot199 # be specified in CMake because they are not stored in the actual project file.200 # This workaround will create a configured *.vcproj.user file that holds the201 # right values. When starting the solution for the first time,202 # these get written to the *vcproj.yourPCname.yourname.user203 80 IF(MSVC) 204 81 IF(CMAKE_CL_64) … … 206 83 ELSE() 207 84 SET(MSVC_PLATFORM "Win32") 208 ENDIF()209 IF(MSVC10)210 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox-main.vcxproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/orxonox-main.vcxproj.user")211 ELSE()212 STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?).*$" "\\1"213 VISUAL_STUDIO_VERSION_SIMPLE "${CMAKE_GENERATOR}")214 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox-main.vcproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/orxonox-main.vcproj.user")215 85 ENDIF() 216 86 ENDIF(MSVC) -
code/trunk/src/external/CMakeLists.txt
r8351 r9550 24 24 ADD_SUBDIRECTORY(cpptcl) 25 25 ADD_SUBDIRECTORY(enet) 26 ADD_SUBDIRECTORY(gmock) 27 ADD_SUBDIRECTORY(gtest) 26 28 ADD_SUBDIRECTORY(loki) 27 29 IF(CEGUI_OGRE_RENDERER_BUILD_REQUIRED) -
code/trunk/src/libraries/core/CommandLineParser.cc
r8858 r9550 50 50 void CommandLineArgument::parse(const std::string& value) 51 51 { 52 if (value_. getType() == MT_Type::Bool)52 if (value_.isType<bool>()) 53 53 { 54 54 // simulate command line switch … … 69 69 else 70 70 { 71 if (!value_.set Value(value))72 { 73 value_.set Value(defaultValue_);71 if (!value_.set(value)) 72 { 73 value_.set(defaultValue_); 74 74 ThrowException(Argument, "Could not read command line argument '" + getName() + "'."); 75 75 } … … 298 298 infoStr << " "; 299 299 infoStr << "--" << it->second->getName() << ' '; 300 if (it->second->getValue().getType() != MT_Type::Bool) 300 if (it->second->getValue().isType<bool>()) 301 infoStr << " "; 302 else 301 303 infoStr << "ARG "; 302 else303 infoStr << " ";304 304 // fill with the necessary amount of blanks 305 305 infoStr << std::string(maxNameSize - it->second->getName().size(), ' '); -
code/trunk/src/libraries/core/CommandLineParser.h
r8858 r9550 200 200 inline void CommandLineParser::getValue<std::string>(const std::string& name, std::string* value) 201 201 { 202 *value = getArgument(name)->getValue().get String();202 *value = getArgument(name)->getValue().get<std::string>(); 203 203 } 204 204 … … 217 217 OrxAssert(!_getInstance().existsArgument(name), 218 218 "Cannot add a command line argument with name '" + name + "' twice."); 219 OrxAssert( MultiType(defaultValue).getType() != MT_Type::Bool || MultiType(defaultValue).getBool() != true,219 OrxAssert(!MultiType(defaultValue).isType<bool>() || MultiType(defaultValue).get<bool>() != true, 220 220 "Boolean command line arguments with positive default values are not supported." << endl 221 221 << "Please use SetCommandLineSwitch and adjust your argument: " << name); -
code/trunk/src/libraries/core/ConfigValueContainer.cc
r8858 r9550 70 70 this->bIsVector_ = false; 71 71 72 this->defvalueString_ = this->value_.get String();72 this->defvalueString_ = this->value_.get<std::string>(); 73 73 this->update(); 74 74 } … … 83 83 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 84 84 { 85 ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType (MT_Type::String));85 ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType<std::string>()); 86 86 this->defvalueStringVector_.push_back(this->valueVector_[i]); 87 87 } … … 118 118 if (this->tset(input)) 119 119 { 120 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, input, this->value_.isType (MT_Type::String));120 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, input, this->value_.isType<std::string>()); 121 121 return true; 122 122 } … … 137 137 if (this->tset(index, input)) 138 138 { 139 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, index, input, this->value_.isType (MT_Type::String));139 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, index, input, this->value_.isType<std::string>()); 140 140 return true; 141 141 } … … 236 236 this->valueVector_.erase(this->valueVector_.begin() + index); 237 237 for (unsigned int i = index; i < this->valueVector_.size(); i++) 238 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType (MT_Type::String));238 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType<std::string>()); 239 239 ConfigFileManager::getInstance().getConfigFile(this->type_)->deleteVectorEntries(this->sectionname_, this->varname_, this->valueVector_.size()); 240 240 … … 272 272 { 273 273 if (!this->bIsVector_) 274 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType (MT_Type::String));274 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType<std::string>()); 275 275 else 276 276 { … … 281 281 if (i < this->defvalueStringVector_.size()) 282 282 { 283 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType (MT_Type::String));283 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType<std::string>()); 284 284 } 285 285 else 286 286 { 287 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, MultiType(), this->value_.isType (MT_Type::String));287 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, MultiType(), this->value_.isType<std::string>()); 288 288 } 289 289 -
code/trunk/src/libraries/core/Core.cc
r8858 r9550 55 55 #include "util/Exception.h" 56 56 #include "util/output/LogWriter.h" 57 #include "util/output/OutputManager.h" 57 58 #include "util/Scope.h" 58 59 #include "util/ScopedSingletonManager.h" … … 167 168 this->configFileManager_ = new ConfigFileManager(); 168 169 this->configFileManager_->setFilename(ConfigFileType::Settings, 169 CommandLineParser::getValue("settingsFile").get String());170 CommandLineParser::getValue("settingsFile").get<std::string>()); 170 171 171 172 // Required as well for the config values … … 180 181 181 182 // Set the correct log path and rewrite the log file with the correct log levels 182 LogWriter::getInstance().setLogPath(PathConfig::getLogPathString());183 OutputManager::getInstance().getLogWriter()->setLogDirectory(PathConfig::getLogPathString()); 183 184 184 185 #if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN) 185 186 // Create persistent IO console 186 if (CommandLineParser::getValue("noIOConsole").get Bool())187 if (CommandLineParser::getValue("noIOConsole").get<bool>()) 187 188 { 188 189 ModifyConfigValue(bStartIOConsole_, tset, false); … … 258 259 void Core::setConfigValues() 259 260 { 260 SetConfigValueExternal( LogWriter::getInstance().configurableMaxLevel_,261 LogWriter::getInstance().getConfigurableSectionName(),262 LogWriter::getInstance().getConfigurableMaxLevelName(),263 LogWriter::getInstance().configurableMaxLevel_)261 SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableMaxLevel_, 262 OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(), 263 OutputManager::getInstance().getLogWriter()->getConfigurableMaxLevelName(), 264 OutputManager::getInstance().getLogWriter()->configurableMaxLevel_) 264 265 .description("The maximum level of output shown in the log file") 265 .callback(static_cast<BaseWriter*>( &LogWriter::getInstance()), &BaseWriter::changedConfigurableLevel);266 SetConfigValueExternal( LogWriter::getInstance().configurableAdditionalContextsMaxLevel_,267 LogWriter::getInstance().getConfigurableSectionName(),268 LogWriter::getInstance().getConfigurableAdditionalContextsMaxLevelName(),269 LogWriter::getInstance().configurableAdditionalContextsMaxLevel_)266 .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableLevel); 267 SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_, 268 OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(), 269 OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsMaxLevelName(), 270 OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_) 270 271 .description("The maximum level of output shown in the log file for additional contexts") 271 .callback(static_cast<BaseWriter*>( &LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContextsLevel);272 SetConfigValueExternal( LogWriter::getInstance().configurableAdditionalContexts_,273 LogWriter::getInstance().getConfigurableSectionName(),274 LogWriter::getInstance().getConfigurableAdditionalContextsName(),275 LogWriter::getInstance().configurableAdditionalContexts_)272 .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContextsLevel); 273 SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_, 274 OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(), 275 OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsName(), 276 OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_) 276 277 .description("Additional output contexts shown in the log file") 277 .callback(static_cast<BaseWriter*>( &LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContexts);278 .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts); 278 279 279 280 SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun()) … … 337 338 { 338 339 orxout(internal_info) << "loading graphics in Core" << endl; 339 340 340 341 // Any exception should trigger this, even in upgradeToGraphics (see its remarks) 341 342 Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics); -
code/trunk/src/libraries/core/PathConfig.cc
r8858 r9550 188 188 // Check for data path override by the command line 189 189 if (!CommandLineParser::getArgument("externalDataPath")->hasDefaultValue()) 190 externalDataPath_ = CommandLineParser::getValue("externalDataPath").get String();190 externalDataPath_ = CommandLineParser::getValue("externalDataPath").get<std::string>(); 191 191 else 192 192 externalDataPath_ = specialConfig::externalDataDevDirectory; … … 227 227 if (!CommandLineParser::getArgument("writingPathSuffix")->hasDefaultValue()) 228 228 { 229 const std::string& directory(CommandLineParser::getValue("writingPathSuffix").get String());229 const std::string& directory(CommandLineParser::getValue("writingPathSuffix").get<std::string>()); 230 230 configPath_ = configPath_ / directory; 231 231 logPath_ = logPath_ / directory; -
code/trunk/src/libraries/core/command/CommandEvaluation.cc
r8858 r9550 119 119 @brief Executes the command which was evaluated by this object and returns its return-value. 120 120 @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 @return Returns the result of the command (or M T_Type::Null if there is no return value)121 @return Returns the result of the command (or MultiType::Null if there is no return value) 122 122 */ 123 123 MultiType CommandEvaluation::query(int* error) … … 138 138 139 139 if (*error != CommandExecutor::Success) 140 return M T_Type::Null;140 return MultiType::Null; 141 141 } 142 142 … … 170 170 171 171 // return a null value in case of an error 172 return M T_Type::Null;172 return MultiType::Null; 173 173 } 174 174 … … 225 225 return this->arguments_[index]; 226 226 227 return M T_Type::Null;227 return MultiType::Null; 228 228 } 229 229 … … 600 600 // print the default value if available 601 601 if (command->getExecutor()->defaultValueSet(i)) 602 output += '=' + command->getExecutor()->getDefaultValue(i).get String() + ']';602 output += '=' + command->getExecutor()->getDefaultValue(i).get<std::string>() + ']'; 603 603 else 604 604 output += '}'; -
code/trunk/src/libraries/core/command/CommandExecutor.cc
r8858 r9550 83 83 @param error A pointer to a value (or NULL) 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 @return Returns the return-value of the command (if any - M T_Type::Null otherwise)85 @return Returns the return-value of the command (if any - MultiType::Null otherwise) 86 86 */ 87 87 /* static */ MultiType CommandExecutor::queryMT(const std::string& command, int* error, bool useTcl) … … 133 133 /* static */ std::string CommandExecutor::query(const std::string& command, int* error, bool useTcl) 134 134 { 135 return CommandExecutor::queryMT(command, error, useTcl).get String();135 return CommandExecutor::queryMT(command, error, useTcl).get<std::string>(); 136 136 } 137 137 -
code/trunk/src/libraries/core/command/ConsoleCommand.h
r9348 r9550 222 222 #include <stack> 223 223 #include <vector> 224 #include <boost/preprocessor/cat.hpp>225 #include <boost/preprocessor/facilities/expand.hpp>226 224 227 225 #include "util/VA_NARGS.h" -
code/trunk/src/libraries/core/command/Executor.cc
r8858 r9550 79 79 @param delimiter The delimiter that is used to separate the arguments in the string @a arguments 80 80 @param bPrintError If true, errors are printed to the console if the function couldn't be executed with the given arguments 81 @return Returns the return value of the function (or M T_Type::Null if there is no return value)81 @return Returns the return value of the function (or MultiType::Null if there is no return value) 82 82 */ 83 83 MultiType Executor::parse(const std::string& arguments, int* error, const std::string& delimiter, bool bPrintError) const … … 92 92 @param delimiter The delimiter that was used to separate the arguments in the SubString @a arguments (used to join the surplus arguments) 93 93 @param bPrintError If true, errors are printed to the console if the function couldn't be executed with the given arguments 94 @return Returns the return value of the function (or M T_Type::Null if there is no return value)94 @return Returns the return value of the function (or MultiType::Null if there is no return value) 95 95 */ 96 96 MultiType Executor::parse(const SubString& arguments, int* error, const std::string& delimiter, bool bPrintError) const … … 105 105 if (bPrintError) 106 106 orxout(internal_warning) << "Can't call executor " << this->name_ << " through parser: Not enough arguments or default values given (input: " << arguments.join() << ")." << endl; 107 return M T_Type::Null;107 return MultiType::Null; 108 108 } 109 109 -
code/trunk/src/libraries/core/command/Executor.h
r8858 r9550 169 169 return this->defaultValue_[index]; 170 170 171 return M T_Type::Null;171 return MultiType::Null; 172 172 } 173 173 -
code/trunk/src/libraries/core/command/Functor.h
r8858 r9550 189 189 virtual ~Functor() {} 190 190 191 /// 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; M T_Type::Null otherwise)192 virtual MultiType operator()(const MultiType& param1 = M T_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;191 /// 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) 192 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) = 0; 193 193 194 194 /// Creates a new instance of Functor with the same values like this (used instead of a copy-constructor) … … 245 245 virtual ~FunctorMember() { if (this->bSafeMode_) { this->unregisterObject(this->object_); } } 246 246 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; M T_Type::Null otherwise)248 virtual MultiType operator()(O* object, const MultiType& param1 = M T_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;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) 248 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 249 250 250 // see Functor::operator()() 251 MultiType operator()(const MultiType& param1 = M T_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null)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) 252 252 { 253 253 // call the function if an object was assigned … … 257 257 { 258 258 orxout(internal_error) << "Can't execute FunctorMember, no object set." << endl; 259 return M T_Type::Null;259 return MultiType::Null; 260 260 } 261 261 } … … 324 324 FunctorMember(void* object = 0) {} 325 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; M T_Type::Null otherwise)327 virtual MultiType operator()(void* object, const MultiType& param1 = M T_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;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) 327 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 328 329 329 // see Functor::operator()() 330 MultiType operator()(const MultiType& param1 = M T_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null)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 331 { 332 332 return (*this)((void*)0, param1, param2, param3, param4, param5); … … 416 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 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 M T_Type::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 M T_Type::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 M T_Type::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 M T_Type::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 M T_Type::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 M T_Type::Null; } };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 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 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); } }; … … 428 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 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 M T_Type::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 M T_Type::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 M T_Type::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 M T_Type::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 M T_Type::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 M T_Type::Null; } };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 436 437 437 // Helper class, used to identify the header of a function-pointer (independent of its class) … … 497 497 498 498 // see FunctorMember::operator()() 499 MultiType operator()(O* object, const MultiType& param1 = M T_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null)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 500 { 501 501 return detail::FunctorCaller<R, O, isconst, P1, P2, P3, P4, P5>::call(this->functionPointer_, object, param1, param2, param3, param4, param5); -
code/trunk/src/libraries/core/command/IOConsolePOSIX.cc
r8858 r9550 38 38 #include "util/Math.h" 39 39 #include "util/output/ConsoleWriter.h" 40 #include "util/output/OutputManager.h" 40 41 #include "core/Game.h" 41 42 #include "core/input/InputBuffer.h" … … 75 76 76 77 // Disable standard std::cout logging 77 ConsoleWriter::getInstance().disable();78 OutputManager::getInstance().getConsoleWriter()->disable(); 78 79 // Redirect std::cout to an ostringstream 79 80 // (Other part is in the initialiser list) … … 103 104 std::cout.rdbuf(this->cout_.rdbuf()); 104 105 // Enable standard std::cout logging again 105 ConsoleWriter::getInstance().enable();106 OutputManager::getInstance().getConsoleWriter()->enable(); 106 107 } 107 108 -
code/trunk/src/libraries/core/command/IOConsoleWindows.cc
r8858 r9550 35 35 #include "util/Math.h" 36 36 #include "util/output/ConsoleWriter.h" 37 #include "util/output/OutputManager.h" 37 38 #include "core/Game.h" 38 39 #include "core/input/InputBuffer.h" … … 53 54 { 54 55 // Disable standard this->cout_ logging 55 ConsoleWriter::getInstance().disable();56 OutputManager::getInstance().getConsoleWriter()->disable(); 56 57 // Redirect std::cout to an ostringstream 57 58 // (Other part is in the initialiser list) … … 109 110 std::cout.rdbuf(this->cout_.rdbuf()); 110 111 // Enable standard this->cout_ logging again 111 ConsoleWriter::getInstance().enable();112 OutputManager::getInstance().getConsoleWriter()->enable(); 112 113 113 114 resetTerminalMode(); -
code/trunk/src/libraries/core/command/Shell.cc
r8858 r9550 88 88 89 89 // Get the previous output and add it to the Shell 90 MemoryWriter::getInstance().resendOutput(this);90 OutputManager::getInstance().getMemoryWriter()->resendOutput(this); 91 91 } 92 92 … … 170 170 { 171 171 OutputLevel level = (value ? DefaultLogLevel::Dev : DefaultLogLevel::User); 172 ModifyConfigValueExternal(this->configurableMaxLevel_, this->getConfigurableMaxLevelName(), tset, level);172 ModifyConfigValueExternal(this->configurableMaxLevel_, this->getConfigurableMaxLevelName(), tset, static_cast<int>(level)); 173 173 } 174 174 } -
code/trunk/src/libraries/core/command/TclBind.cc
r8858 r9550 183 183 184 184 if (bQuery) 185 result = evaluation.query(&error).get String();185 result = evaluation.query(&error).get<std::string>(); 186 186 else 187 187 error = evaluation.execute(); -
code/trunk/src/libraries/core/input/InputManager.cc
r8858 r9550 176 176 if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen()) 177 177 { 178 if (CommandLineParser::getValue("keyboard_no_grab").get Bool())178 if (CommandLineParser::getValue("keyboard_no_grab").get<bool>()) 179 179 paramList.insert(StringPair("x11_keyboard_grab", "false")); 180 180 else -
code/trunk/src/libraries/network/Client.cc
r8858 r9550 68 68 timeSinceLastUpdate_(0) 69 69 { 70 this->setDestination( CommandLineParser::getValue("dest").get String(), CommandLineParser::getValue("port") );70 this->setDestination( CommandLineParser::getValue("dest").get<std::string>(), CommandLineParser::getValue("port") ); 71 71 } 72 72 -
code/trunk/src/libraries/tools/Shader.cc
r8858 r9550 161 161 void Shader::setParameter(size_t technique, size_t pass, const std::string& parameter, int value) 162 162 { 163 ParameterContainer container = {technique, pass, parameter, value , 0.0f, MT_Type::Int};163 ParameterContainer container = {technique, pass, parameter, value}; 164 164 this->parameters_.push_back(container); 165 165 this->addAsListener(); … … 171 171 void Shader::setParameter(size_t technique, size_t pass, const std::string& parameter, float value) 172 172 { 173 ParameterContainer container = {technique, pass, parameter, 0, value, MT_Type::Float};173 ParameterContainer container = {technique, pass, parameter, value}; 174 174 this->parameters_.push_back(container); 175 175 this->addAsListener(); … … 204 204 { 205 205 // change the value of the parameter depending on its type 206 switch (it->valueType_) 207 { 208 case MT_Type::Int: 209 passPtr->getFragmentProgramParameters()->setNamedConstant(it->parameter_, it->valueInt_); 210 break; 211 case MT_Type::Float: 212 passPtr->getFragmentProgramParameters()->setNamedConstant(it->parameter_, it->valueFloat_); 213 break; 214 default: 215 break; 216 } 206 if (it->value_.isType<int>()) 207 passPtr->getFragmentProgramParameters()->setNamedConstant(it->parameter_, it->value_.get<int>()); 208 else if (it->value_.isType<float>()) 209 passPtr->getFragmentProgramParameters()->setNamedConstant(it->parameter_, it->value_.get<float>()); 217 210 } 218 211 else -
code/trunk/src/libraries/tools/Shader.h
r8729 r9550 114 114 std::string parameter_; ///< The name of the parameter 115 115 116 int valueInt_; ///< The desired int value of the parameter 117 float valueFloat_; ///< The desired float value of the parameter 118 119 MT_Type::Value valueType_; ///< The type of the parameter (currently only int or float) 116 MultiType value_; ///< The desired value of the parameter 120 117 }; 121 118 -
code/trunk/src/libraries/util/Math.h
r8729 r9550 139 139 { 140 140 return x*x*x; 141 }142 143 /**144 @brief Rounds the value to the nearest integer.145 */146 template <typename T>147 inline int round(T x)148 {149 return static_cast<int>(x + 0.5);150 141 } 151 142 … … 247 238 inline T interpolate(float time, const T& start, const T& end) 248 239 { 249 return time * (end - start) + start;240 return static_cast<T>(time * (end - start) + start); 250 241 } 251 242 … … 260 251 inline T interpolateSmooth(float time, const T& start, const T& end) 261 252 { 262 return (-2 * (end - start) * cube(time)) + (3 * (end - start) * square(time)) + start;253 return static_cast<T>((-2 * (end - start) * cube(time)) + (3 * (end - start) * square(time)) + start); 263 254 } 264 255 -
code/trunk/src/libraries/util/MultiType.cc
r7401 r9550 37 37 namespace orxonox 38 38 { 39 const MultiType MultiType::Null; 40 39 41 /** 40 42 @brief Converts the current value of the MultiType to a new type. 41 43 @param type The type 42 44 */ 43 bool MultiType::convert( MT_Type::Valuetype)45 bool MultiType::convert(Type::Enum type) 44 46 { 45 47 switch (type) 46 48 { 47 case MT_Type::Null:49 case Type::Null: 48 50 this->reset(); return true; 49 case MT_Type::Char:51 case Type::Char: 50 52 return this->convert<char>(); break; 51 case MT_Type::UnsignedChar:53 case Type::UnsignedChar: 52 54 return this->convert<unsigned char>(); break; 53 case MT_Type::Short:55 case Type::Short: 54 56 return this->convert<short>(); break; 55 case MT_Type::UnsignedShort:57 case Type::UnsignedShort: 56 58 return this->convert<unsigned short>(); break; 57 case MT_Type::Int:59 case Type::Int: 58 60 return this->convert<int>(); break; 59 case MT_Type::UnsignedInt:61 case Type::UnsignedInt: 60 62 return this->convert<unsigned int>(); break; 61 case MT_Type::Long:63 case Type::Long: 62 64 return this->convert<long>(); break; 63 case MT_Type::UnsignedLong:65 case Type::UnsignedLong: 64 66 return this->convert<unsigned long>(); break; 65 case MT_Type::LongLong:67 case Type::LongLong: 66 68 return this->convert<long long>(); break; 67 case MT_Type::UnsignedLongLong:69 case Type::UnsignedLongLong: 68 70 return this->convert<unsigned long long>(); break; 69 case MT_Type::Float:71 case Type::Float: 70 72 return this->convert<float>(); break; 71 case MT_Type::Double:73 case Type::Double: 72 74 return this->convert<double>(); break; 73 case MT_Type::LongDouble:75 case Type::LongDouble: 74 76 return this->convert<long double>(); break; 75 case MT_Type::Bool:77 case Type::Bool: 76 78 return this->convert<bool>(); break; 77 case MT_Type::VoidPointer:79 case Type::VoidPointer: 78 80 return this->convert<void*>(); break; 79 case MT_Type::String:81 case Type::String: 80 82 return this->convert<std::string>(); break; 81 case MT_Type::Vector2:83 case Type::Vector2: 82 84 return this->convert<orxonox::Vector2>(); break; 83 case MT_Type::Vector3:85 case Type::Vector3: 84 86 return this->convert<orxonox::Vector3>(); break; 85 case MT_Type::Vector4:87 case Type::Vector4: 86 88 return this->convert<orxonox::Vector4>(); break; 87 case MT_Type::ColourValue:89 case Type::ColourValue: 88 90 return this->convert<orxonox::ColourValue>(); break; 89 case MT_Type::Quaternion:91 case Type::Quaternion: 90 92 return this->convert<orxonox::Quaternion>(); break; 91 case MT_Type::Radian:93 case Type::Radian: 92 94 return this->convert<orxonox::Radian>(); break; 93 case MT_Type::Degree:95 case Type::Degree: 94 96 return this->convert<orxonox::Degree>(); break; 95 97 default: … … 104 106 std::string MultiType::getTypename() const 105 107 { 106 MT_Type::Value type = (this->value_) ? this->value_->type_ : MT_Type::Null;108 Type::Enum type = (this->value_) ? this->value_->type_ : Type::Null; 107 109 108 110 switch (type) 109 111 { 110 case MT_Type::Char:112 case Type::Char: 111 113 return "char"; break; 112 case MT_Type::UnsignedChar:114 case Type::UnsignedChar: 113 115 return "unsigned char"; break; 114 case MT_Type::Short:116 case Type::Short: 115 117 return "short"; break; 116 case MT_Type::UnsignedShort:118 case Type::UnsignedShort: 117 119 return "unsigned short"; break; 118 case MT_Type::Int:120 case Type::Int: 119 121 return "int"; break; 120 case MT_Type::UnsignedInt:122 case Type::UnsignedInt: 121 123 return "unsigned int"; break; 122 case MT_Type::Long:124 case Type::Long: 123 125 return "long"; break; 124 case MT_Type::UnsignedLong:126 case Type::UnsignedLong: 125 127 return "unsigned long"; break; 126 case MT_Type::LongLong:128 case Type::LongLong: 127 129 return "long long"; break; 128 case MT_Type::UnsignedLongLong:130 case Type::UnsignedLongLong: 129 131 return "unsigned long long"; break; 130 case MT_Type::Float:132 case Type::Float: 131 133 return "float"; break; 132 case MT_Type::Double:134 case Type::Double: 133 135 return "double"; break; 134 case MT_Type::LongDouble:136 case Type::LongDouble: 135 137 return "long double"; break; 136 case MT_Type::Bool:138 case Type::Bool: 137 139 return "bool"; break; 138 case MT_Type::VoidPointer:140 case Type::VoidPointer: 139 141 return "void*"; break; 140 case MT_Type::String:142 case Type::String: 141 143 return "std::string"; break; 142 case MT_Type::Vector2:144 case Type::Vector2: 143 145 return "orxonox::Vector2"; break; 144 case MT_Type::Vector3:146 case Type::Vector3: 145 147 return "orxonox::Vector3"; break; 146 case MT_Type::Vector4:148 case Type::Vector4: 147 149 return "orxonox::Vector4"; break; 148 case MT_Type::ColourValue:150 case Type::ColourValue: 149 151 return "orxonox::ColourValue"; break; 150 case MT_Type::Quaternion:152 case Type::Quaternion: 151 153 return "orxonox::Quaternion"; break; 152 case MT_Type::Radian:154 case Type::Radian: 153 155 return "orxonox::Radian"; break; 154 case MT_Type::Degree:156 case Type::Degree: 155 157 return "orxonox::Degree"; break; 156 158 default: … … 159 161 } 160 162 161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Char ) ? (static_cast<MT_Value<char> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 162 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedChar ) ? (static_cast<MT_Value<unsigned char> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 163 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Short ) ? (static_cast<MT_Value<short> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 164 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedShort ) ? (static_cast<MT_Value<unsigned short> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 165 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Int ) ? (static_cast<MT_Value<int> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 166 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedInt ) ? (static_cast<MT_Value<unsigned int> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 167 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Long ) ? (static_cast<MT_Value<long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 168 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLong ) ? (static_cast<MT_Value<unsigned long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 169 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongLong ) ? (static_cast<MT_Value<long long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 170 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLongLong) ? (static_cast<MT_Value<unsigned long long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 171 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Float ) ? (static_cast<MT_Value<float> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 172 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Double ) ? (static_cast<MT_Value<double> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 173 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongDouble ) ? (static_cast<MT_Value<long double> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 174 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Bool ) ? (static_cast<MT_Value<bool> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 175 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_Type::VoidPointer ) ? (static_cast<MT_Value<void*> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 176 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_Type::String ) ? (static_cast<MT_Value<std::string> *>(this->value_))->value_ : (*this->value_)) : NilValue<std::string>(); } ///< Returns the current value, converted to the requested type. 177 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector2 ) ? (static_cast<MT_Value<orxonox::Vector2> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector2>(); } ///< Returns the current value, converted to the requested type. 178 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector3 ) ? (static_cast<MT_Value<orxonox::Vector3> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector3>(); } ///< Returns the current value, converted to the requested type. 179 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector4 ) ? (static_cast<MT_Value<orxonox::Vector4> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector4>(); } ///< Returns the current value, converted to the requested type. 180 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_Type::ColourValue ) ? (static_cast<MT_Value<orxonox::ColourValue>*>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::ColourValue>(); } ///< Returns the current value, converted to the requested type. 181 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Quaternion ) ? (static_cast<MT_Value<orxonox::Quaternion> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Quaternion>(); } ///< Returns the current value, converted to the requested type. 182 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Radian ) ? (static_cast<MT_Value<orxonox::Radian> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Radian>(); } ///< Returns the current value, converted to the requested type. 183 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Degree ) ? (static_cast<MT_Value<orxonox::Degree> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Degree>(); } ///< Returns the current value, converted to the requested type. 184 185 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_Type::Char ); } ///< Creates a new value container for the given type. 186 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_Type::UnsignedChar ); } ///< Creates a new value container for the given type. 187 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_Type::Short ); } ///< Creates a new value container for the given type. 188 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_Type::UnsignedShort ); } ///< Creates a new value container for the given type. 189 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_Type::Int ); } ///< Creates a new value container for the given type. 190 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_Type::UnsignedInt ); } ///< Creates a new value container for the given type. 191 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_Type::Long ); } ///< Creates a new value container for the given type. 192 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_Type::UnsignedLong ); } ///< Creates a new value container for the given type. 193 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_Type::LongLong ); } ///< Creates a new value container for the given type. 194 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_Type::UnsignedLongLong); } ///< Creates a new value container for the given type. 195 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_Type::Float ); } ///< Creates a new value container for the given type. 196 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_Type::Double ); } ///< Creates a new value container for the given type. 197 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_Type::LongDouble ); } ///< Creates a new value container for the given type. 198 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_Type::Bool ); } ///< Creates a new value container for the given type. 199 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_Type::VoidPointer ); } ///< Creates a new value container for the given type. 200 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_Type::String ); } ///< Creates a new value container for the given type. 201 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_Type::Vector2 ); } ///< Creates a new value container for the given type. 202 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_Type::Vector3 ); } ///< Creates a new value container for the given type. 203 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_Type::Vector4 ); } ///< Creates a new value container for the given type. 204 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_Type::ColourValue ); } ///< Creates a new value container for the given type. 205 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_Type::Quaternion ); } ///< Creates a new value container for the given type. 206 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_Type::Radian ); } ///< Creates a new value container for the given type. 207 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_Type::Degree ); } ///< Creates a new value container for the given type. 163 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, Type::Char ); } 164 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, Type::UnsignedChar ); } 165 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, Type::Short ); } 166 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, Type::UnsignedShort ); } 167 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, Type::Int ); } 168 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, Type::UnsignedInt ); } 169 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, Type::Long ); } 170 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, Type::UnsignedLong ); } 171 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, Type::LongLong ); } 172 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, Type::UnsignedLongLong); } 173 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, Type::Float ); } 174 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, Type::Double ); } 175 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, Type::LongDouble ); } 176 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, Type::Bool ); } 177 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, Type::VoidPointer ); } 178 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, Type::String ); } 179 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, Type::Vector2 ); } 180 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, Type::Vector3 ); } 181 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, Type::Vector4 ); } 182 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, Type::ColourValue ); } 183 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, Type::Quaternion ); } 184 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, Type::Radian ); } 185 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, Type::Degree ); } 208 186 } -
code/trunk/src/libraries/util/MultiType.h
r8858 r9550 51 51 - @ref orxonox::MultiType::MultiType "The constructor" 52 52 - The assignment operator= (orxonox::MultiType::operator=()) 53 - @ref orxonox::MultiType::set Value() "setValue(value)"53 - @ref orxonox::MultiType::set() "set(value)" 54 54 55 55 If you assign another value of another type, the MultiType keeps "its" type and … … 58 58 If you want to change the type, there are three possibilities: 59 59 - @ref orxonox::MultiType::convert "convert<T>()" sets the type to T and converts the currently assigned value 60 - @ref orxonox::MultiType:: setType "setType<T>()" sets the type to T and resets the value to zero using zeroise<T>()61 - setValue<T>(value) assigns a new value and changes the type to T.60 - @ref orxonox::MultiType::reset "reset<T>()" sets the type to T and resets the value to zero using zeroise<T>() 61 - force<T>(value) assigns a new value and changes the type to T. 62 62 63 63 Examples: 64 64 @code 65 MultiType a = 10; 66 a.set Value("3.14");// a has still the type int and "3.14" gets converted, therefore the value is now 367 a. setValue<float>("3.14"); // a has now the type float and "3.14" gets converted to 3.14f68 a.convert<bool>(); 69 a = false; 65 MultiType a = 10; // a has now the type int and the value 10 66 a.set("3.14"); // a has still the type int and "3.14" gets converted, therefore the value is now 3 67 a.force<float>("3.14"); // a has now the type float and "3.14" gets converted to 3.14f 68 a.convert<bool>(); // converts 3.14f to bool, which is true 69 a = false; // assigns false, this is equivalent to a.setValue(false) 70 70 @endcode 71 71 … … 106 106 #include <OgreColourValue.h> 107 107 #include <loki/TypeTraits.h> 108 #include "Math.h" 108 109 #include "mbool.h" 109 110 110 111 namespace orxonox 111 112 { 112 /**113 @brief Enum of all possible types of a MultiType.114 */115 namespace MT_Type116 {117 enum Value118 {119 Null,120 Char,121 UnsignedChar,122 Short,123 UnsignedShort,124 Int,125 UnsignedInt,126 Long,127 UnsignedLong,128 LongLong,129 UnsignedLongLong,130 Float,131 Double,132 LongDouble,133 Bool,134 VoidPointer,135 String,136 Vector2,137 Vector3,138 Vector4,139 ColourValue,140 Quaternion,141 Radian,142 Degree143 };144 }145 146 113 /** 147 114 @brief The MultiType can hold a value of many possible types and convert them to other types. … … 165 132 template <typename T> friend class MT_Value; 166 133 134 struct Type 135 { 136 /** 137 @brief Enum of all possible types of a MultiType. 138 */ 139 enum Enum 140 { 141 Null, 142 Char, 143 UnsignedChar, 144 Short, 145 UnsignedShort, 146 Int, 147 UnsignedInt, 148 Long, 149 UnsignedLong, 150 LongLong, 151 UnsignedLongLong, 152 Float, 153 Double, 154 LongDouble, 155 Bool, 156 VoidPointer, 157 String, 158 Vector2, 159 Vector3, 160 Vector4, 161 ColourValue, 162 Quaternion, 163 Radian, 164 Degree 165 }; 166 }; 167 167 168 public: 168 169 /** … … 173 174 { 174 175 public: 175 MT_ValueBase(MT_Type::Value type) : type_(type), bHasDefaultValue_(false) {}176 virtual ~MT_ValueBase() {}176 inline MT_ValueBase(void* data, Type::Enum type) : type_(type), bLastConversionSuccessful(true), data_(data) {} 177 inline virtual ~MT_ValueBase() {} 177 178 178 179 virtual MT_ValueBase* clone() const = 0; 179 180 180 181 virtual void reset() = 0; 181 virtual bool assimilate(const MultiType& other) = 0;182 182 183 183 /// Returns the type of the current value. 184 const MT_Type::Value& getType() const { return this->type_; } 184 inline const Type::Enum& getType() const { return this->type_; } 185 /// Returns true if the type of the stored value is T. 186 template <typename T> inline bool isType() const { return false; } 185 187 186 188 /// Checks whether the value is a default one. 187 bool hasDefaultValue() const { return this->bHasDefaultValue_; }189 inline bool lastConversionSuccessful() const { return this->bLastConversionSuccessful; } 188 190 189 191 virtual bool setValue(const char& value) = 0; … … 211 213 virtual bool setValue(const orxonox::Degree& value) = 0; 212 214 215 virtual bool setValue(const MultiType& other) = 0; 216 213 217 virtual bool getValue(char* value) const = 0; 214 218 virtual bool getValue(unsigned char* value) const = 0; … … 235 239 virtual bool getValue(orxonox::Degree* value) const = 0; 236 240 237 virtual operator char() const = 0; 238 virtual operator unsigned char() const = 0; 239 virtual operator short() const = 0; 240 virtual operator unsigned short() const = 0; 241 virtual operator int() const = 0; 242 virtual operator unsigned int() const = 0; 243 virtual operator long() const = 0; 244 virtual operator unsigned long() const = 0; 245 virtual operator long long() const = 0; 246 virtual operator unsigned long long() const = 0; 247 virtual operator float() const = 0; 248 virtual operator double() const = 0; 249 virtual operator long double() const = 0; 250 virtual operator bool() const = 0; 251 virtual operator void*() const = 0; 252 virtual operator std::string() const = 0; 253 virtual operator orxonox::Vector2() const = 0; 254 virtual operator orxonox::Vector3() const = 0; 255 virtual operator orxonox::Vector4() const = 0; 256 virtual operator orxonox::ColourValue() const = 0; 257 virtual operator orxonox::Quaternion() const = 0; 258 virtual operator orxonox::Radian() const = 0; 259 virtual operator orxonox::Degree() const = 0; 241 template <typename T> T get() const 242 { 243 if (this->isType<T>()) 244 return *reinterpret_cast<const T*>(this->data_); 245 else 246 { 247 T value; 248 this->getValue(&value); 249 return value; 250 } 251 } 260 252 261 253 virtual void toString(std::ostream& outstream) const = 0; 262 254 263 virtual void importData( uint8_t*& mem )=0; 264 virtual void exportData( uint8_t*& mem ) const=0; 265 virtual uint8_t getSize() const=0; 266 267 MT_Type::Value type_; ///< The type of the current value 268 bool bHasDefaultValue_; ///< True if the last conversion wasn't successful 255 virtual void importData(uint8_t*& mem) = 0; 256 virtual void exportData(uint8_t*& mem) const = 0; 257 virtual uint8_t getSize() const = 0; 258 259 Type::Enum type_; ///< The type of the current value 260 bool bLastConversionSuccessful; ///< True if the last conversion was successful 261 void* data_; ///< For direct access to the value if the type is known 269 262 }; 270 263 271 264 public: 272 inline MultiType() : value_(0) {} ///< Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value. 273 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 274 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 275 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 276 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 277 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 278 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 279 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 280 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 281 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 282 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 283 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 284 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 285 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 286 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 287 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 288 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 289 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 290 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 291 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 292 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 293 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 294 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 295 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 296 inline MultiType(const orxonox::mbool& value) : value_(0) { this->assignValue((bool)value); } ///< Constructor: Assigns the given mbool and converts it to bool. 297 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } ///< Constructor: Converts the char array to a std::string, assigns the value and sets the type. 298 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } ///< Copyconstructor: Assigns value and type of the other MultiType. 299 inline MultiType(MT_Type::Value type) : value_(0) { this->setType(type); } ///< Constructor: Sets the type, the next assignment will determine the value. 265 static const MultiType Null; 266 267 /// Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value. 268 inline MultiType() : value_(0) { } 269 /// Constructor: Assigns the given value and sets the type. 270 template <typename V> 271 inline MultiType(const V& value) : value_(0) { this->set(value); } 272 /// Copyconstructor: Assigns value and type of the other MultiType. 273 inline MultiType(const MultiType& other) : value_(0) { this->set(other); } 300 274 301 275 /// Destructor: Deletes the MT_Value. 302 276 inline ~MultiType() { if (this->value_) { delete this->value_; } } 303 277 304 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } ///< Assigns a new value. The value will be converted to the current type of the MultiType. 305 template <typename V> inline MultiType& operator=(V* value) { this->setValue(value); return (*this); } ///< Assigns a pointer. 306 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } ///< Assigns the value of the other MultiType and converts it to the current type of the MultiType. 307 inline MultiType& operator=(MT_Type::Value type) { this->setType(type); return (*this); } ///< Resets the value and changes the type. 308 309 inline bool setValue(const char& value); 310 inline bool setValue(const unsigned char& value); 311 inline bool setValue(const short& value); 312 inline bool setValue(const unsigned short& value); 313 inline bool setValue(const int& value); 314 inline bool setValue(const unsigned int& value); 315 inline bool setValue(const long& value); 316 inline bool setValue(const unsigned long& value); 317 inline bool setValue(const long long& value); 318 inline bool setValue(const unsigned long long& value); 319 inline bool setValue(const float& value); 320 inline bool setValue(const double& value); 321 inline bool setValue(const long double& value); 322 inline bool setValue(const bool& value); 323 inline bool setValue( void* const& value); 324 inline bool setValue(const std::string& value); 325 inline bool setValue(const orxonox::Vector2& value); 326 inline bool setValue(const orxonox::Vector3& value); 327 inline bool setValue(const orxonox::Vector4& value); 328 inline bool setValue(const orxonox::ColourValue& value); 329 inline bool setValue(const orxonox::Quaternion& value); 330 inline bool setValue(const orxonox::Radian& value); 331 inline bool setValue(const orxonox::Degree& value); 332 inline bool setValue(const char* value); 278 /// Assigns a new value. The value will be converted to the current type of the MultiType. 279 template <typename V> inline MultiType& operator=(const V& value) { this->set(value); return (*this); } 333 280 /// Assigns a pointer. 334 template <typename V> inline bool setValue(V* value) 281 template <typename V> inline MultiType& operator=(V* value) { this->set(value); return (*this); } 282 /// Assigns the value of the other MultiType and converts it to the current type of the MultiType. 283 inline MultiType& operator=(const MultiType& other) { this->set(other); return (*this); } 284 285 /// Assigns the given value and converts it to the current type. 286 template <typename V> inline bool set(const V& value) 287 { 288 if (this->value_) 289 return this->value_->setValue(value); 290 291 this->assignValue(value); 292 return true; 293 } 294 /// Assigns a pointer. 295 template <typename V> inline bool set(V* value) 335 296 { 336 297 if (this->value_) 337 298 return this->value_->setValue(static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 338 else 339 return this->assignValue (static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 299 300 this->assignValue(static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 301 return true; 340 302 } 341 303 /// Assigns the value of the other MultiType and converts it to the current type. 342 bool setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } } 304 inline bool set(const MultiType& other) 305 { 306 if (this->value_) 307 return this->value_->setValue(other); 308 else if (other.value_) 309 this->value_ = other.value_->clone(); 310 return true; 311 } 312 343 313 /// Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). 344 template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); } 345 314 template <typename T, typename V> inline bool force(const V& value) 315 { 316 this->reset<T>(); 317 return this->set(value); 318 } 346 319 347 320 /// Copies the other MultiType by assigning value and type. 348 inline void copy(const MultiType& other) { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 321 inline void copy(const MultiType& other) 322 { 323 if (this == &other) 324 return; 325 if (this->value_) 326 delete this->value_; 327 this->value_ = (other.value_) ? other.value_->clone() : 0; 328 } 349 329 350 330 /// Converts the current value to type T. 351 template <typename T> inline bool convert() { return this->setValue<T>((typename Loki::TypeTraits<T>::UnqualifiedReferredType)(*this)); } 352 /// Converts the current value to the type of the other MultiType. 353 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } 354 bool convert(MT_Type::Value type); 355 356 /// Current content gets deleted. New type is MT_Type::Null 357 inline void reset() { if (this->value_) delete this->value_; this->value_ = 0; } 358 /// Current content gets overridden with default zero value 359 inline void resetValue() { if (this->value_) this->value_->reset(); } 360 331 template <typename T> inline bool convert() { return this->force<T>(MultiType(*this)); } 332 333 /// Resets value and type. Type will be void afterwards and null() returns true. 334 inline void reset() { if (this->value_) delete this->value_; this->value_ = 0; } 361 335 /// Resets the value and changes the internal type to T. 362 template <typename T> inline void setType() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } 363 /// Resets the value and changes the internal type to the type of the other MultiType. 364 inline void setType(const MultiType& other) { this->setType(other.getType()); } 365 /// Resets the value and changes the internal type to the given type. 366 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } 367 368 /// Returns the current type. 369 inline MT_Type::Value getType() const { return (this->value_) ? this->value_->type_ : MT_Type::Null; } 370 /// Returns true if the current type equals the given type. 371 inline bool isType(MT_Type::Value type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_Type::Null); } 372 /// Returns true if the current type is T. 373 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 374 std::string getTypename() const; 375 376 /// Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT 377 inline void exportData(uint8_t*& mem) const { assert(sizeof(MT_Type::Value)<=8); *static_cast<uint8_t*>(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->exportData(mem); } 378 /// Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT 379 inline void importData(uint8_t*& mem) { assert(sizeof(MT_Type::Value)<=8); this->setType(static_cast<MT_Type::Value>(*static_cast<uint8_t*>(mem))); mem+=sizeof(uint8_t); this->value_->importData(mem); } 380 /// Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT 381 inline uint8_t*& operator << (uint8_t*& mem) { importData(mem); return mem; } 382 /// Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT 383 inline void operator >> (uint8_t*& mem) const { exportData(mem); } 384 inline uint32_t getNetworkSize() const { assert(this->value_); return this->value_->getSize() + sizeof(uint8_t); } 385 386 /// Checks whether the value is a default one (assigned after a failed conversion) 387 bool hasDefaultValue() const { return this->value_->hasDefaultValue(); } 336 template <typename T> inline void reset() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } 337 /// Current value gets overridden with default zero value 338 inline void resetValue() { if (this->value_) this->value_->reset(); } 339 340 /// Returns true if the type of the current value is T. 341 template <typename T> inline bool isType() const { return (this->value_ ? this->value_->isType<T>() : false); } 342 std::string getTypename() const; 343 344 /// Checks whether the last conversion was successful 345 inline bool lastConversionSuccessful() const { return !this->value_ || this->value_->lastConversionSuccessful(); } 388 346 389 347 /// Checks if the MT contains no value. 390 bool null() const { return (!this->value_); }391 392 operator char() const;393 operator unsigned char() const;394 operator short() const;395 operator unsigned short() const;396 operator int() const;397 operator unsigned int() const;398 operator long() const;399 operator unsigned long() const;400 operator long long() const;401 operator unsigned long long() const;402 operator float() const;403 operator double() const;404 operator long double() const;405 operator bool() const;406 operator void*() const;407 operator std::string() const;408 operator orxonox::Vector2() const;409 operator orxonox::Vector3() const;410 operator orxonox::Vector4() const;411 operator orxonox::ColourValue() const;412 operator orxonox::Quaternion() const;413 operator orxonox::Radian() const;414 operator orxonox::Degree() const;348 inline bool null() const { return !this->value_; } 349 350 inline operator char() const { return (this->value_ ? this->value_->get<char>() : 0); } 351 inline operator unsigned char() const { return (this->value_ ? this->value_->get<unsigned char>() : 0); } 352 inline operator short() const { return (this->value_ ? this->value_->get<short>() : 0); } 353 inline operator unsigned short() const { return (this->value_ ? this->value_->get<unsigned short>() : 0); } 354 inline operator int() const { return (this->value_ ? this->value_->get<int>() : 0); } 355 inline operator unsigned int() const { return (this->value_ ? this->value_->get<unsigned int>() : 0); } 356 inline operator long() const { return (this->value_ ? this->value_->get<long>() : 0); } 357 inline operator unsigned long() const { return (this->value_ ? this->value_->get<unsigned long>() : 0); } 358 inline operator long long() const { return (this->value_ ? this->value_->get<long long>() : 0); } 359 inline operator unsigned long long() const { return (this->value_ ? this->value_->get<unsigned long long>() : 0); } 360 inline operator float() const { return (this->value_ ? this->value_->get<float>() : 0); } 361 inline operator double() const { return (this->value_ ? this->value_->get<double>() : 0); } 362 inline operator long double() const { return (this->value_ ? this->value_->get<long double>() : 0); } 363 inline operator bool() const { return (this->value_ ? this->value_->get<bool>() : 0); } 364 inline operator void*() const { return (this->value_ ? this->value_->get<void*>() : 0); } 365 inline operator std::string() const { return (this->value_ ? this->value_->get<std::string>() : NilValue<std::string>()); } 366 inline operator orxonox::Vector2() const { return (this->value_ ? this->value_->get<orxonox::Vector2>() : NilValue<orxonox::Vector2>()); } 367 inline operator orxonox::Vector3() const { return (this->value_ ? this->value_->get<orxonox::Vector3>() : NilValue<orxonox::Vector3>()); } 368 inline operator orxonox::Vector4() const { return (this->value_ ? this->value_->get<orxonox::Vector4>() : NilValue<orxonox::Vector4>()); } 369 inline operator orxonox::ColourValue() const { return (this->value_ ? this->value_->get<orxonox::ColourValue>() : NilValue<orxonox::ColourValue>()); } 370 inline operator orxonox::Quaternion() const { return (this->value_ ? this->value_->get<orxonox::Quaternion>() : NilValue<orxonox::Quaternion>()); } 371 inline operator orxonox::Radian() const { return (this->value_ ? this->value_->get<orxonox::Radian>() : NilValue<orxonox::Radian>()); } 372 inline operator orxonox::Degree() const { return (this->value_ ? this->value_->get<orxonox::Degree>() : NilValue<orxonox::Degree>()); } 415 373 /// Returns the current value, converted to a T* pointer. 416 374 template <class T> operator T*() const { return (static_cast<T*>(this->operator void*())); } 417 375 418 inline bool getValue(char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 419 inline bool getValue(unsigned char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 420 inline bool getValue(short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 421 inline bool getValue(unsigned short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 422 inline bool getValue(int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 423 inline bool getValue(unsigned int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 424 inline bool getValue(long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 425 inline bool getValue(unsigned long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 426 inline bool getValue(long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 427 inline bool getValue(unsigned long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 428 inline bool getValue(float* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 429 inline bool getValue(double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 430 inline bool getValue(long double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 431 inline bool getValue(bool* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 432 inline bool getValue(void** value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 433 inline bool getValue(std::string* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 434 inline bool getValue(orxonox::Vector2* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 435 inline bool getValue(orxonox::Vector3* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 436 inline bool getValue(orxonox::Vector4* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 437 inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 438 inline bool getValue(orxonox::Quaternion* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 439 inline bool getValue(orxonox::Radian* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 440 inline bool getValue(orxonox::Degree* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 441 442 inline char getChar() const { return this->operator char(); } ///< Returns the current value, converted to the requested type. 443 inline unsigned char getUnsignedChar() const { return this->operator unsigned char(); } ///< Returns the current value, converted to the requested type. 444 inline short getShort() const { return this->operator short(); } ///< Returns the current value, converted to the requested type. 445 inline unsigned short getUnsignedShort() const { return this->operator unsigned short(); } ///< Returns the current value, converted to the requested type. 446 inline int getInt() const { return this->operator int(); } ///< Returns the current value, converted to the requested type. 447 inline unsigned int getUnsignedInt() const { return this->operator unsigned int(); } ///< Returns the current value, converted to the requested type. 448 inline long getLong() const { return this->operator long(); } ///< Returns the current value, converted to the requested type. 449 inline unsigned long getUnsignedLong() const { return this->operator unsigned long(); } ///< Returns the current value, converted to the requested type. 450 inline long long getLongLong() const { return this->operator long long(); } ///< Returns the current value, converted to the requested type. 451 inline unsigned long long getUnsignedLongLong() const { return this->operator unsigned long long(); } ///< Returns the current value, converted to the requested type. 452 inline float getFloat() const { return this->operator float(); } ///< Returns the current value, converted to the requested type. 453 inline double getDouble() const { return this->operator double(); } ///< Returns the current value, converted to the requested type. 454 inline long double getLongDouble() const { return this->operator long double(); } ///< Returns the current value, converted to the requested type. 455 inline bool getBool() const { return this->operator bool(); } ///< Returns the current value, converted to the requested type. 456 inline void* getVoid() const { return this->operator void*(); } ///< Returns the current value, converted to the requested type. 457 inline std::string getString() const { return this->operator std::string(); } ///< Returns the current value, converted to the requested type. 458 inline orxonox::Vector2 getVector2() const { return this->operator orxonox::Vector2(); } ///< Returns the current value, converted to the requested type. 459 inline orxonox::Vector3 getVector3() const { return this->operator orxonox::Vector3(); } ///< Returns the current value, converted to the requested type. 460 inline orxonox::Vector4 getVector4() const { return this->operator orxonox::Vector4(); } ///< Returns the current value, converted to the requested type. 461 inline orxonox::ColourValue getColourValue() const { return this->operator orxonox::ColourValue(); } ///< Returns the current value, converted to the requested type. 462 inline orxonox::Quaternion getQuaternion() const { return this->operator orxonox::Quaternion(); } ///< Returns the current value, converted to the requested type. 463 inline orxonox::Radian getRadian() const { return this->operator orxonox::Radian(); } ///< Returns the current value, converted to the requested type. 464 inline orxonox::Degree getDegree() const { return this->operator orxonox::Degree(); } ///< Returns the current value, converted to the requested type. 465 template <typename T> inline T* getPointer() const { return static_cast<T*>(this->getVoid()); } ///< Returns the current value, converted to a T* pointer. 376 /// Assigns the value to the given pointer. The value gets converted if the types don't match. 377 template <typename T> inline bool getValue(T* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } 378 379 /// Returns the current value, converted to the requested type. 380 template <typename T> inline T get() const { return *this; } 381 382 383 /////////////////////////////// 384 // network-related functions // 385 /////////////////////////////// 386 /// Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT 387 inline void exportData(uint8_t*& mem) const 388 { 389 assert(sizeof(Type::Enum) <= 8); 390 *static_cast<uint8_t*>(mem) = this->getType(); 391 mem += sizeof(uint8_t); 392 this->value_->exportData(mem); 393 } 394 /// Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT 395 inline void importData(uint8_t*& mem) 396 { 397 assert(sizeof(Type::Enum) <= 8); 398 this->setType(static_cast<Type::Enum>(*static_cast<uint8_t*>(mem))); 399 mem += sizeof(uint8_t); 400 this->value_->importData(mem); 401 } 402 /// Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT 403 inline uint8_t*& operator<<(uint8_t*& mem) 404 { 405 importData(mem); 406 return mem; 407 } 408 /// Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT 409 inline void operator>>(uint8_t*& mem) const 410 { 411 exportData(mem); 412 } 413 inline uint32_t getNetworkSize() const 414 { 415 assert(this->value_); 416 return this->value_->getSize() + sizeof(uint8_t); 417 } 466 418 467 419 private: 468 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_Type::Char) { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value); return true; } } ///<Assigns a new value by changing type and creating a new container.469 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedChar) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.470 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_Type::Short) { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.471 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedShort) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.472 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_Type::Int) { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.473 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedInt) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.474 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_Type::Long) { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.475 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.476 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_Type::LongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.477 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.478 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_Type::Float) { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.479 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_Type::Double) { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.480 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_Type::LongDouble) { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.481 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_Type::Bool) { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.482 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_Type::VoidPointer) { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.483 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_Type::String) { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.484 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector2) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 485 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector3) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.486 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector4) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.487 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_Type::ColourValue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.488 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_Type::Quaternion) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.489 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_Type::Radian) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.490 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_Type::Degree) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); return true; } } ///< Assigns a new value by changing type and creating a new container.420 /// Assigns a new value by changing type and creating a new container. 421 template <typename T> inline void assignValue(const T& value) 422 { 423 if (this->isType<T>()) 424 this->value_->setValue(value); 425 else 426 this->changeValueContainer(value); 427 } 428 /// Assigns a new value by changing type and creating a new container (overload for pointers). 429 template <typename T> inline void assignValue(T* const& value) 430 { 431 if (this->isType<void*>()) 432 this->value_->setValue(static_cast<void*>(value)); 433 else 434 this->changeValueContainer<void*>(value); 435 } 436 437 /// Resets the value and changes the internal type to the given type. 438 inline void setType(Type::Enum type) { this->reset(); this->convert(type); this->resetValue(); } 439 /// Returns the current type. 440 inline Type::Enum getType() const { return (this->value_) ? this->value_->type_ : Type::Null; } 441 /// Converts the current value to the given type. 442 bool convert(Type::Enum type); 491 443 492 444 /// Changes the value container. 493 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } 445 template <typename T> inline void changeValueContainer(const T& value) 446 { 447 if (this->value_) 448 delete this->value_; 449 this->createNewValueContainer(value); 450 } 494 451 /// Creates a new value container (works only with specialized types). 495 template <typename T> 452 template <typename T> inline void createNewValueContainer(const T& value) { /* STATIC ASSERT */ *****value; return false; } 496 453 497 454 MT_ValueBase* value_; //!< A pointer to the value container … … 499 456 500 457 /// Puts the MultiType on a stream by using the native << operator of the current type. 501 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 502 503 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_Type::Char); } ///< Returns true if the current type equals the given type. 504 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedChar); } ///< Returns true if the current type equals the given type. 505 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_Type::Short); } ///< Returns true if the current type equals the given type. 506 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedShort); } ///< Returns true if the current type equals the given type. 507 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_Type::Int); } ///< Returns true if the current type equals the given type. 508 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedInt); } ///< Returns true if the current type equals the given type. 509 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_Type::Long); } ///< Returns true if the current type equals the given type. 510 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLong); } ///< Returns true if the current type equals the given type. 511 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_Type::LongLong); } ///< Returns true if the current type equals the given type. 512 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong); } ///< Returns true if the current type equals the given type. 513 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_Type::Float); } ///< Returns true if the current type equals the given type. 514 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_Type::Double); } ///< Returns true if the current type equals the given type. 515 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_Type::LongDouble); } ///< Returns true if the current type equals the given type. 516 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_Type::Bool); } ///< Returns true if the current type equals the given type. 517 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_Type::VoidPointer); } ///< Returns true if the current type equals the given type. 518 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_Type::String); } ///< Returns true if the current type equals the given type. 519 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector2); } ///< Returns true if the current type equals the given type. 520 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector3); } ///< Returns true if the current type equals the given type. 521 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector4); } ///< Returns true if the current type equals the given type. 522 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_Type::ColourValue); } ///< Returns true if the current type equals the given type. 523 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_Type::Quaternion); } ///< Returns true if the current type equals the given type. 524 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_Type::Radian); } ///< Returns true if the current type equals the given type. 525 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_Type::Degree); } ///< Returns true if the current type equals the given type. 526 527 /// Deletes the content, type becomes MT_Type::Null. 528 template <> inline bool MultiType::convert<void>() { this->reset(); return true; } 529 530 // Specialization to avoid ambiguities with the conversion operator 531 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } ///< Converts the current value to the given type. 532 template <> inline bool MultiType::convert<orxonox::Vector2>() { return this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } ///< Converts the current value to the given type. 533 template <> inline bool MultiType::convert<orxonox::Vector3>() { return this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } ///< Converts the current value to the given type. 534 template <> inline bool MultiType::convert<orxonox::Vector4>() { return this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } ///< Converts the current value to the given type. 535 template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } ///< Converts the current value to the given type. 536 template <> inline bool MultiType::convert<orxonox::Quaternion>() { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } ///< Converts the current value to the given type. 537 template <> inline bool MultiType::convert<orxonox::Radian>() { return this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } ///< Converts the current value to the given type. 538 template <> inline bool MultiType::convert<orxonox::Degree>() { return this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } ///< Converts the current value to the given type. 539 540 // Specialization to avoid ambiguities with the conversion operator 541 template <> inline bool MultiType::convert<const std::string&>() { return this->convert<std::string>(); } ///< Converts the current value to the given type. 542 template <> inline bool MultiType::convert<const orxonox::Vector2&>() { return this->convert<orxonox::Vector2>(); } ///< Converts the current value to the given type. 543 template <> inline bool MultiType::convert<const orxonox::Vector3&>() { return this->convert<orxonox::Vector3>(); } ///< Converts the current value to the given type. 544 template <> inline bool MultiType::convert<const orxonox::Vector4&>() { return this->convert<orxonox::Vector4>(); } ///< Converts the current value to the given type. 545 template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } ///< Converts the current value to the given type. 546 template <> inline bool MultiType::convert<const orxonox::Quaternion&>() { return this->convert<orxonox::Quaternion>(); } ///< Converts the current value to the given type. 547 template <> inline bool MultiType::convert<const orxonox::Radian&>() { return this->convert<orxonox::Radian>(); } ///< Converts the current value to the given type. 548 template <> inline bool MultiType::convert<const orxonox::Degree&>() { return this->convert<orxonox::Degree>(); } ///< Converts the current value to the given type. 458 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) 459 { 460 if (mt.value_) 461 mt.value_->toString(outstream); 462 return outstream; 463 } 464 465 template <> inline bool MultiType::MT_ValueBase::isType<char>() const { return this->type_ == Type::Char; } 466 template <> inline bool MultiType::MT_ValueBase::isType<unsigned char>() const { return this->type_ == Type::UnsignedChar; } 467 template <> inline bool MultiType::MT_ValueBase::isType<short>() const { return this->type_ == Type::Short; } 468 template <> inline bool MultiType::MT_ValueBase::isType<unsigned short>() const { return this->type_ == Type::UnsignedShort; } 469 template <> inline bool MultiType::MT_ValueBase::isType<int>() const { return this->type_ == Type::Int; } 470 template <> inline bool MultiType::MT_ValueBase::isType<unsigned int>() const { return this->type_ == Type::UnsignedInt; } 471 template <> inline bool MultiType::MT_ValueBase::isType<long>() const { return this->type_ == Type::Long; } 472 template <> inline bool MultiType::MT_ValueBase::isType<unsigned long>() const { return this->type_ == Type::UnsignedLong; } 473 template <> inline bool MultiType::MT_ValueBase::isType<long long>() const { return this->type_ == Type::LongLong; } 474 template <> inline bool MultiType::MT_ValueBase::isType<unsigned long long>() const { return this->type_ == Type::UnsignedLongLong; } 475 template <> inline bool MultiType::MT_ValueBase::isType<float>() const { return this->type_ == Type::Float; } 476 template <> inline bool MultiType::MT_ValueBase::isType<double>() const { return this->type_ == Type::Double; } 477 template <> inline bool MultiType::MT_ValueBase::isType<long double>() const { return this->type_ == Type::LongDouble; } 478 template <> inline bool MultiType::MT_ValueBase::isType<bool>() const { return this->type_ == Type::Bool; } 479 template <> inline bool MultiType::MT_ValueBase::isType<void*>() const { return this->type_ == Type::VoidPointer; } 480 template <> inline bool MultiType::MT_ValueBase::isType<std::string>() const { return this->type_ == Type::String; } 481 template <> inline bool MultiType::MT_ValueBase::isType<orxonox::Vector2>() const { return this->type_ == Type::Vector2; } 482 template <> inline bool MultiType::MT_ValueBase::isType<orxonox::Vector3>() const { return this->type_ == Type::Vector3; } 483 template <> inline bool MultiType::MT_ValueBase::isType<orxonox::Vector4>() const { return this->type_ == Type::Vector4; } 484 template <> inline bool MultiType::MT_ValueBase::isType<orxonox::ColourValue>() const { return this->type_ == Type::ColourValue; } 485 template <> inline bool MultiType::MT_ValueBase::isType<orxonox::Quaternion>() const { return this->type_ == Type::Quaternion; } 486 template <> inline bool MultiType::MT_ValueBase::isType<orxonox::Radian>() const { return this->type_ == Type::Radian; } 487 template <> inline bool MultiType::MT_ValueBase::isType<orxonox::Degree>() const { return this->type_ == Type::Degree; } 488 489 template <> inline bool MultiType::set(const char* value) { return this->set(std::string(value)); } 490 template <> inline bool MultiType::set(const mbool& value) { return this->set((bool)value); } 491 492 // Spezializations for void 493 template <> inline bool MultiType::isType<void>() const { return this->null(); } 494 template <> inline bool MultiType::convert<void>() { this->reset(); return true; } 549 495 550 496 template <> _UtilExport void MultiType::createNewValueContainer(const char& value); … … 571 517 template <> _UtilExport void MultiType::createNewValueContainer(const orxonox::Radian& value); 572 518 template <> _UtilExport void MultiType::createNewValueContainer(const orxonox::Degree& value); 573 574 inline bool MultiType::setValue(const char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.575 inline bool MultiType::setValue(const unsigned char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.576 inline bool MultiType::setValue(const short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.577 inline bool MultiType::setValue(const unsigned short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.578 inline bool MultiType::setValue(const int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.579 inline bool MultiType::setValue(const unsigned int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.580 inline bool MultiType::setValue(const long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.581 inline bool MultiType::setValue(const unsigned long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.582 inline bool MultiType::setValue(const long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.583 inline bool MultiType::setValue(const unsigned long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.584 inline bool MultiType::setValue(const float& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.585 inline bool MultiType::setValue(const double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.586 inline bool MultiType::setValue(const long double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.587 inline bool MultiType::setValue(const bool& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.588 inline bool MultiType::setValue( void* const& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.589 inline bool MultiType::setValue(const std::string& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.590 inline bool MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.591 inline bool MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.592 inline bool MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.593 inline bool MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.594 inline bool MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.595 inline bool MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.596 inline bool MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type.597 598 /// Assigns the given value and converts it to the current type.599 inline bool MultiType::setValue(const char* value) { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } }600 519 } 601 520 -
code/trunk/src/libraries/util/MultiTypeValue.h
r8706 r9550 55 55 public: 56 56 /// Constructor: Assigns the value and the type identifier. 57 MT_Value(const T& value, M T_Type::Value type) : MT_ValueBase(type), value_(value) {}57 MT_Value(const T& value, MultiType::Type::Enum type) : MT_ValueBase(&this->value_, type), value_(value) {} 58 58 59 59 /// Creates a copy of itself. … … 61 61 62 62 /// Resets the current value to the default. 63 inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; } 64 65 /** 66 @brief Assigns the value of the other MultiType, converted to T. 67 @param other The other MultiType 68 */ 69 inline bool assimilate(const MultiType& other) 70 { 71 if (other.value_) 72 { 73 return !(bHasDefaultValue_ = !other.value_->getValue(&value_)); 74 } 75 else 76 { 77 this->value_ = zeroise<T>(); 78 return !(bHasDefaultValue_ = true); 79 } 80 } 63 inline void reset() { this->value_ = zeroise<T>(); bLastConversionSuccessful = true; } 81 64 82 65 inline bool getValue(char* value) const { return convertValue<T, char >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. … … 95 78 inline bool getValue(bool* value) const { return convertValue<T, bool >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 96 79 inline bool getValue(void** value) const { return convertValue<T, void* >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 97 inline bool getValue(std::string* value) const { return convertValue<T, std::string >(value, value_, zeroise<std::string> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 98 inline bool getValue(orxonox::Vector2* value) const { return convertValue<T, orxonox::Vector2 >(value, value_, zeroise<orxonox::Vector2> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 99 inline bool getValue(orxonox::Vector3* value) const { return convertValue<T, orxonox::Vector3 >(value, value_, zeroise<orxonox::Vector3> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 100 inline bool getValue(orxonox::Vector4* value) const { return convertValue<T, orxonox::Vector4 >(value, value_, zeroise<orxonox::Vector4> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 101 inline bool getValue(orxonox::ColourValue* value) const { return convertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 102 inline bool getValue(orxonox::Quaternion* value) const { return convertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 103 inline bool getValue(orxonox::Radian* value) const { return convertValue<T, orxonox::Radian >(value, value_, zeroise<orxonox::Radian> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 104 inline bool getValue(orxonox::Degree* value) const { return convertValue<T, orxonox::Degree >(value, value_, zeroise<orxonox::Degree> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 105 106 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !convertValue<char , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 107 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !convertValue<unsigned char , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 108 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !convertValue<short , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 109 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !convertValue<unsigned short , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 110 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !convertValue<int , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 111 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !convertValue<unsigned int , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 112 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !convertValue<long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 113 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 114 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !convertValue<long long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 115 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 116 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !convertValue<float , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 117 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !convertValue<double , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 118 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !convertValue<long double , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 119 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !convertValue<bool , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 120 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !convertValue<void* , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 121 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !convertValue<std::string , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 122 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector2 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 123 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector3 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 124 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector4 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 125 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 126 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 127 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Radian , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 128 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Degree , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 129 130 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 131 inline operator unsigned char() const { return getConvertedValue<T, unsigned char> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 132 inline operator short() const { return getConvertedValue<T, short> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 133 inline operator unsigned short() const { return getConvertedValue<T, unsigned short> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 134 inline operator int() const { return getConvertedValue<T, int> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 135 inline operator unsigned int() const { return getConvertedValue<T, unsigned int> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 136 inline operator long() const { return getConvertedValue<T, long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 137 inline operator unsigned long() const { return getConvertedValue<T, unsigned long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 138 inline operator long long() const { return getConvertedValue<T, long long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 139 inline operator unsigned long long() const { return getConvertedValue<T, unsigned long long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 140 inline operator float() const { return getConvertedValue<T, float> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 141 inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 142 inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 143 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 144 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 145 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, NilValue<std::string >()); } ///< Returns the current value, converted to the requested type. 146 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, NilValue<orxonox::Vector2 >()); } ///< Returns the current value, converted to the requested type. 147 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, NilValue<orxonox::Vector3 >()); } ///< Returns the current value, converted to the requested type. 148 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, NilValue<orxonox::Vector4 >()); } ///< Returns the current value, converted to the requested type. 149 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, NilValue<orxonox::ColourValue>()); } ///< Returns the current value, converted to the requested type. 150 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, NilValue<orxonox::Quaternion >()); } ///< Returns the current value, converted to the requested type. 151 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, NilValue<orxonox::Radian >()); } ///< Returns the current value, converted to the requested type. 152 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, NilValue<orxonox::Degree >()); } ///< Returns the current value, converted to the requested type. 80 inline bool getValue(std::string* value) const { return convertValue<T, std::string >(value, value_, NilValue<std::string> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 81 inline bool getValue(orxonox::Vector2* value) const { return convertValue<T, orxonox::Vector2 >(value, value_, NilValue<orxonox::Vector2> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 82 inline bool getValue(orxonox::Vector3* value) const { return convertValue<T, orxonox::Vector3 >(value, value_, NilValue<orxonox::Vector3> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 83 inline bool getValue(orxonox::Vector4* value) const { return convertValue<T, orxonox::Vector4 >(value, value_, NilValue<orxonox::Vector4> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 84 inline bool getValue(orxonox::ColourValue* value) const { return convertValue<T, orxonox::ColourValue>(value, value_, NilValue<orxonox::ColourValue>()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 85 inline bool getValue(orxonox::Quaternion* value) const { return convertValue<T, orxonox::Quaternion >(value, value_, NilValue<orxonox::Quaternion> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 86 inline bool getValue(orxonox::Radian* value) const { return convertValue<T, orxonox::Radian >(value, value_, NilValue<orxonox::Radian> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 87 inline bool getValue(orxonox::Degree* value) const { return convertValue<T, orxonox::Degree >(value, value_, NilValue<orxonox::Degree> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 88 89 /** 90 @brief Assigns the value of the other MultiType, converted to T. 91 @param other The other MultiType 92 */ 93 inline bool setValue(const MultiType& other) 94 { 95 if (other.value_) 96 { 97 return (this->bLastConversionSuccessful = other.value_->getValue(&value_)); 98 } 99 else 100 { 101 this->value_ = zeroise<T>(); 102 return (bLastConversionSuccessful = false); 103 } 104 } 105 106 inline bool setValue(const char& value) { return (bLastConversionSuccessful = convertValue<char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 107 inline bool setValue(const unsigned char& value) { return (bLastConversionSuccessful = convertValue<unsigned char , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 108 inline bool setValue(const short& value) { return (bLastConversionSuccessful = convertValue<short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 109 inline bool setValue(const unsigned short& value) { return (bLastConversionSuccessful = convertValue<unsigned short , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 110 inline bool setValue(const int& value) { return (bLastConversionSuccessful = convertValue<int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 111 inline bool setValue(const unsigned int& value) { return (bLastConversionSuccessful = convertValue<unsigned int , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 112 inline bool setValue(const long& value) { return (bLastConversionSuccessful = convertValue<long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 113 inline bool setValue(const unsigned long& value) { return (bLastConversionSuccessful = convertValue<unsigned long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 114 inline bool setValue(const long long& value) { return (bLastConversionSuccessful = convertValue<long long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 115 inline bool setValue(const unsigned long long& value) { return (bLastConversionSuccessful = convertValue<unsigned long long , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 116 inline bool setValue(const float& value) { return (bLastConversionSuccessful = convertValue<float , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 117 inline bool setValue(const double& value) { return (bLastConversionSuccessful = convertValue<double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 118 inline bool setValue(const long double& value) { return (bLastConversionSuccessful = convertValue<long double , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 119 inline bool setValue(const bool& value) { return (bLastConversionSuccessful = convertValue<bool , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 120 inline bool setValue( void* const& value) { return (bLastConversionSuccessful = convertValue<void* , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 121 inline bool setValue(const std::string& value) { return (bLastConversionSuccessful = convertValue<std::string , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 122 inline bool setValue(const orxonox::Vector2& value) { return (bLastConversionSuccessful = convertValue<orxonox::Vector2 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 123 inline bool setValue(const orxonox::Vector3& value) { return (bLastConversionSuccessful = convertValue<orxonox::Vector3 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 124 inline bool setValue(const orxonox::Vector4& value) { return (bLastConversionSuccessful = convertValue<orxonox::Vector4 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 125 inline bool setValue(const orxonox::ColourValue& value) { return (bLastConversionSuccessful = convertValue<orxonox::ColourValue, T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 126 inline bool setValue(const orxonox::Quaternion& value) { return (bLastConversionSuccessful = convertValue<orxonox::Quaternion , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 127 inline bool setValue(const orxonox::Radian& value) { return (bLastConversionSuccessful = convertValue<orxonox::Radian , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 128 inline bool setValue(const orxonox::Degree& value) { return (bLastConversionSuccessful = convertValue<orxonox::Degree , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T. 153 129 154 130 /// Puts the current value on the stream -
code/trunk/src/libraries/util/SignalHandler.cc
r9016 r9550 21 21 * 22 22 * Author: 23 * Christoph Renner 23 * Christoph Renner (Linux implementation) 24 * Fabian 'x3n' Landau (Windows implementation) 24 25 * Co-authors: 25 26 * ... … … 139 140 orxout(user_error) << "Received signal " << sigName.c_str() << endl << "Try to write backtrace to file orxonox_crash.log" << endl; 140 141 141 142 142 143 // First start GDB which will be attached to this process later on 143 144 144 145 int gdbIn[2]; 145 146 int gdbOut[2]; 146 147 int gdbErr[2]; 147 148 148 149 if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 ) 149 150 { … … 151 152 exit(EXIT_FAILURE); 152 153 } 153 154 154 155 int gdbPid = fork(); 155 156 // this process will run gdb 156 157 157 158 if ( gdbPid == -1 ) 158 159 { … … 160 161 exit(EXIT_FAILURE); 161 162 } 162 163 163 164 if ( gdbPid == 0 ) 164 165 { 165 166 // start gdb 166 167 167 168 close(gdbIn[1]); 168 169 close(gdbOut[0]); 169 170 close(gdbErr[0]); 170 171 171 172 dup2( gdbIn[0], STDIN_FILENO ); 172 173 dup2( gdbOut[1], STDOUT_FILENO ); 173 174 dup2( gdbErr[1], STDERR_FILENO ); 174 175 175 176 execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL)); 176 177 } 177 178 178 179 179 180 // Now start a fork of this process on which GDB will be attached on 180 181 181 182 int sigPipe[2]; 182 183 if ( pipe(sigPipe) == -1 ) … … 202 203 { 203 204 getInstance().dontCatch(); 204 205 205 206 // make sure gdb is allowed to attach to our PID even if there are some system restrictions 206 207 #ifdef PR_SET_PTRACER … … 208 209 orxout(user_error) << "could not set proper permissions for GDB to attach to process..." << endl; 209 210 #endif 210 211 211 212 // wait for message from parent when it has attached gdb 212 213 int someData; -
code/trunk/src/libraries/util/SignalHandler.h
r8351 r9550 21 21 * 22 22 * Author: 23 * Christoph Renner 23 * Christoph Renner (Linux implementation) 24 * Fabian 'x3n' Landau (Windows implementation) 24 25 * Co-authors: 25 26 * ... -
code/trunk/src/libraries/util/StringUtils.cc
r8858 r9550 81 81 } 82 82 83 /// Splits a given string by a delimiter and stores it in an output vector 83 /// Splits a given string by a delimiter and stores it in an output vector. See @ref SubString for a more sophisticated implementation. 84 84 void vectorize(const std::string& str, char delimiter, std::vector<std::string>* output) 85 85 { 86 output->clear(); 86 87 for (size_t start = 0, end = 0; end != std::string::npos; start = end + 1) 87 88 { … … 92 93 93 94 /** 94 @brief Returns the position of the next quotation mark in the string, starting with start. 95 @brief Returns the position of the next quotation mark in the string, starting with start. Escaped quotation marks (with \ in front) are not considered. 95 96 @param str The string 96 97 @param start The first position to look at … … 130 131 size_t quote = static_cast<size_t>(-1); 131 132 while ((quote = getNextQuote(str, quote + 1)) < pos) 132 {133 if (quote == pos)134 return false;135 133 quotecount++; 136 } 137 134 135 if (quote == pos) 136 return false; 138 137 if (quote == std::string::npos) 139 138 return false; … … 156 155 size_t pos2 = getNextQuote(str, pos1 + 1); 157 156 if (pos1 != std::string::npos && pos2 != std::string::npos) 158 return str.substr(pos1 , pos2 - pos1 +1);157 return str.substr(pos1 + 1, pos2 - pos1 - 1); 159 158 else 160 159 return ""; … … 247 246 { 248 247 return getStripped(str).empty(); 249 }250 251 /// Determines if a string contains only numbers and maximal one '.'.252 bool isNumeric(const std::string& str)253 {254 bool foundPoint = false;255 256 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)257 {258 if (((*it) < '0' || (*it) > '9'))259 {260 if ((*it) != '.' && !foundPoint)261 foundPoint = true;262 else263 return false;264 }265 }266 267 return true;268 248 } 269 249 … … 444 424 bool hasComment(const std::string& str) 445 425 { 446 return (get CommentPosition(str) != std::string::npos);447 } 448 449 /// If the string contains a comment, the comment gets returned (including the comment symbol ), an empty string otherwise.426 return (getNextCommentPosition(str) != std::string::npos); 427 } 428 429 /// If the string contains a comment, the comment gets returned (including the comment symbol and white spaces in front of it), an empty string otherwise. 450 430 std::string getComment(const std::string& str) 451 431 { 452 return str.substr(getCommentPosition(str)); 453 } 454 455 /// If the string contains a comment, the position of the comment-symbol gets returned, @c std::string::npos otherwise. 456 size_t getCommentPosition(const std::string& str) 457 { 458 return getNextCommentPosition(str, 0); 459 } 460 461 /** 462 @brief Returns the position of the next comment-symbol, starting with @a start. 432 size_t pos = getNextCommentPosition(str); 433 if (pos == std::string::npos) 434 return ""; 435 else 436 return str.substr(pos); 437 } 438 439 /** 440 @brief Returns the beginning of the next comment including whitespaces in front of the comment symbol. 463 441 @param str The string 464 442 @param start The first position to look at -
code/trunk/src/libraries/util/StringUtils.h
r8858 r9550 58 58 _UtilExport void vectorize(const std::string& str, char delimiter, std::vector<std::string>* output); 59 59 60 _UtilExport size_t getNextQuote(const std::string& str, size_t start );60 _UtilExport size_t getNextQuote(const std::string& str, size_t start = 0); 61 61 _UtilExport bool isBetweenQuotes(const std::string& str, size_t pos); 62 62 … … 69 69 _UtilExport bool isEmpty(const std::string& str); 70 70 _UtilExport bool isComment(const std::string& str); 71 _UtilExport bool isNumeric(const std::string& str);72 71 73 72 _UtilExport std::string addSlashes(const std::string& str); … … 85 84 _UtilExport bool hasComment(const std::string& str); 86 85 _UtilExport std::string getComment(const std::string& str); 87 _UtilExport size_t getCommentPosition(const std::string& str);88 86 _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0); 89 87 -
code/trunk/src/libraries/util/SubString.cc
r8858 r9550 87 87 @param other The other SubString 88 88 @param begin The beginning of the subset 89 90 The subset ranges from the token with index @a begin to the end of the tokens. 91 If @a begin is greater than the greatest index, the new SubString will be empty. 92 */ 93 SubString::SubString(const SubString& other, unsigned int begin) 94 { 95 for (unsigned int i = begin; i < other.size(); ++i) 96 { 97 this->tokens_.push_back(other[i]); 98 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 99 } 100 } 101 102 /** 103 @brief creates a new SubString based on a subset of an other SubString. 104 @param other The other SubString 105 @param begin The beginning of the subset 106 @param end The end of the subset 107 108 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 109 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 110 */ 111 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 112 { 113 for (unsigned int i = begin; i < std::min(other.size(), end); ++i) 114 { 115 this->tokens_.push_back(other[i]); 116 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 89 @param length The length of the subset 90 91 The subset ranges from the token with index @a begin and contains @a length elements. 92 */ 93 SubString::SubString(const SubString& other, size_t begin, size_t length) 94 { 95 for (size_t i = 0; i < length; ++i) 96 { 97 if (begin + i >= other.size()) 98 break; 99 100 this->tokens_.push_back(other[begin + i]); 101 this->bTokenInSafemode_.push_back(other.isInSafemode(begin + i)); 117 102 } 118 103 } … … 123 108 @param argv An array of pointers to the arguments 124 109 */ 125 SubString::SubString( unsigned int argc, const char** argv)126 { 127 for (unsigned int i = 0; i < argc; ++i)110 SubString::SubString(size_t argc, const char** argv) 111 { 112 for (size_t i = 0; i < argc; ++i) 128 113 { 129 114 this->tokens_.push_back(std::string(argv[i])); … … 158 143 159 144 /** 160 @copydoc operator==161 */162 bool SubString::compare(const SubString& other) const163 {164 return (*this == other);165 }166 167 /**168 145 @brief Compares this SubString to another SubString and returns true if the first @a length values match. 169 146 @param other The other SubString 170 147 @param length How many tokens to compare 171 148 */ 172 bool SubString::compare(const SubString& other, unsigned int length) const173 { 174 if ( length > this->size() || length > other.size())149 bool SubString::compare(const SubString& other, size_t length) const 150 { 151 if (std::min(length, this->size()) != std::min(length, other.size())) 175 152 return false; 176 153 177 for ( unsigned int i = 0; i < length; ++i)154 for (size_t i = 0; i < std::min(length, this->size()); ++i) 178 155 if ((this->tokens_[i] != other.tokens_[i]) || (this->bTokenInSafemode_[i] != other.bTokenInSafemode_[i])) 179 156 return false; 157 180 158 return true; 181 159 } … … 196 174 SubString& SubString::operator+=(const SubString& other) 197 175 { 198 for ( unsigned int i = 0; i < other.size(); ++i)176 for (size_t i = 0; i < other.size(); ++i) 199 177 { 200 178 this->tokens_.push_back(other[i]); … … 207 185 @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) 208 186 */ 209 unsigned int SubString::split(const std::string& line,210 211 212 187 size_t SubString::split(const std::string& line, 188 const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, 189 char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, 190 char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) 213 191 { 214 192 this->tokens_.clear(); … … 228 206 { 229 207 std::string retVal = this->tokens_[0]; 230 for ( unsigned int i = 1; i < this->tokens_.size(); ++i)208 for (size_t i = 1; i < this->tokens_.size(); ++i) 231 209 retVal += delimiter + this->tokens_[i]; 232 210 return retVal; … … 239 217 @brief Creates a subset of this SubString. 240 218 @param begin The beginning of the subset 219 @param length The length of the subset 241 220 @return A new SubString containing the defined subset. 242 221 243 The subset ranges from the token with index @a begin to the end of the tokens. 244 If @a begin is greater than the greatest index, the new SubString will be empty. 222 The subset ranges from the token with index @a begin and contains @a length elements. 245 223 246 224 This function is added for your convenience, and does the same as 247 SubString::SubString(const SubString& other, unsigned int begin) 248 */ 249 SubString SubString::subSet(unsigned int begin) const 250 { 251 return SubString(*this, begin); 252 } 253 254 /** 255 @brief Creates a subset of this SubString. 256 @param begin The beginning of the subset 257 @param end The ending of the subset 258 @return A new SubString containing the defined subset. 259 260 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 261 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 262 263 This function is added for your convenience, and does the same as 264 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 265 */ 266 SubString SubString::subSet(unsigned int begin, unsigned int end) const 267 { 268 return SubString(*this, begin, end); 225 SubString::SubString(const SubString& other, size_t begin, size_t length) 226 */ 227 SubString SubString::subSet(size_t begin, size_t length) const 228 { 229 return SubString(*this, begin, length); 269 230 } 270 231 … … 298 259 { 299 260 SPLIT_LINE_STATE state = start_state; 300 unsigned int i = 0;301 unsigned int fallBackNeighbours = 0;261 size_t i = 0; 262 size_t fallBackNeighbours = 0; 302 263 303 264 std::string token; … … 514 475 { 515 476 orxout(debug_output) << "Substring-information::count=" << this->tokens_.size() << " ::"; 516 for ( unsigned int i = 0; i < this->tokens_.size(); ++i)477 for (size_t i = 0; i < this->tokens_.size(); ++i) 517 478 orxout(debug_output) << "s" << i << "='" << this->tokens_[i].c_str() << "'::"; 518 479 orxout(debug_output) << endl; -
code/trunk/src/libraries/util/SubString.h
r8858 r9550 58 58 SubString tokens(text, SubString::WhiteSpaces, "", false, '\\', true, '"', true, '{', '}', true, '\0'); 59 59 60 for ( unsigned int i = 0; i < tokens.size(); ++i)60 for (size_t i = 0; i < tokens.size(); ++i) 61 61 orxout() << i << ": " << tokens[i] << endl; 62 62 @endcode … … 127 127 bool bRemoveParenthesisChars = true, 128 128 char commentChar = '\0'); 129 SubString(unsigned int argc, const char** argv); 130 SubString(const SubString& other, unsigned int begin); 131 SubString(const SubString& other, unsigned int begin, unsigned int end); 129 SubString(size_t argc, const char** argv); 130 SubString(const SubString& other, size_t begin, size_t length = std::string::npos); 132 131 ~SubString(); 133 132 … … 135 134 SubString& operator=(const SubString& other); 136 135 bool operator==(const SubString& other) const; 137 bool compare(const SubString& other) const; 138 bool compare(const SubString& other, unsigned int length) const; 136 bool compare(const SubString& other, size_t length = std::string::npos) const; 139 137 SubString operator+(const SubString& other) const; 140 138 SubString& operator+=(const SubString& other); … … 144 142 ///////////////////////////////////////// 145 143 // Split and Join the any String. /////// 146 unsigned int split(const std::string& line,147 148 149 150 151 152 153 154 155 156 157 144 size_t split(const std::string& line, 145 const std::string& delimiters = SubString::WhiteSpaces, 146 const std::string& delimiterNeighbours = "", 147 bool bAllowEmptyEntries = false, 148 char escapeChar ='\\', 149 bool bRemoveEscapeChar = true, 150 char safemodeChar = '"', 151 bool bRemoveSafemodeChar = true, 152 char openparenthesisChar = '{', 153 char closeparenthesisChar = '}', 154 bool bRemoveParenthesisChars = true, 155 char commentChar = '\0'); 158 156 159 157 std::string join(const std::string& delimiter = " ") const; … … 161 159 162 160 // retrieve a SubSet from the String 163 SubString subSet(unsigned int begin) const; 164 SubString subSet(unsigned int begin, unsigned int end) const; 161 SubString subSet(size_t begin, size_t length = std::string::npos) const; 165 162 166 163 // retrieve Information from within … … 168 165 inline bool empty() const { return this->tokens_.empty(); } 169 166 /// Returns the number of tokens stored in this SubString 170 inline unsigned int size() const { return this->tokens_.size(); }167 inline size_t size() const { return this->tokens_.size(); } 171 168 /// Returns the i'th token from the subset of strings @param index The index of the requested token 172 inline const std::string& operator[]( unsigned int index) const { return this->tokens_[index]; }169 inline const std::string& operator[](size_t index) const { return this->tokens_[index]; } 173 170 /// Returns the i'th token from the subset of strings @param index The index of the requested token 174 inline const std::string& getString( unsigned int index) const { return (*this)[index]; }171 inline const std::string& getString(size_t index) const { return (*this)[index]; } 175 172 /// Returns all tokens as std::vector 176 173 inline const std::vector<std::string>& getAllStrings() const { return this->tokens_; } 177 174 /// Returns true if the token is in safemode. @param index The index of the token 178 inline bool isInSafemode( unsigned int index) const { return this->bTokenInSafemode_[index]; }175 inline bool isInSafemode(size_t index) const { return this->bTokenInSafemode_[index]; } 179 176 /// Returns the front of the list of tokens. 180 177 inline const std::string& front() const { return this->tokens_.front(); } -
code/trunk/src/libraries/util/UtilPrereqs.h
r8858 r9550 84 84 namespace orxonox 85 85 { 86 class AdditionalContextListener; 87 class BaseWriter; 86 88 class Clock; 89 class ConsoleWriter; 87 90 class Exception; 88 91 class ExprParser; 92 class LogWriter; 93 class MemoryWriter; 89 94 class MultiType; 90 95 class OutputListener; … … 96 101 class ScopedSingleton; 97 102 class ScopeListener; 103 template <class T> 104 class SharedPtr; 98 105 class SignalHandler; 99 106 template <class T> 100 107 class Singleton; 108 class SubcontextOutputListener; 101 109 class SubString; 102 110 } -
code/trunk/src/libraries/util/VA_NARGS.h
r7401 r9550 36 36 type aware, but for different numbers of arguments is still very powerful). 37 37 38 Important: The macro can not be overloaded for 0 arguments: ORXONOX_VA_NARGS() returns 1! 39 38 40 Example: A macro to call functions 39 41 @code … … 64 66 */ 65 67 68 #include <boost/preprocessor/cat.hpp> 66 69 #include <boost/preprocessor/facilities/expand.hpp> 67 70 -
code/trunk/src/libraries/util/output/ConsoleWriter.cc
r9348 r9550 34 34 #include "ConsoleWriter.h" 35 35 36 #include <iostream>37 36 38 37 #include "OutputManager.h" … … 48 47 After creation, the instance is enabled. 49 48 */ 50 ConsoleWriter::ConsoleWriter( ) : BaseWriter("Console")49 ConsoleWriter::ConsoleWriter(std::ostream& outputStream) : BaseWriter("Console"), outputStream_(outputStream) 51 50 { 52 51 #ifdef ORXONOX_RELEASE … … 66 65 67 66 /** 68 @brief Returns the only existing instance of this class.69 */70 /*static*/ ConsoleWriter& ConsoleWriter::getInstance()71 {72 static ConsoleWriter instance;73 return instance;74 }75 76 /**77 67 @brief Inherited function from BaseWriter, writes output to the console using std::cout. 78 68 */ 79 69 void ConsoleWriter::printLine(const std::string& line, OutputLevel) 80 70 { 81 std::cout<< line << std::endl;71 this->outputStream_ << line << std::endl; 82 72 } 83 73 -
code/trunk/src/libraries/util/output/ConsoleWriter.h
r8858 r9550 37 37 38 38 #include "util/UtilPrereqs.h" 39 40 #include <ostream> 41 39 42 #include "BaseWriter.h" 40 43 … … 44 47 @brief ConsoleWriter inherits from BaseWriter and writes output to the console. 45 48 46 This class can be seen as an equivalent to std::cout within the output 47 system. It is implemented as a singleton for static acces. 49 This class can be seen as an equivalent to std::cout within the output system. 48 50 */ 49 51 class _UtilExport ConsoleWriter : public BaseWriter 50 52 { 51 53 public: 52 static ConsoleWriter& getInstance(); 54 ConsoleWriter(std::ostream& outputStream); 55 ConsoleWriter(const ConsoleWriter&); 56 virtual ~ConsoleWriter(); 53 57 54 58 void enable(); 55 59 void disable(); 60 61 inline const std::ostream& getOutputStream() const 62 { return this->outputStream_; } 56 63 57 64 protected: … … 59 66 60 67 private: 61 ConsoleWriter(); 62 ConsoleWriter(const ConsoleWriter&); 63 virtual ~ConsoleWriter(); 64 65 bool bEnabled_; ///< If false, the instance will not write output to the console. 68 std::ostream& outputStream_; ///< The ostream to which the console writer writes its output 69 bool bEnabled_; ///< If false, the instance will not write output to the console. 66 70 }; 67 71 } -
code/trunk/src/libraries/util/output/LogWriter.cc
r8858 r9550 39 39 #include "OutputManager.h" 40 40 #include "MemoryWriter.h" 41 #include "util/Convert.h" 41 42 42 43 namespace orxonox 43 44 { 45 static const int MAX_ARCHIVED_FILES = 9; 46 44 47 /** 45 48 @brief Constructor, initializes the desired output levels and the name and path of the log-file, and opens the log-file. … … 58 61 // get the path for a temporary file, depending on the system 59 62 #ifdef ORXONOX_PLATFORM_WINDOWS 60 this-> path_ = getenv("TEMP");63 this->directory_ = getenv("TEMP"); 61 64 #else 62 this-> path_ = "/tmp";65 this->directory_ = "/tmp"; 63 66 #endif 64 this->bDefaultPath_ = true; 67 68 // send a message to the user so that he can find the file in the case of a crash. 69 OutputManager::getInstance().pushMessage(level::user_info, context::undefined(), "Opening log file " + this->getPath()); 65 70 66 71 this->openFile(); … … 76 81 77 82 /** 78 @brief Returns the only existing instance of this class.79 */80 /*static*/ LogWriter& LogWriter::getInstance()81 {82 static LogWriter instance;83 return instance;84 }85 86 /**87 83 @brief Opens the log-file in order to write output to it. 88 84 */ 89 85 void LogWriter::openFile() 90 86 { 91 // get the full file-name 92 std::string name = this->path_ + '/' + this->filename_; 93 94 // if we open the log file in the default directory, send a message to the user so that he can find the file in the case of a crash. 95 if (this->bDefaultPath_) 96 OutputManager::getInstance().pushMessage(level::user_info, context::undefined(), "Opening log file " + name); 87 // archive the old log file 88 this->archive(); 97 89 98 90 // open the file 99 this->file_.open( name.c_str(), std::fstream::out);91 this->file_.open(this->getPath().c_str(), std::fstream::out); 100 92 101 93 // check if it worked and print some output … … 119 111 120 112 /** 113 * @brief Archives old copies of the log file by adding increasing numbers to the filename. 114 */ 115 void LogWriter::archive(int index) 116 { 117 std::string oldPath = this->getArchivedPath(index); 118 119 // see if the file already exists, otherwise return 120 std::ifstream stream(oldPath.c_str()); 121 bool exists = stream.is_open(); 122 stream.close(); 123 124 if (!exists) 125 return; 126 127 if (index < MAX_ARCHIVED_FILES) 128 { 129 // increment the index and archive the file with the next higher index 130 this->archive(++index); 131 132 // create the new path based on the incremented index 133 std::string newPath = this->getArchivedPath(index); 134 135 // move the file 136 std::rename(oldPath.c_str(), newPath.c_str()); 137 } 138 else 139 { 140 // delete the file 141 std::remove(oldPath.c_str()); 142 } 143 } 144 145 /** 146 * @brief Returns the path for archived copies of the logfile (based on the archive index) 147 */ 148 std::string LogWriter::getArchivedPath(int index) const 149 { 150 std::string path = this->getPath(); 151 if (index > 0) 152 path += '.' + multi_cast<std::string>(index); 153 return path; 154 } 155 156 /** 121 157 @brief Changes the path of the log-file. Re-writes the log-file by using MemoryWriter. 122 158 */ 123 void LogWriter::setLog Path(const std::string& path)159 void LogWriter::setLogDirectory(const std::string& directory) 124 160 { 125 161 // notify about the change of the log-file (because the old file will no longer be updated) 126 OutputManager::getInstance().pushMessage(level::internal_info, context::undefined(), "Migrating log file from " + this-> path_ + "\nto " + path);162 OutputManager::getInstance().pushMessage(level::internal_info, context::undefined(), "Migrating log file from " + this->directory_ + "\nto " + directory); 127 163 128 164 // close the old file, update the path and open the new file 129 165 this->closeFile(); 130 this->path_ = path; 131 this->bDefaultPath_ = false; 166 this->directory_ = directory; 132 167 this->openFile(); 133 168 134 169 // request old output from MemoryWriter 135 MemoryWriter::getInstance().resendOutput(this); 170 if (OutputManager::getInstance().getMemoryWriter()) 171 OutputManager::getInstance().getMemoryWriter()->resendOutput(this); 136 172 } 137 173 -
code/trunk/src/libraries/util/output/LogWriter.h
r8858 r9550 47 47 @brief The LogWriter class inherits from BaseWriter and writes output to a log-file. 48 48 49 It is implemented as singleton because we (currently) use only one 50 log-file. The path of the file can be changed, in which case the file 49 The path of the file can be changed, in which case the file 51 50 is rewritten by using the output stored by MemoryWriter. This adds the 52 51 possibility to change the desired output levels before changing the … … 57 56 { 58 57 public: 59 static LogWriter& getInstance(); 58 LogWriter(); 59 LogWriter(const LogWriter&); 60 virtual ~LogWriter(); 60 61 61 void setLogPath(const std::string& path); 62 void setLogDirectory(const std::string& directory); 63 64 /** @brief Returns the path to the logfile. */ 65 inline std::string getPath() const 66 { return this->directory_ + '/' + this->filename_; } 67 /** @brief Returns the open file stream. */ 68 inline const std::ofstream& getFile() const 69 { return this->file_; } 62 70 63 71 protected: … … 65 73 66 74 private: 67 LogWriter();68 LogWriter(const LogWriter&);69 virtual ~LogWriter();70 71 75 void openFile(); 72 76 void closeFile(); 73 77 74 std::string filename_; ///< The name of the log-file (without directories) 75 std::string path_; ///< The path of the log-file (without file-name) 76 bool bDefaultPath_; ///< If true, the log-file resides at the default path (which is usually a temporary directory) 78 void archive(int index = 0); 79 std::string getArchivedPath(int index) const; 77 80 81 std::string filename_; ///< The name of the log-file (without directory) 82 std::string directory_; ///< The directory where the log-file resided (without file-name) 78 83 std::ofstream file_; ///< The output file stream. 79 84 }; -
code/trunk/src/libraries/util/output/MemoryWriter.cc
r8858 r9550 53 53 54 54 /** 55 @brief Returns the only existing instance of this singleton class.56 */57 /*static*/ MemoryWriter& MemoryWriter::getInstance()58 {59 static MemoryWriter instance;60 return instance;61 }62 63 /**64 55 @brief Implementation of the output() function inherited from OutputListener, stores the received output in memory. 65 56 */ -
code/trunk/src/libraries/util/output/MemoryWriter.h
r8858 r9550 67 67 68 68 public: 69 static MemoryWriter& getInstance(); 69 MemoryWriter(); 70 MemoryWriter(const MemoryWriter&); 71 virtual ~MemoryWriter(); 70 72 71 73 void resendOutput(OutputListener* listener) const; … … 76 78 77 79 private: 78 MemoryWriter();79 MemoryWriter(const MemoryWriter&);80 virtual ~MemoryWriter();81 82 80 std::vector<Message> messages_; ///< Stores all output messages from the creation of this instance until disable() is called. 83 81 }; -
code/trunk/src/libraries/util/output/OutputDefinitions.h
r8879 r9550 47 47 context argument. 48 48 */ 49 #define REGISTER_OUTPUT_CONTEXT(name) \ 50 const OutputContextContainer& name() { static const OutputContextContainer& context = registerContext(#name); return context; } 49 #ifndef DISABLE_OUTPUT_CONTEXT_STATIC_CACHE 50 #define REGISTER_OUTPUT_CONTEXT(name) \ 51 const OutputContextContainer& name() { static OutputContextContainer context = registerContext(#name); return context; } 52 #else 53 #define REGISTER_OUTPUT_CONTEXT(name) \ 54 const OutputContextContainer& name() { return registerContext(#name); } 55 #endif 51 56 52 57 /** … … 60 65 individually by derivatives of orxonox::SubcontextOutputListener. 61 66 */ 62 #define REGISTER_OUTPUT_SUBCONTEXT(name, subname) \ 63 const OutputContextContainer& subname() { static const OutputContextContainer& context = registerContext(#name, #subname); return context; } 67 #ifndef DISABLE_OUTPUT_CONTEXT_STATIC_CACHE 68 #define REGISTER_OUTPUT_SUBCONTEXT(name, subname) \ 69 const OutputContextContainer& subname() { static const OutputContextContainer context = registerContext(#name, #subname); return context; } 70 #else 71 #define REGISTER_OUTPUT_SUBCONTEXT(name, subname) \ 72 const OutputContextContainer& subname() { return registerContext(#name, #subname); } 73 #endif 64 74 65 75 // tolua_begin … … 105 115 OutputContextSubID sub_id; ///< The id of the sub-context (or context::no_subcontext if this container doesn't define a sub-context) 106 116 std::string name; ///< The name of this context 117 118 inline bool operator==(const OutputContextContainer& other) const 119 { 120 return this->mask == other.mask && this->sub_id == other.sub_id && this->name == other.name; 121 } 107 122 }; 108 123 -
code/trunk/src/libraries/util/output/OutputListener.cc
r8858 r9550 62 62 63 63 /** 64 @brief Adds a listener to the list. 65 */ 66 void OutputListener::registerListener(AdditionalContextListener* listener) 67 { 68 this->listeners_.push_back(listener); 69 } 70 71 /** 72 @brief Removes a listener from the list. 73 */ 74 void OutputListener::unregisterListener(AdditionalContextListener* listener) 75 { 76 for (std::vector<AdditionalContextListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 77 { 78 if (*it == listener) 79 { 80 this->listeners_.erase(it); 81 break; 82 } 83 } 84 } 85 86 /** 64 87 @brief Defines the level mask in a way which accepts all output up to the level \c max. 65 88 */ … … 88 111 this->levelMask_ = mask; 89 112 90 OutputManager::getInstance().updateCombinedLevelMask(); 113 for (size_t i = 0; i < this->listeners_.size(); ++i) 114 this->listeners_[i]->updatedLevelMask(this); 91 115 } 92 116 … … 118 142 this->additionalContextsLevelMask_ = mask; 119 143 120 OutputManager::getInstance().updateCombinedAdditionalContextsLevelMask(); 144 for (size_t i = 0; i < this->listeners_.size(); ++i) 145 this->listeners_[i]->updatedAdditionalContextsLevelMask(this); 121 146 } 122 147 … … 128 153 this->additionalContextsMask_ = mask; 129 154 130 OutputManager::getInstance().updateCombinedAdditionalContextsMask(); 155 for (size_t i = 0; i < this->listeners_.size(); ++i) 156 this->listeners_[i]->updatedAdditionalContextsMask(this); 131 157 } 132 158 -
code/trunk/src/libraries/util/output/OutputListener.h
r8858 r9550 55 55 virtual ~OutputListener(); 56 56 57 void registerListener(AdditionalContextListener* listener); 58 void unregisterListener(AdditionalContextListener* listener); 59 57 60 void setLevelMax(OutputLevel max); 58 61 void setLevelRange(OutputLevel min, OutputLevel max); … … 63 66 void setAdditionalContextsLevelMask(OutputLevel mask); 64 67 65 v oid setAdditionalContextsMask(OutputContextMask mask);68 virtual void setAdditionalContextsMask(OutputContextMask mask); 66 69 67 70 /// @brief Returns the level mask. … … 78 81 79 82 /// @brief Called by OutputManager for each line of output, checks if this listener actually accepts this output before it calls the output() function. 80 inlinevoid unfilteredOutput(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)83 virtual void unfilteredOutput(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 81 84 { if (this->acceptsOutput(level, context)) this->output(level, context, lines); } 82 85 … … 85 88 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) = 0; 86 89 90 inline const std::vector<AdditionalContextListener*>& getListeners() const 91 { return this->listeners_; } 92 87 93 private: 88 OutputLevel levelMask_; ///< Mask of accepted output levels, independent of contexts 89 OutputContextMask additionalContextsMask_; ///< Mask of accepted additional contexts 90 OutputLevel additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts 94 std::vector<AdditionalContextListener*> listeners_; ///< List of all registered additional context listeners 95 96 OutputLevel levelMask_; ///< Mask of accepted output levels, independent of contexts 97 OutputContextMask additionalContextsMask_; ///< Mask of accepted additional contexts 98 OutputLevel additionalContextsLevelMask_; ///< Mask of accepted output levels of the additional contexts 91 99 }; 92 100 -
code/trunk/src/libraries/util/output/OutputManager.cc
r8858 r9550 33 33 34 34 #include "OutputManager.h" 35 36 #include <iostream> 35 37 36 38 #include "MemoryWriter.h" … … 39 41 #include "util/Output.h" 40 42 #include "util/StringUtils.h" 43 #include "util/SharedPtr.h" 41 44 42 45 namespace orxonox … … 52 55 53 56 this->subcontextCounter_ = 0; 57 58 this->isInitialized_ = false; 59 this->memoryWriterInstance_ = 0; 60 this->consoleWriterInstance_ = 0; 61 this->logWriterInstance_ = 0; 62 63 // register 'undefined' context in order to give it always the first context-ID 64 this->registerContext("undefined"); 54 65 } 55 66 … … 59 70 OutputManager::~OutputManager() 60 71 { 72 while (!this->listeners_.empty()) 73 this->unregisterListener(this->listeners_[0]); 74 75 if (this->memoryWriterInstance_) 76 delete this->memoryWriterInstance_; 77 if (this->consoleWriterInstance_) 78 delete this->consoleWriterInstance_; 79 if (this->logWriterInstance_) 80 delete this->logWriterInstance_; 81 } 82 83 /*static*/ SharedPtr<OutputManager>& OutputManager::Testing::getInstancePointer() 84 { 85 static SharedPtr<OutputManager> instance(new OutputManager()); 86 return instance; 61 87 } 62 88 … … 66 92 /*static*/ OutputManager& OutputManager::getInstance() 67 93 { 68 static OutputManager instance; 69 return instance; 94 return *OutputManager::Testing::getInstancePointer(); 70 95 } 71 96 … … 80 105 /*static*/ OutputManager& OutputManager::getInstanceAndCreateListeners() 81 106 { 82 static OutputManager& instance = OutputManager::getInstance(); 83 84 static MemoryWriter& memoryWriterInstance = MemoryWriter::getInstance(); (void)memoryWriterInstance; 85 static ConsoleWriter& consoleWriterInstance = ConsoleWriter::getInstance(); (void)consoleWriterInstance; 86 static LogWriter& logWriterInstance = LogWriter::getInstance(); (void)logWriterInstance; 107 OutputManager& instance = *OutputManager::Testing::getInstancePointer(); 108 109 if (!instance.isInitialized_) { 110 instance.isInitialized_ = true; 111 instance.memoryWriterInstance_ = new MemoryWriter(); 112 instance.consoleWriterInstance_ = new ConsoleWriter(std::cout); 113 instance.logWriterInstance_ = new LogWriter(); 114 } 87 115 88 116 return instance; … … 113 141 void OutputManager::registerListener(OutputListener* listener) 114 142 { 143 listener->registerListener(this); 115 144 this->listeners_.push_back(listener); 116 145 this->updateMasks(); … … 122 151 void OutputManager::unregisterListener(OutputListener* listener) 123 152 { 153 listener->unregisterListener(this); 124 154 for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 125 155 { … … 267 297 { 268 298 // "undefined" context is ignored because it's used implicitly if no explicit context is defined 269 staticOutputContextMask undefined_mask = context::undefined().mask;299 OutputContextMask undefined_mask = context::undefined().mask; 270 300 271 301 std::string prefix = this->getLevelName(level) + ": "; -
code/trunk/src/libraries/util/output/OutputManager.h
r8858 r9550 43 43 44 44 #include "OutputDefinitions.h" 45 #include "AdditionalContextListener.h" 45 46 46 47 namespace orxonox … … 61 62 Additionally OutputManager is used to register output contexts. 62 63 */ 63 class _UtilExport OutputManager 64 class _UtilExport OutputManager : public AdditionalContextListener 64 65 { 65 66 public: 67 OutputManager(); 68 OutputManager(const OutputManager&); 69 virtual ~OutputManager(); 70 66 71 static OutputManager& getInstance(); 67 72 static OutputManager& getInstanceAndCreateListeners(); 68 73 69 void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message); 74 inline MemoryWriter* getMemoryWriter() { return this->memoryWriterInstance_; } 75 inline ConsoleWriter* getConsoleWriter() { return this->consoleWriterInstance_; } 76 inline LogWriter* getLogWriter() { return this->logWriterInstance_; } 70 77 71 void registerListener(OutputListener* listener); 72 void unregisterListener(OutputListener* listener); 78 virtual void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message); 73 79 74 void updateMasks(); 75 void updateCombinedLevelMask(); 76 void updateCombinedAdditionalContextsLevelMask(); 77 void updateCombinedAdditionalContextsMask(); 80 virtual void registerListener(OutputListener* listener); 81 virtual void unregisterListener(OutputListener* listener); 82 83 virtual void updatedLevelMask(const OutputListener* listener) 84 { this->updateCombinedLevelMask(); } 85 virtual void updatedAdditionalContextsLevelMask(const OutputListener* listener) 86 { this->updateCombinedAdditionalContextsLevelMask(); } 87 virtual void updatedAdditionalContextsMask(const OutputListener* listener) 88 { this->updateCombinedAdditionalContextsMask(); } 78 89 79 90 /** … … 95 106 std::string getDefaultPrefix(OutputLevel level, const OutputContextContainer& context) const; 96 107 108 inline const std::vector<OutputListener*>& getListeners() const 109 { return this->listeners_; } 110 111 inline OutputLevel getCombinedLevelMask() const { return this->combinedLevelMask_; } 112 inline OutputLevel getCombinedAdditionalContextsLevelMask() const { return this->combinedAdditionalContextsLevelMask_; } 113 inline OutputContextMask getCombinedAdditionalContextsMask() const { return this->combinedAdditionalContextsMask_; } 114 97 115 private: 98 OutputManager(); 99 OutputManager(const OutputManager&); 100 ~OutputManager(); 116 void updateMasks(); 117 void updateCombinedLevelMask(); 118 void updateCombinedAdditionalContextsLevelMask(); 119 void updateCombinedAdditionalContextsMask(); 101 120 102 121 std::vector<OutputListener*> listeners_; ///< List of all registered output listeners … … 109 128 std::map<std::string, OutputContextContainer> contextContainers_; ///< Contains all contexts including sub-contexts and their containers 110 129 OutputContextSubID subcontextCounter_; ///< Counts the number of sub-contexts (and generates their IDs) 130 131 bool isInitialized_; ///< Becomes true once the following instances were created 132 MemoryWriter* memoryWriterInstance_; ///< The main instance of MemoryWriter, managed by OutputManager 133 ConsoleWriter* consoleWriterInstance_; ///< The main instance of ConsoleWriter, managed by OutputManager 134 LogWriter* logWriterInstance_; ///< The main instance of LogWriter, managed by OutputManager 135 136 public: 137 struct _UtilExport Testing 138 { 139 static SharedPtr<OutputManager>& getInstancePointer(); 140 }; 111 141 }; 112 142 } -
code/trunk/src/libraries/util/output/OutputStream.h
r8858 r9550 102 102 } 103 103 104 inline const OutputLevel getOutputLevel() const { return this->level_; } 105 inline const OutputContextContainer* getOutputContext() const { return this->context_; } 106 inline bool acceptsOutput() const { return this->bAcceptsOutput_; } 107 104 108 private: 105 109 /// @brief Generic function to add values to the output stream, using the inherited << operator from std::ostringstream. -
code/trunk/src/libraries/util/output/SubcontextOutputListener.h
r8858 r9550 73 73 virtual ~SubcontextOutputListener(); 74 74 75 v oid setAdditionalContextsMask(OutputContextMask mask);75 virtual void setAdditionalContextsMask(OutputContextMask mask); 76 76 void setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts); 77 77 78 78 virtual bool acceptsOutput(OutputLevel level, const OutputContextContainer& context) const; 79 80 inline const std::set<OutputContextSubID>& getSubcontexts() const 81 { return this->subcontexts_; } 79 82 80 83 private: -
code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc
r7489 r9550 117 117 const std::string& CommandNotification::bindingNiceifyer(const std::string& binding) 118 118 { 119 SubString s tring = SubString(binding, ".");119 SubString substring = SubString(binding, "."); 120 120 std::string name; 121 121 std::string group; 122 switch(s tring.size())122 switch(substring.size()) 123 123 { 124 124 case 0: … … 127 127 return binding; 128 128 case 2: 129 group = s tring[0];129 group = substring[0]; 130 130 default: 131 name = s tring.subSet(1, string.size()).join(".");131 name = substring.subSet(1).join("."); 132 132 } 133 133 … … 148 148 return *(new std::string(stream.str())); 149 149 } 150 150 151 151 } -
code/trunk/src/orxonox/LevelManager.cc
r8891 r9550 65 65 if (!CommandLineParser::getArgument("level")->hasDefaultValue()) 66 66 { 67 ModifyConfigValue(defaultLevelName_, tset, CommandLineParser::getValue("level").get String());67 ModifyConfigValue(defaultLevelName_, tset, CommandLineParser::getValue("level").get<std::string>()); 68 68 } 69 69 -
code/trunk/src/orxonox/Main.cc
r8858 r9550 68 68 orxout(user_status) << "Finished initialization" << endl; 69 69 70 if (CommandLineParser::getValue("generateDoc").get String().empty())70 if (CommandLineParser::getValue("generateDoc").get<std::string>().empty()) 71 71 { 72 72 orxout(internal_info) << "preparing game states" << endl; … … 86 86 87 87 // Some development hacks (not really, but in the future, these calls won't make sense anymore) 88 if (CommandLineParser::getValue("standalone").get Bool())88 if (CommandLineParser::getValue("standalone").get<bool>()) 89 89 Game::getInstance().requestStates("graphics, standalone, level"); 90 else if (CommandLineParser::getValue("server").get Bool())90 else if (CommandLineParser::getValue("server").get<bool>()) 91 91 Game::getInstance().requestStates("graphics, server, level"); 92 else if (CommandLineParser::getValue("client").get Bool())92 else if (CommandLineParser::getValue("client").get<bool>()) 93 93 Game::getInstance().requestStates("graphics, client, level"); 94 else if (CommandLineParser::getValue("dedicated").get Bool())94 else if (CommandLineParser::getValue("dedicated").get<bool>()) 95 95 Game::getInstance().requestStates("server, level"); 96 else if (CommandLineParser::getValue("dedicatedClient").get Bool())96 else if (CommandLineParser::getValue("dedicatedClient").get<bool>()) 97 97 Game::getInstance().requestStates("client, level"); 98 98 /* ADD masterserver command */ 99 else if (CommandLineParser::getValue("masterserver").get Bool())99 else if (CommandLineParser::getValue("masterserver").get<bool>()) 100 100 Game::getInstance().requestStates("masterserver"); 101 101 else 102 102 { 103 if (!CommandLineParser::getValue("console").get Bool())103 if (!CommandLineParser::getValue("console").get<bool>()) 104 104 Game::getInstance().requestStates("graphics, mainMenu"); 105 105 } -
code/trunk/src/orxonox/graphics/ParticleEmitter.cc
r8858 r9550 71 71 SUPER(ParticleEmitter, XMLPort, xmlelement, mode); 72 72 73 XMLPortParam(ParticleEmitter, "lod", setLODxml, getLODxml, xmlelement, mode).defaultValues( LODParticle::Normal);73 XMLPortParam(ParticleEmitter, "lod", setLODxml, getLODxml, xmlelement, mode).defaultValues(static_cast<unsigned int>(LODParticle::Normal)); 74 74 XMLPortParam(ParticleEmitter, "source", setSource, getSource, xmlelement, mode); 75 75 } -
code/trunk/src/orxonox/overlays/InGameConsole.cc
r8858 r9550 47 47 #include "util/ScopedSingletonManager.h" 48 48 #include "util/output/MemoryWriter.h" 49 #include "util/output/OutputManager.h" 49 50 #include "core/CoreIncludes.h" 50 51 #include "core/ConfigValueIncludes.h" … … 95 96 // Output buffering is not anymore needed. Not the best solution to do 96 97 // this here, but there isn't much of another way. 97 MemoryWriter::getInstance().disable();98 OutputManager::getInstance().getMemoryWriter()->disable(); 98 99 } 99 100
Note: See TracChangeset
for help on using the changeset viewer.