Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 12, 2009, 11:58:01 PM (15 years ago)
Author:
rgrieder
Message:

Merged most of the core4 revisions back to the trunk except for:

  • orxonox_cast
  • all the radical changes in the input library
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/CommandLine.h

    r3196 r3280  
    3838#define SetCommandLineArgument(name, defaultValue) \
    3939    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
    40     = orxonox::CommandLine::addArgument(#name, defaultValue)
     40    = orxonox::CommandLine::addArgument(#name, defaultValue, false)
     41#define SetCommandLineOnlyArgument(name, defaultValue) \
     42    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
     43    = orxonox::CommandLine::addArgument(#name, defaultValue, true)
    4144#define SetCommandLineSwitch(name) \
    4245    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
    43     = orxonox::CommandLine::addArgument(#name, false)
     46    = orxonox::CommandLine::addArgument(#name, false, false)
     47#define SetCommandLineOnlySwitch(name) \
     48    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
     49    = orxonox::CommandLine::addArgument(#name, false, true)
    4450
    4551
     
    7480
    7581        //! Returns the shortcut (example: "-p 22" for "--port 22") of the argument.
    76         //! Evaluates to "" if none there is none.
     82        //! Evaluates to "" if there is none.
    7783        const std::string& getShortcut() const { return shortcut_; }
    7884        //! Sets the shortcut for the argument
     
    9399    private:
    94100        //! Constructor initialises both value_ and defaultValue_ with defaultValue.
    95         CommandLineArgument(const std::string& name, const MultiType& defaultValue)
     101        CommandLineArgument(const std::string& name, const MultiType& defaultValue, bool bCommandLineOnly)
    96102            : bHasDefaultValue_(true)
    97103            , name_(name)
    98104            , value_(defaultValue)
    99105            , defaultValue_(defaultValue)
     106            , bCommandLineOnly_(bCommandLineOnly)
    100107        { }
    101108
     
    105112
    106113        //! Parses the value string of a command line argument.
    107         void parse(const std::string& value);
     114        void parse(const std::string& value, bool bParsingFile);
    108115
    109116        //! Tells whether the value has been changed by the command line.
     
    115122        std::string usageInformation_; //!< Tells about the usage of this parameter
    116123
    117         MultiType value_;            //!< The actual value
    118         MultiType defaultValue_;     //!< Default value. Should not be changed.
     124        MultiType   value_;            //!< The actual value
     125        MultiType   defaultValue_;     //!< Default value. Should not be changed.
     126        bool        bCommandLineOnly_; //!< Whether you cannot specify the value in a text file
    119127    };
    120128
     
    134142
    135143        //! Parse redirection to internal member method.
    136         static void parseAll(int argc, char** argv) { _getInstance()._parseAll(argc, argv); }
     144        static void parseCommandLine(int argc, char** argv) { _getInstance()._parseCommandLine(argc, argv); }
     145        static void parseFile() { _getInstance()._parseFile(); }
    137146
    138147        static std::string getUsageInformation();
     
    146155        { return getArgument(name)->getValue(); }
    147156        template <class T>
    148         static CommandLineArgument& addArgument(const std::string& name, T defaultValue);
     157        static CommandLineArgument& addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly);
    149158
    150159        static bool existsArgument(const std::string& name)
     
    165174        static CommandLine& _getInstance();
    166175
    167         void _parseAll(int argc, char** argv);
    168         void _parse(const std::vector<std::string>& arguments);
    169         void checkFullArgument(const std::string& name, const std::string& value);
    170         void checkShortcut(const std::string& shortcut, const std::string& value);
     176        void _parseCommandLine(int argc, char** argv);
     177        void _parseFile();
     178        void _parse(const std::vector<std::string>& arguments, bool bParsingFile);
     179        void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile);
     180        void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile);
    171181
    172182        /**
     
    199209    */
    200210    template <class T>
    201     CommandLineArgument& CommandLine::addArgument(const std::string& name, T defaultValue)
     211    CommandLineArgument& CommandLine::addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly)
    202212    {
    203213        OrxAssert(!_getInstance().existsArgument(name),
    204214            "Cannot add a command line argument with name '" + name + "' twice.");
    205 
    206         return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue));
     215        OrxAssert(MultiType(defaultValue).getType() != MT_Type::Bool || MultiType(defaultValue).getBool() != true,
     216               "Boolean command line arguments with positive default values are not supported." << std::endl
     217            << "Please use SetCommandLineSwitch and adjust your argument: " << name);
     218
     219        return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue, bCommandLineOnly));
    207220    }
    208221}
Note: See TracChangeset for help on using the changeset viewer.