Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / options / filenameoptionmanager.h
index 24853ce7b75861bbbe1290591495abc3af1d5b00..0fd50ceec80a86631e466e349e55e42a0c91d176 100644 (file)
 
 #include <string>
 
-#include "../utility/common.h"
+#include "gromacs/options/options.h"
+#include "gromacs/utility/common.h"
 
 namespace gmx
 {
 
+class FileNameOptionInfo;
 class Options;
 
 /*! \brief
  * Handles interaction of file name options with global options.
  *
- * Currently, this class implements support for a global default file name
- * that overrides any option-specific default.
+ * This class contains all logic that completes file names based on user input
+ * and file system contents.  Additionally, this class implements support for a
+ * global default file name that overrides any option-specific default, as well
+ * as additional control over how the completion is done.
  *
  * \todo
- * Currently, this class has very little logic, and just provides the global
- * values to FileNameOptionStorage implementation.  A cleaner design would have
- * most of the non-trivial file name completion logic in this class, so that
- * the customizations would be centralized here.
+ * Most of the functionality in this class is specific to command line parsing,
+ * so it would be cleaner to replace this with an interface, and have the
+ * actual code in the `commandline` module.
  *
- * Creating a FileNameOptionManager for an Options object is optional, even if
+ * Adding a FileNameOptionManager for an Options object is optional, even if
  * the Options contains FileNameOption options.  Features from the manager are
- * not available if the manager is not created, but otherwise the options work.
+ * not available if the manager is not created, but otherwise the options work:
+ * the values provided to FileNameOption are used as they are, and exceptions
+ * are thrown if they are no valid instead of attempting to complete them.
  *
- * \see setManagerForFileNameOptions()
+ * \see Options::addManager()
  *
  * \inpublicapi
  * \ingroup module_selection
  */
-class FileNameOptionManager
+class FileNameOptionManager : public OptionManagerInterface
 {
     public:
         FileNameOptionManager();
-        ~FileNameOptionManager();
+        virtual ~FileNameOptionManager();
+
+        /*! \brief
+         * Disables special input file option handling.
+         *
+         * If disabled, this removes all file system calls from the file
+         * name option parsing.
+         * The values returned by FileNameOption for input and input/output
+         * files are handled with the same simple rule as for output files:
+         * the default extension is added if the file does not end in a
+         * recognized extension, and no other checking is done.
+         *
+         * This changes the following behavior:
+         *  - Providing non-existent files does not trigger errors.
+         *  - Extensions for input files are not completed to an existing file.
+         *  - Compressed input files do not work.
+         */
+        void disableInputOptionChecking(bool bDisable);
 
         /*! \brief
          * Adds an option for setting the default global file name.
@@ -93,8 +115,41 @@ class FileNameOptionManager
          */
         void addDefaultFileNameOption(Options *options, const char *name);
 
-        //! Returns the currently set default file name.
-        const std::string &defaultFileName() const;
+        /*! \brief
+         * Completes file name option values.
+         *
+         * \param[in] value  Value provided by the user.
+         * \param[in] option Option for which the value should be completed.
+         * \returns   Value for the file name option.
+         * \throws    std::bad_alloc if out of memory.
+         * \throws    InvalidInputError if the value is not valid for this
+         *     option.
+         *
+         * This method is called for each value that the user provides to
+         * a FileNameOption.  The return value (if non-empty) is used as the
+         * value of the option instead of the user-provided one.
+         */
+        std::string completeFileName(const std::string        &value,
+                                     const FileNameOptionInfo &option);
+        /*! \brief
+         * Completes default values for file name options.
+         *
+         * \param[in] prefix Default prefix for the file name.
+         * \param[in] option Option for which the value should be completed.
+         * \returns   Value for the file name option.
+         * \throws    std::bad_alloc if out of memory.
+         * \throws    InvalidInputError if the value is not valid for this
+         *     option.
+         *
+         * This method is called for each FileNameOption that has a default
+         * value (either a standard default value, or if the user provided the
+         * option without an explicit value).  \p prefix is the default value
+         * without the default extension for the option.
+         * If the return value is non-empty, it is used as the default value
+         * for the option instead of \p prefix + default extension.
+         */
+        std::string completeDefaultFileName(const std::string        &prefix,
+                                            const FileNameOptionInfo &option);
 
     private:
         class Impl;
@@ -102,20 +157,6 @@ class FileNameOptionManager
         PrivateImplPointer<Impl> impl_;
 };
 
-/*! \brief
- * Set manager for all file name options.
- *
- * Recursively sets the manager to \p manager for all file name options in
- * \p options.
- * Must be called before value assignment starts for \p options.
- *
- * Does not throw.
- *
- * \inpublicapi
- */
-void setManagerForFileNameOptions(Options               *options,
-                                  FileNameOptionManager *manager);
-
 } // namespace gmx
 
 #endif