Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10345


Ignore:
Timestamp:
Apr 5, 2015, 5:32:40 PM (10 years ago)
Author:
landauf
Message:

wrap CommandLineArguments in StaticallyInitializedInstances

Location:
code/branches/core7/src
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/Core.cc

    r10343 r10345  
    6060#include "util/SignalHandler.h"
    6161#include "PathConfig.h"
    62 #include "commandline/CommandLineParser.h"
     62#include "commandline/CommandLineIncludes.h"
    6363#include "config/ConfigFileManager.h"
    6464#include "config/ConfigValueIncludes.h"
     
    140140        }
    141141
     142        // TODO: initialize CommandLineParser here
    142143        ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances();
    143144
  • code/branches/core7/src/libraries/core/PathConfig.cc

    r10343 r10345  
    5353#include "util/Output.h"
    5454#include "util/Exception.h"
    55 #include "commandline/CommandLineParser.h"
     55#include "commandline/CommandLineIncludes.h"
    5656
    5757// Differentiate Boost Filesystem v2 and v3
  • code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc

    r10343 r10345  
    338338        }
    339339    }
     340
     341    /**
     342    @brief
     343        Adds a new CommandLineArgument to the internal map.
     344        Note that only such arguments are actually valid.
     345    */
     346    void CommandLineParser::addArgument(CommandLineArgument* argument)
     347    {
     348        OrxAssert(!_getInstance().existsArgument(argument->getName()),
     349            "Cannot add a command line argument with name '" + argument->getName() + "' twice.");
     350        OrxAssert(!argument->getDefaultValue().isType<bool>() || argument->getDefaultValue().get<bool>() != true,
     351               "Boolean command line arguments with positive default values are not supported." << endl
     352            << "Please use SetCommandLineSwitch and adjust your argument: " << argument->getName());
     353
     354        _getInstance().cmdLineArgs_[argument->getName()] = argument;
     355    }
    340356}
  • code/branches/core7/src/libraries/core/commandline/CommandLineParser.h

    r10343 r10345  
    4949#include "util/MultiType.h"
    5050
    51 #define SetCommandLineArgument(name, defaultValue) \
    52     orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
    53     = orxonox::CommandLineParser::addArgument(#name, defaultValue)
    54 #define SetCommandLineSwitch(name) \
    55     orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
    56     = orxonox::CommandLineParser::addArgument(#name, false)
    57 
    5851namespace orxonox
    5952{
     
    8073
    8174    public:
     75        //! Constructor initialises both value_ and defaultValue_ with defaultValue.
     76        CommandLineArgument(const std::string& name, const MultiType& defaultValue)
     77            : bHasDefaultValue_(true)
     78            , name_(name)
     79            , value_(defaultValue)
     80            , defaultValue_(defaultValue)
     81        { }
     82        ~CommandLineArgument() { }
     83
    8284        //! Tells whether the value has been changed by the command line.
    8385        bool hasDefaultValue() const { return bHasDefaultValue_; }
     
    104106
    105107    private:
    106         //! Constructor initialises both value_ and defaultValue_ with defaultValue.
    107         CommandLineArgument(const std::string& name, const MultiType& defaultValue)
    108             : bHasDefaultValue_(true)
    109             , name_(name)
    110             , value_(defaultValue)
    111             , defaultValue_(defaultValue)
    112         { }
    113 
    114108        //! Undefined copy constructor
    115109        CommandLineArgument(const CommandLineArgument& instance);
    116         ~CommandLineArgument() { }
    117110
    118111        //! Parses the value string of a command line argument.
     
    158151        static const MultiType& getValue(const std::string& name)
    159152        { return getArgument(name)->getValue(); }
    160         template <class T>
    161         static CommandLineArgument& addArgument(const std::string& name, T defaultValue);
     153        static void addArgument(CommandLineArgument* argument);
    162154
    163155        static bool existsArgument(const std::string& name)
     
    202194        *value = getArgument(name)->getValue().get<std::string>();
    203195    }
    204 
    205     /**
    206     @brief
    207         Adds a new CommandLineArgument to the internal map.
    208         Note that only such arguments are actually valid.
    209     @param name
    210         Name of the argument. Shortcut can be added later.
    211     @param defaultValue
    212         Default value that is used when argument was not given.
    213     */
    214     template <class T>
    215     CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue)
    216     {
    217         OrxAssert(!_getInstance().existsArgument(name),
    218             "Cannot add a command line argument with name '" + name + "' twice.");
    219         OrxAssert(!MultiType(defaultValue).isType<bool>() || MultiType(defaultValue).get<bool>() != true,
    220                "Boolean command line arguments with positive default values are not supported." << endl
    221             << "Please use SetCommandLineSwitch and adjust your argument: " << name);
    222 
    223         return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue));
    224     }
    225196}
    226197
  • code/branches/core7/src/libraries/core/input/InputManager.cc

    r10343 r10345  
    4848#include "core/GraphicsManager.h"
    4949#include "core/config/ConfigValueIncludes.h"
    50 #include "core/commandline/CommandLineParser.h"
     50#include "core/commandline/CommandLineIncludes.h"
    5151#include "core/command/ConsoleCommand.h"
    5252#include "core/command/Functor.h"
  • code/branches/core7/src/orxonox/LevelManager.cc

    r10343 r10345  
    3737
    3838#include "util/ScopedSingletonManager.h"
    39 #include "core/commandline/CommandLineParser.h"
     39#include "core/commandline/CommandLineIncludes.h"
    4040#include "core/config/ConfigValueIncludes.h"
    4141#include "core/CoreIncludes.h"
  • code/branches/core7/src/orxonox/Main.cc

    r10343 r10345  
    3636#include "Main.h"
    3737
    38 #include "core/commandline/CommandLineParser.h"
     38#include "core/commandline/CommandLineIncludes.h"
    3939#include "core/Game.h"
    4040#include "core/LuaState.h"
  • code/branches/core7/src/orxonox/gamestates/GSClient.cc

    r10343 r10345  
    3030
    3131#include "util/Exception.h"
    32 #include "core/commandline/CommandLineParser.h"
     32#include "core/commandline/CommandLineIncludes.h"
    3333#include "core/Game.h"
    3434#include "core/GameMode.h"
  • code/branches/core7/src/orxonox/gamestates/GSServer.cc

    r10343 r10345  
    3030
    3131#include "util/Output.h"
    32 #include "core/commandline/CommandLineParser.h"
     32#include "core/commandline/CommandLineIncludes.h"
    3333#include "core/Game.h"
    3434#include "core/GameMode.h"
Note: See TracChangeset for help on using the changeset viewer.