[Orxonox-commit 3844] r8520 - code/branches/unity_build/src/libraries/core

rgrieder at orxonox.net rgrieder at orxonox.net
Fri May 20 05:51:21 CEST 2011


Author: rgrieder
Date: 2011-05-20 05:51:21 +0200 (Fri, 20 May 2011)
New Revision: 8520

Modified:
   code/branches/unity_build/src/libraries/core/CommandLineParser.cc
   code/branches/unity_build/src/libraries/core/CommandLineParser.h
   code/branches/unity_build/src/libraries/core/Core.cc
   code/branches/unity_build/src/libraries/core/PathConfig.cc
Log:
Removed useless and possibly confusion feature: specifying a file with additional command line arguments.
If we ever have too many command line arguments, then something is wrong anyway. And configuring a dedicated server should be done with config values (but a different file).
In general, always prefer config values to CommandLineArguments.

Modified: code/branches/unity_build/src/libraries/core/CommandLineParser.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/CommandLineParser.cc	2011-05-20 03:27:39 UTC (rev 8519)
+++ code/branches/unity_build/src/libraries/core/CommandLineParser.cc	2011-05-20 03:51:21 UTC (rev 8520)
@@ -40,8 +40,6 @@
 
 namespace orxonox
 {
-    SetCommandLineOnlyArgument(optionsFile, "start.ini").shortcut("o");
-
     /**
     @brief
         Parses a value string for a command line argument.
@@ -49,10 +47,8 @@
         Bools are treated specially. That is necessary
         so that you can have simple command line switches.
     */
-    void CommandLineArgument::parse(const std::string& value, bool bParsingFile)
+    void CommandLineArgument::parse(const std::string& value)
     {
-        if (bParsingFile && this->bCommandLineOnly_)
-            ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files.");
         if (value_.getType() == MT_Type::Bool)
         {
             // simulate command line switch
@@ -115,21 +111,21 @@
         _getInstance().cmdLineArgs_.clear();
     }
 
-    /**
-    @brief
-        Reads the command line parses the values of each argument.
-        It is then stored in the corresponding CommandLineArgument.
+    /** Parses the command line string for arguments and stores these.
     @note
         The reason that you have to provide the string to be parsed as
-        space separted list is because of argc and argv. If you only have
+        space separated list is because of argc and argv. If you only have
         a whole string, simply use getAllStrings() of SubString.
-    @param arguments
-        Vector of space separated strings.
-    @param bParsingFile
-        Parsing a file or the command line itself
+    @param cmdLine
+        Command line string WITHOUT the execution path.
     */
-    void CommandLineParser::_parse(const std::vector<std::string>& arguments, bool bParsingFile)
+    void CommandLineParser::_parse(const std::string& cmdLine)
     {
+        std::vector<std::string> arguments;
+        SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);
+        for (unsigned i = 0; i < tokens.size(); ++i)
+            arguments.push_back(tokens[i]);
+
         try
         {
             // why this? See bFirstTimeParse_ declaration.
@@ -176,13 +172,13 @@
                             value = removeTrailingWhitespaces(value);
                             if (!name.empty())
                             {
-                                checkFullArgument(name, value, bParsingFile);
+                                checkFullArgument(name, value);
                                 name.clear();
                                 assert(shortcut.empty());
                             }
                             else if (!shortcut.empty())
                             {
-                                checkShortcut(shortcut, value, bParsingFile);
+                                checkShortcut(shortcut, value);
                                 shortcut.clear();
                                 assert(name.empty());
                             }
@@ -221,18 +217,18 @@
             value = removeTrailingWhitespaces(value);
             if (!name.empty())
             {
-                checkFullArgument(name, value, bParsingFile);
+                checkFullArgument(name, value);
                 assert(shortcut.empty());
             }
             else if (!shortcut.empty())
             {
-                checkShortcut(shortcut, value, bParsingFile);
+                checkShortcut(shortcut, value);
                 assert(name.empty());
             }
         }
         catch (const ArgumentException& ex)
         {
-            COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
+            COUT(0) << "Could not parse command line: " << ex.what() << std::endl;
             COUT(0) << CommandLineParser::getUsageInformation() << std::endl;
             throw GeneralException("");
         }
@@ -248,13 +244,13 @@
     @param bParsingFile
         Parsing a file or the command line itself
     */
-    void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile)
+    void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value)
     {
         std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);
         if (it == cmdLineArgs_.end())
             ThrowException(Argument, "Command line argument '" + name + "' does not exist.");
 
-        it->second->parse(value, bParsingFile);
+        it->second->parse(value);
     }
 
     /**
@@ -267,13 +263,13 @@
     @param bParsingFile
         Parsing a file or the command line itself
     */
-    void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile)
+    void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value)
     {
         std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);
         if (it == cmdLineArgsShortcut_.end())
             ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist.");
 
-        it->second->parse(value, bParsingFile);
+        it->second->parse(value);
     }
 
     std::string CommandLineParser::getUsageInformation()
@@ -341,52 +337,4 @@
             return it->second;
         }
     }
-
-    /**
-    @brief
-        Parses only the command line for CommandLineArguments.
-    */
-    void CommandLineParser::_parseCommandLine(const std::string& cmdLine)
-    {
-        std::vector<std::string> args;
-        SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);
-        for (unsigned i = 0; i < tokens.size(); ++i)
-            args.push_back(tokens[i]);
-        this->_parse(args, false);
-    }
-
-    /**
-    @brief
-        Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.
-    */
-    void CommandLineParser::_parseFile()
-    {
-        const std::string& filename = CommandLineParser::getValue("optionsFile").getString();
-
-        // look for additional arguments in given file or start.ini as default
-        // They will not overwrite the arguments given directly
-        std::ifstream file;
-        file.open((PathConfig::getConfigPathString() + filename).c_str());
-        std::vector<std::string> args;
-        if (file)
-        {
-            while (!file.eof())
-            {
-                std::string line;
-                std::getline(file, line);
-                line = removeTrailingWhitespaces(line);
-                //if (!(line[0] == '#' || line[0] == '%'))
-                //{
-                SubString tokens(line, " ", " ", false, '\\', true, '"', true, '\0', '\0', false, '#');
-                for (unsigned i = 0; i < tokens.size(); ++i)
-                    if (tokens[i][0] != '#')
-                        args.push_back(tokens[i]);
-                //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());
-                //}
-            }
-            file.close();
-        }
-
-        _parse(args, true);
-    }
 }

Modified: code/branches/unity_build/src/libraries/core/CommandLineParser.h
===================================================================
--- code/branches/unity_build/src/libraries/core/CommandLineParser.h	2011-05-20 03:27:39 UTC (rev 8519)
+++ code/branches/unity_build/src/libraries/core/CommandLineParser.h	2011-05-20 03:51:21 UTC (rev 8520)
@@ -50,18 +50,11 @@
 
 #define SetCommandLineArgument(name, defaultValue) \
     orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, defaultValue, false)
-#define SetCommandLineOnlyArgument(name, defaultValue) \
-    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, defaultValue, true)
+    = orxonox::CommandLineParser::addArgument(#name, defaultValue)
 #define SetCommandLineSwitch(name) \
     orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, false, false)
-#define SetCommandLineOnlySwitch(name) \
-    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, false, true)
+    = orxonox::CommandLineParser::addArgument(#name, false)
 
-
 namespace orxonox
 {
     /**
@@ -111,12 +104,11 @@
 
     private:
         //! Constructor initialises both value_ and defaultValue_ with defaultValue.
-        CommandLineArgument(const std::string& name, const MultiType& defaultValue, bool bCommandLineOnly)
+        CommandLineArgument(const std::string& name, const MultiType& defaultValue)
             : bHasDefaultValue_(true)
             , name_(name)
             , value_(defaultValue)
             , defaultValue_(defaultValue)
-            , bCommandLineOnly_(bCommandLineOnly)
         { }
 
         //! Undefined copy constructor
@@ -124,7 +116,7 @@
         ~CommandLineArgument() { }
 
         //! Parses the value string of a command line argument.
-        void parse(const std::string& value, bool bParsingFile);
+        void parse(const std::string& value);
 
         //! Tells whether the value has been changed by the command line.
         bool bHasDefaultValue_;
@@ -136,7 +128,6 @@
 
         MultiType   value_;            //!< The actual value
         MultiType   defaultValue_;     //!< Default value. Should not be changed.
-        bool        bCommandLineOnly_; //!< Whether you cannot specify the value in a text file
     };
 
 
@@ -154,8 +145,8 @@
     public:
 
         //! Parse redirection to internal member method.
-        static void parseCommandLine(const std::string& cmdLine) { _getInstance()._parseCommandLine(cmdLine); }
-        static void parseFile() { _getInstance()._parseFile(); }
+        static void parse(const std::string& cmdLine)
+        { _getInstance()._parse(cmdLine); }
 
         static std::string getUsageInformation();
 
@@ -167,7 +158,7 @@
         static MultiType getValue(const std::string& name)
         { return getArgument(name)->getValue(); }
         template <class T>
-        static CommandLineArgument& addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly);
+        static CommandLineArgument& addArgument(const std::string& name, T defaultValue);
 
         static bool existsArgument(const std::string& name)
         {
@@ -188,11 +179,9 @@
 
         static CommandLineParser& _getInstance();
 
-        void _parseCommandLine(const std::string& cmdLine);
-        void _parseFile();
-        void _parse(const std::vector<std::string>& arguments, bool bParsingFile);
-        void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile);
-        void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile);
+        void _parse(const std::string& cmdLine);
+        void checkFullArgument(const std::string& name, const std::string& value);
+        void checkShortcut(const std::string& shortcut, const std::string& value);
 
         /**
             Tells whether we parsed for the first time. The CommmandLineArguments are added before main().
@@ -221,11 +210,9 @@
         Name of the argument. Shortcut can be added later.
     @param defaultValue
         Default value that is used when argument was not given.
-    @param bCommandLineOnly
-        Parsing a file or the command line itself
     */
     template <class T>
-    CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly)
+    CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue)
     {
         OrxAssert(!_getInstance().existsArgument(name),
             "Cannot add a command line argument with name '" + name + "' twice.");
@@ -233,7 +220,7 @@
                "Boolean command line arguments with positive default values are not supported." << std::endl
             << "Please use SetCommandLineSwitch and adjust your argument: " << name);
 
-        return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue, bCommandLineOnly));
+        return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue));
     }
 }
 

Modified: code/branches/unity_build/src/libraries/core/Core.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/Core.cc	2011-05-20 03:27:39 UTC (rev 8519)
+++ code/branches/unity_build/src/libraries/core/Core.cc	2011-05-20 03:51:21 UTC (rev 8520)
@@ -130,7 +130,7 @@
         }
 
         // Parse command line arguments AFTER the modules have been loaded (static code!)
-        CommandLineParser::parseCommandLine(cmdLine);
+        CommandLineParser::parse(cmdLine);
 
         // Set configurable paths like log, config and media
         this->pathConfig_->setConfigurablePaths();
@@ -143,9 +143,6 @@
         // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used
         OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString());
 
-        // Parse additional options file now that we know its path
-        CommandLineParser::parseFile();
-
 #ifdef ORXONOX_PLATFORM_WINDOWS
         // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
         // do this after ogre has initialised. Somehow Ogre changes the settings again (not through

Modified: code/branches/unity_build/src/libraries/core/PathConfig.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/PathConfig.cc	2011-05-20 03:27:39 UTC (rev 8519)
+++ code/branches/unity_build/src/libraries/core/PathConfig.cc	2011-05-20 03:51:21 UTC (rev 8520)
@@ -73,7 +73,7 @@
     PathConfig* PathConfig::singletonPtr_s  = 0;
 
     SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
-    SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
+    SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
 
     PathConfig::PathConfig()
         : rootPath_(*(new bf::path()))




More information about the Orxonox-commit mailing list