Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

wrap CommandLineArguments in StaticallyInitializedInstances

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.