Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / commandline / cmdlinemodulemanager-impl.h
index 7612920cd0044b50a70b26ade957ca1a5926249f..847b623a751ecec3ef51df615de3dc839b1b6c3e 100644 (file)
 #include <string>
 #include <vector>
 
-#include "cmdlinemodule.h"
-#include "cmdlinemodulemanager.h"
-
+#include "gromacs/commandline/cmdlinemodule.h"
+#include "gromacs/commandline/cmdlinemodulemanager.h"
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/options/options.h"
 #include "gromacs/utility/common.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/uniqueptr.h"
 
 namespace gmx
 {
+
+//! \addtogroup module_commandline
+//! \{
+
 //! Container type for mapping module names to module objects.
 typedef std::map<std::string, CommandLineModulePointer> CommandLineModuleMap;
 
@@ -65,8 +70,6 @@ typedef std::map<std::string, CommandLineModulePointer> CommandLineModuleMap;
  * This class contains the state of a module group.  CommandLineModuleGroup
  * provides the public interface to construct/alter the state, and
  * CommandLineModuleManager and its associated classes use it for help output.
- *
- * \ingroup module_commandline
  */
 class CommandLineModuleGroupData
 {
@@ -83,15 +86,17 @@ class CommandLineModuleGroupData
         /*! \brief
          * Constructs an empty module group.
          *
-         * \param[in] modules  List of all modules
+         * \param[in] modules     List of all modules
          *     (used for checking and default descriptions).
-         * \param[in] title    Title of the group.
+         * \param[in] binaryName  Name of the binary containing the modules.
+         * \param[in] title       Title of the group.
          *
          * Does not throw.
          */
         CommandLineModuleGroupData(const CommandLineModuleMap &modules,
+                                   const char                 *binaryName,
                                    const char                 *title)
-            : allModules_(modules), title_(title)
+            : allModules_(modules), binaryName_(binaryName), title_(title)
         {
         }
 
@@ -114,6 +119,7 @@ class CommandLineModuleGroupData
 
     private:
         const CommandLineModuleMap &allModules_;
+        const char                 *binaryName_;
         const char                 *title_;
         ModuleList                  modules_;
 
@@ -127,6 +133,80 @@ typedef gmx_unique_ptr<CommandLineModuleGroupData>::type
 typedef std::vector<CommandLineModuleGroupDataPointer>
     CommandLineModuleGroupList;
 
+/*! \internal
+ * \brief
+ * Encapsulates some handling of common options to the wrapper binary.
+ */
+class CommandLineCommonOptionsHolder
+{
+    public:
+        CommandLineCommonOptionsHolder();
+        ~CommandLineCommonOptionsHolder();
+
+        //! Initializes the common options.
+        void initOptions();
+        /*! \brief
+         * Finishes option parsing.
+         *
+         * \returns `false` if the wrapper binary should quit without executing
+         *     any module.
+         */
+        bool finishOptions();
+
+        //! Adjust defaults based on module settings.
+        void adjustFromSettings(const CommandLineModuleSettings &settings);
+
+        //! Returns the internal Options object.
+        Options *options() { return &options_; }
+        //! Returns the settings for printing startup information.
+        const BinaryInformationSettings &binaryInfoSettings() const
+        {
+            return binaryInfoSettings_;
+        }
+
+        /*! \brief
+         * Returns `true` if common options are set such that the wrapper
+         * binary should quit, without running the actual module.
+         */
+        bool shouldIgnoreActualModule() const
+        {
+            return bHelp_ || bVersion_;
+        }
+        //! Returns whether common options specify showing help.
+        bool shouldShowHelp() const { return bHelp_; }
+        //! Returns whether common options specify showing hidden options in help.
+        bool shouldShowHidden() const { return bHidden_; }
+        //! Returns whether common options specify quiet execution.
+        bool shouldBeQuiet() const
+        {
+            return bQuiet_ && !bVersion_;
+        }
+
+        //! Returns the nice level.
+        int niceLevel() const { return niceLevel_; }
+        //! Returns the debug level.
+        int debugLevel() const { return debugLevel_; }
+
+        //! Returns the file to which startup information should be printed.
+        FILE *startupInfoFile() const { return (bVersion_ ? stdout : stderr); }
+
+    private:
+        Options                      options_;
+        //! Settings for what to write in the startup header.
+        BinaryInformationSettings    binaryInfoSettings_;
+        bool                         bHelp_;
+        bool                         bHidden_;
+        bool                         bQuiet_;
+        bool                         bVersion_;
+        bool                         bCopyright_;
+        int                          niceLevel_;
+        int                          debugLevel_;
+
+        GMX_DISALLOW_COPY_AND_ASSIGN(CommandLineCommonOptionsHolder);
+};
+
+//! \}
+
 } // namespace gmx
 
 #endif