Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / options / abstractoption.h
index 5282a147b61959b676c0d54e6979f0f6c5ba296d..2793f2f0faa3e19a5fd99cc73b6937bbbab2a5da 100644 (file)
@@ -1,32 +1,36 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
- *                 G   R   O   M   A   C   S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
  *
- *          GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \file
  * \brief
@@ -43,7 +47,7 @@
  * but methods of OptionTemplate are visible even to the normal user through
  * its subclasses.
  *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inlibraryapi
  * \ingroup module_options
  */
 #include <string>
 #include <vector>
 
-#include "../utility/common.h"
-#include "../utility/uniqueptr.h"
-
-#include "optionflags.h"
+#include "gromacs/options/optionflags.h"
+#include "gromacs/utility/common.h"
 
 namespace gmx
 {
 
 class AbstractOptionStorage;
 template <typename T> class OptionStorageTemplate;
+class OptionManagerContainer;
 class Options;
 
-//! Smart pointer for managing an AbstractOptionStorage object.
-typedef gmx_unique_ptr<AbstractOptionStorage>::type
-        AbstractOptionStoragePointer;
-
 /*! \brief
  * Abstract base class for specifying option properties.
  *
@@ -104,8 +103,10 @@ class AbstractOption
         /*! \brief
          * Creates a default storage object for the option.
          *
-         * \returns The created storage object.
-         * \throws  APIError if invalid option settings have been provided.
+         * \param[in] managers  Manager container (unused if the option does
+         *     not use a manager).
+         * \returns   The created storage object.
+         * \throws    APIError if invalid option settings have been provided.
          *
          * This method is called by Options::addOption() when initializing an
          * option from the settings.
@@ -115,22 +116,16 @@ class AbstractOption
          * They should also throw APIError if they detect problems.
          *
          * Should only be called by Options::addOption().
-         */
-        virtual AbstractOptionStoragePointer createStorage() const = 0;
-
-        /*! \brief
-         * Creates the description string for the option.
          *
-         * \returns Description string for the option.
-         *
-         * This function is virtual to allow derived classes to customize the
-         * description programmatically, e.g., by adding the list of allowed
-         * values.
-         * The default implementation simply returns the user-provided
-         * description.
+         * The ownership of the return value is passed, but is not using a
+         * smart pointer to avoid introducing such a dependency in an installed
+         * header.  The implementation will always consist of a single `new`
+         * call and returning that value, and the caller always immediately
+         * wraps the pointer in a smart pointer, so there is not exception
+         * safety issue.
          */
-        virtual std::string createDescription() const
-        { return descr_ ? descr_ : ""; }
+        virtual AbstractOptionStorage *createStorage(
+            const OptionManagerContainer &managers) const = 0;
 
         //! Sets the description for the option.
         void setDescription(const char *descr) { descr_ = descr; }
@@ -209,8 +204,8 @@ class AbstractOption
  *
  * This template is used as a base class like this:
  * \code
-class ConcreteOption : public OptionTemplate<int, ConcreteOption>
-{
+   class ConcreteOption : public OptionTemplate<int, ConcreteOption>
+   {
  * \endcode
  *
  * All public functions in this class return \c *this casted to a reference to
@@ -258,7 +253,8 @@ class OptionTemplate : public AbstractOption
         //! Requires exactly \p count values for the option.
         MyClass &valueCount(int count) { setValueCount(count); return me(); }
         //! Allows any number of values for the option.
-        MyClass &multiValue() { maxValueCount_ = -1; return me(); }
+        MyClass &multiValue(bool bMulti = true)
+        { if (bMulti) { maxValueCount_ = -1; } return me(); }
 
         /*! \brief
          * Sets a default value for the option.
@@ -451,16 +447,16 @@ class OptionInfo
         bool isHidden() const;
         //! Returns true if the option is required.
         bool isRequired() const;
+        //! Returns the minimum number of values that this option accepts.
+        int minValueCount() const;
+        //! Returns the maximum number of values that this option accepts.
+        int maxValueCount() const;
         //! Returns the name of the option.
         const std::string &name() const;
-        //! Returns the description of the option.
-        const std::string &description() const;
         //! Returns the type of the option as a string.
-        const char *type() const;
-        //! Returns the number of values given for the option.
-        int valueCount() const;
-        //! Returns the i'th value of the option as a string.
-        std::string formatValue(int i) const;
+        std::string type() const;
+        //! Returns the description of the option.
+        std::string formatDescription() const;
         /*! \brief
          * Returns the default value if set for the option as a string.
          *
@@ -468,6 +464,11 @@ class OptionInfo
          */
         std::string formatDefaultValueIfSet() const;
 
+        //! Returns the number of values given for the option.
+        int valueCount() const;
+        //! Returns the i'th value of the option as a string.
+        std::string formatValue(int i) const;
+
     protected:
         /*! \cond libapi */
         /*! \brief
@@ -478,7 +479,7 @@ class OptionInfo
         explicit OptionInfo(AbstractOptionStorage *option);
 
         //! Returns the wrapped option storage object.
-        AbstractOptionStorage &option() { return option_; }
+        AbstractOptionStorage       &option() { return option_; }
         //! Returns the wrapped option storage object.
         const AbstractOptionStorage &option() const { return option_; }
         //! \endcond