Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7424 for sandbox_qt


Ignore:
Timestamp:
Sep 12, 2010, 2:48:11 PM (14 years ago)
Author:
rgrieder
Message:

Added CommandlineParser again and adjusted it to work with QVariant instead of MultiType.
Also removed obsolete Game class.

Location:
sandbox_qt
Files:
2 deleted
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • sandbox_qt/doc/api/CMakeLists.txt

    r7401 r7424  
    5555    OUTPUT ${INTERNAL_DOCFILE}
    5656    COMMAND orxonox-main
    57     ARGS --noIOConsole --generateDoc ${INTERNAL_DOCFILE}
     57    ARGS --generateDoc ${INTERNAL_DOCFILE}
    5858    WORKING_DIRECTORY ${_working_dir}
    5959    COMMENT "Generating additional Doxygen documentation from Orxonox executable"
  • sandbox_qt/src/libraries/core/CMakeLists.txt

    r7421 r7424  
    1919
    2020SET_SOURCE_FILES(CORE_SRC_FILES
     21  CommandlineParser.cc
    2122  Core.cc
    22   Game.cc
    2323  PathConfig.cc
    2424)
  • sandbox_qt/src/libraries/core/CommandLineParser.cc

    r7418 r7424  
    3232#include <sstream>
    3333
    34 #include "util/Convert.h"
     34//#include "util/Convert.h"
    3535#include "util/Debug.h"
    3636#include "util/Exception.h"
     
    5454        if (bParsingFile && this->bCommandLineOnly_)
    5555            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
    6168            {
    6269                this->bHasDefaultValue_ = false;
    6370                this->value_ = temp;
    6471            }
    65             else if (value.empty())
    66             {
    67                 this->bHasDefaultValue_ = false;
    68                 this->value_ = true;
    69             }
    70             else
    71                 ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");
    72         }
    73         else
    74         {
    75             if (!value_.setValue(value))
    76             {
    77                 value_.setValue(defaultValue_);
    78                 ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");
    79             }
    80             else
    81                 this->bHasDefaultValue_ = false;
    8272        }
    8373    }
     
    302292                infoStr << "      ";
    303293            infoStr << "--" << it->second->getName() << ' ';
    304             if (it->second->getValue().getType() != MT_Type::Bool)
     294            if (it->second->getValue().type() != QVariant::Bool)
    305295                infoStr << "ARG ";
    306296            else
     
    362352    void CommandLineParser::_parseFile()
    363353    {
    364         const std::string& filename = CommandLineParser::getValue("optionsFile").getString();
     354        const std::string& filename = CommandLineParser::getValue("optionsFile").toString().toStdString();
    365355
    366356        // look for additional arguments in given file or start.ini as default
  • sandbox_qt/src/libraries/core/CommandLineParser.h

    r7418 r7424  
    4646#include <fstream>
    4747#include <map>
     48#include <QVariant>
    4849#include "util/OrxAssert.h"
    49 #include "util/MultiType.h"
    5050
    5151#define SetCommandLineArgument(name, defaultValue) \
     
    6767    /**
    6868    @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.
    7070
    7171        Whenever you want to have an option specified by a command line switch,
     
    106106
    107107        //! Returns the actual value of the argument. Can be equal to default value.
    108         MultiType getValue() const { return value_; }
     108        QVariant getValue() const { return value_; }
    109109        //! Returns the given default value as type T.
    110         MultiType getDefaultValue() const { return defaultValue_; }
     110        QVariant getDefaultValue() const { return defaultValue_; }
    111111
    112112    private:
    113113        //! 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)
    115115            : bHasDefaultValue_(true)
    116116            , name_(name)
     
    135135        std::string usageInformation_; //!< Tells about the usage of this parameter
    136136
    137         MultiType   value_;            //!< The actual value
    138         MultiType   defaultValue_;     //!< Default value. Should not be changed.
     137        QVariant    value_;            //!< The actual value
     138        QVariant    defaultValue_;     //!< Default value. Should not be changed.
    139139        bool        bCommandLineOnly_; //!< Whether you cannot specify the value in a text file
    140140    };
     
    165165        static void getValue(const std::string& name, T* value)
    166166        { *value = (T)(getArgument(name)->getValue()); }
    167         static MultiType getValue(const std::string& name)
     167        static QVariant getValue(const std::string& name)
    168168        { return getArgument(name)->getValue(); }
    169169        template <class T>
     
    211211    inline void CommandLineParser::getValue<std::string>(const std::string& name, std::string* value)
    212212    {
    213         *value = getArgument(name)->getValue().getString();
     213        *value = getArgument(name)->getValue().toString().toStdString();
    214214    }
    215215
     
    230230        OrxAssert(!_getInstance().existsArgument(name),
    231231            "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,
    233233               "Boolean command line arguments with positive default values are not supported." << std::endl
    234234            << "Please use SetCommandLineSwitch and adjust your argument: " << name);
  • sandbox_qt/src/libraries/core/Core.cc

    r7421 r7424  
    5353#include "util/Exception.h"
    5454#include "PathConfig.h"
     55#include "CommandLineParser.h"
    5556
    5657namespace orxonox
     
    5960    Core* Core::singletonPtr_s  = 0;
    6061
     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
    6168    Core::Core(const std::string& cmdLine)
    6269    {
    6370        // Set the hard coded fixed paths
    6471        this->pathConfig_.reset(new PathConfig());
     72
     73        // Parse command line arguments
     74        CommandLineParser::parseCommandLine(cmdLine);
    6575
    6676        // Set configurable paths like log, config and media
     
    7080        OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString());
    7181
     82        // Parse additional options file now that we know its path
     83        CommandLineParser::parseFile();
     84
    7285#ifdef ORXONOX_PLATFORM_WINDOWS
    7386        // 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();
    7588        if (limitToCPU > 0)
    7689            setThreadAffinity(static_cast<unsigned int>(limitToCPU));
     
    7891
    7992        // Generate documentation instead of normal run?
    80         std::string docFilename;
    81         //CommandLineParser::getValue("generateDoc", &docFilename);
     93        std::string docFilename = CommandLineParser::getValue("generateDoc").toString().toStdString();
    8294        if (!docFilename.empty())
    8395        {
     
    8597            if (docFile.is_open())
    8698            {
    87                 //CommandLineParser::generateDoc(docFile);
     99                CommandLineParser::generateDoc(docFile);
    88100                docFile.close();
    89101            }
  • sandbox_qt/src/libraries/core/Core.h

    r7421 r7424  
    8383            void initRandomNumberGenerator();
    8484
    85             void update() {}
    86 
    8785            void setThreadAffinity(int limitToCPU);
    8886            // MANAGED SINGLETONS/OBJECTS
  • sandbox_qt/src/orxonox/Main.cc

    r7423 r7424  
    3939#include <QCoreApplication>
    4040
    41 #include "core/Game.h"
     41#include "util/Debug.h"
     42#include "core/CommandlineParser.h"
     43#include "core/Core.h"
    4244#include "Main.h"
    4345
    4446namespace orxonox
    4547{
     48    SetCommandLineArgument(generateDoc, "")
     49        .information("Generates a Doxygen file from things like SetConsoleCommand");
     50
    4651    /**
    4752    @brief
     
    5257        QApplication app(argc, argv);
    5358
     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
    5464        QCoreApplication::setOrganizationName("");
    5565        QCoreApplication::setOrganizationDomain("");
    5666        QCoreApplication::setApplicationName("");
    5767
    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;
    6272    }
    6373}
Note: See TracChangeset for help on using the changeset viewer.