Changeset 7424 for sandbox_qt/src
- Timestamp:
- Sep 12, 2010, 2:48:11 PM (14 years ago)
- Location:
- sandbox_qt/src
- Files:
-
- 2 deleted
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
sandbox_qt/src/libraries/core/CMakeLists.txt
r7421 r7424 19 19 20 20 SET_SOURCE_FILES(CORE_SRC_FILES 21 CommandlineParser.cc 21 22 Core.cc 22 Game.cc23 23 PathConfig.cc 24 24 ) -
sandbox_qt/src/libraries/core/CommandLineParser.cc
r7418 r7424 32 32 #include <sstream> 33 33 34 #include "util/Convert.h"34 //#include "util/Convert.h" 35 35 #include "util/Debug.h" 36 36 #include "util/Exception.h" … … 54 54 if (bParsingFile && this->bCommandLineOnly_) 55 55 ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files."); 56 if (value_.getType() == MT_Type::Bool) 57 { 58 // simulate command line switch 59 bool temp; 60 if (convertValue(&temp, value)) 56 if (value_.type() == QVariant::Bool) 57 { 58 // Command line switch activated 59 this->bHasDefaultValue_ = false; 60 this->value_ = true; 61 } 62 else 63 { 64 QVariant temp(QString::fromStdString(value)); 65 if (!temp.convert(value_.type())) 66 ThrowException(Argument, "Could not read command line argument '" + getName() + "'."); 67 else 61 68 { 62 69 this->bHasDefaultValue_ = false; 63 70 this->value_ = temp; 64 71 } 65 else if (value.empty())66 {67 this->bHasDefaultValue_ = false;68 this->value_ = true;69 }70 else71 ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");72 }73 else74 {75 if (!value_.setValue(value))76 {77 value_.setValue(defaultValue_);78 ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");79 }80 else81 this->bHasDefaultValue_ = false;82 72 } 83 73 } … … 302 292 infoStr << " "; 303 293 infoStr << "--" << it->second->getName() << ' '; 304 if (it->second->getValue(). getType() != MT_Type::Bool)294 if (it->second->getValue().type() != QVariant::Bool) 305 295 infoStr << "ARG "; 306 296 else … … 362 352 void CommandLineParser::_parseFile() 363 353 { 364 const std::string& filename = CommandLineParser::getValue("optionsFile"). getString();354 const std::string& filename = CommandLineParser::getValue("optionsFile").toString().toStdString(); 365 355 366 356 // look for additional arguments in given file or start.ini as default -
sandbox_qt/src/libraries/core/CommandLineParser.h
r7418 r7424 46 46 #include <fstream> 47 47 #include <map> 48 #include <QVariant> 48 49 #include "util/OrxAssert.h" 49 #include "util/MultiType.h"50 50 51 51 #define SetCommandLineArgument(name, defaultValue) \ … … 67 67 /** 68 68 @brief 69 Container class for a command line argument of any type supported by MultiType.69 Container class for a command line argument of any type supported by QVariant. 70 70 71 71 Whenever you want to have an option specified by a command line switch, … … 106 106 107 107 //! Returns the actual value of the argument. Can be equal to default value. 108 MultiTypegetValue() const { return value_; }108 QVariant getValue() const { return value_; } 109 109 //! Returns the given default value as type T. 110 MultiTypegetDefaultValue() const { return defaultValue_; }110 QVariant getDefaultValue() const { return defaultValue_; } 111 111 112 112 private: 113 113 //! Constructor initialises both value_ and defaultValue_ with defaultValue. 114 CommandLineArgument(const std::string& name, const MultiType& defaultValue, bool bCommandLineOnly)114 CommandLineArgument(const std::string& name, const QVariant& defaultValue, bool bCommandLineOnly) 115 115 : bHasDefaultValue_(true) 116 116 , name_(name) … … 135 135 std::string usageInformation_; //!< Tells about the usage of this parameter 136 136 137 MultiTypevalue_; //!< The actual value138 MultiTypedefaultValue_; //!< Default value. Should not be changed.137 QVariant value_; //!< The actual value 138 QVariant defaultValue_; //!< Default value. Should not be changed. 139 139 bool bCommandLineOnly_; //!< Whether you cannot specify the value in a text file 140 140 }; … … 165 165 static void getValue(const std::string& name, T* value) 166 166 { *value = (T)(getArgument(name)->getValue()); } 167 static MultiTypegetValue(const std::string& name)167 static QVariant getValue(const std::string& name) 168 168 { return getArgument(name)->getValue(); } 169 169 template <class T> … … 211 211 inline void CommandLineParser::getValue<std::string>(const std::string& name, std::string* value) 212 212 { 213 *value = getArgument(name)->getValue(). getString();213 *value = getArgument(name)->getValue().toString().toStdString(); 214 214 } 215 215 … … 230 230 OrxAssert(!_getInstance().existsArgument(name), 231 231 "Cannot add a command line argument with name '" + name + "' twice."); 232 OrxAssert( MultiType(defaultValue).getType() != MT_Type::Bool || MultiType(defaultValue).getBool() != true,232 OrxAssert(QVariant(defaultValue).type() != QVariant::Bool || QVariant(defaultValue).toBool() != true, 233 233 "Boolean command line arguments with positive default values are not supported." << std::endl 234 234 << "Please use SetCommandLineSwitch and adjust your argument: " << name); -
sandbox_qt/src/libraries/core/Core.cc
r7421 r7424 53 53 #include "util/Exception.h" 54 54 #include "PathConfig.h" 55 #include "CommandLineParser.h" 55 56 56 57 namespace orxonox … … 59 60 Core* Core::singletonPtr_s = 0; 60 61 62 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file"); 63 64 #ifdef ORXONOX_PLATFORM_WINDOWS 65 SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)"); 66 #endif 67 61 68 Core::Core(const std::string& cmdLine) 62 69 { 63 70 // Set the hard coded fixed paths 64 71 this->pathConfig_.reset(new PathConfig()); 72 73 // Parse command line arguments 74 CommandLineParser::parseCommandLine(cmdLine); 65 75 66 76 // Set configurable paths like log, config and media … … 70 80 OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString()); 71 81 82 // Parse additional options file now that we know its path 83 CommandLineParser::parseFile(); 84 72 85 #ifdef ORXONOX_PLATFORM_WINDOWS 73 86 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump 74 int limitToCPU = 0;//CommandLineParser::getValue("limitToCPU");87 int limitToCPU = CommandLineParser::getValue("limitToCPU").toInt(); 75 88 if (limitToCPU > 0) 76 89 setThreadAffinity(static_cast<unsigned int>(limitToCPU)); … … 78 91 79 92 // Generate documentation instead of normal run? 80 std::string docFilename; 81 //CommandLineParser::getValue("generateDoc", &docFilename); 93 std::string docFilename = CommandLineParser::getValue("generateDoc").toString().toStdString(); 82 94 if (!docFilename.empty()) 83 95 { … … 85 97 if (docFile.is_open()) 86 98 { 87 //CommandLineParser::generateDoc(docFile);99 CommandLineParser::generateDoc(docFile); 88 100 docFile.close(); 89 101 } -
sandbox_qt/src/libraries/core/Core.h
r7421 r7424 83 83 void initRandomNumberGenerator(); 84 84 85 void update() {}86 87 85 void setThreadAffinity(int limitToCPU); 88 86 // MANAGED SINGLETONS/OBJECTS -
sandbox_qt/src/orxonox/Main.cc
r7423 r7424 39 39 #include <QCoreApplication> 40 40 41 #include "core/Game.h" 41 #include "util/Debug.h" 42 #include "core/CommandlineParser.h" 43 #include "core/Core.h" 42 44 #include "Main.h" 43 45 44 46 namespace orxonox 45 47 { 48 SetCommandLineArgument(generateDoc, "") 49 .information("Generates a Doxygen file from things like SetConsoleCommand"); 50 46 51 /** 47 52 @brief … … 52 57 QApplication app(argc, argv); 53 58 59 QStringList arguments = QCoreApplication::arguments(); 60 if (!arguments.value(0).isEmpty() && arguments.value(0)[0] != '-') 61 arguments.pop_front(); // Remove application path 62 Core core(arguments.join(" ").toStdString()); 63 54 64 QCoreApplication::setOrganizationName(""); 55 65 QCoreApplication::setOrganizationDomain(""); 56 66 QCoreApplication::setApplicationName(""); 57 67 58 //if (CommandLineParser::getValue("generateDoc").getString().empty())59 60 return app.exec();61 //return 0;68 if (CommandLineParser::getValue("generateDoc").toString().isEmpty()) 69 return app.exec(); 70 else 71 return 0; 62 72 } 63 73 }
Note: See TracChangeset
for help on using the changeset viewer.