2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2015, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Declares gmx::IOptionsContainer.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_options
43 #ifndef GMX_OPTIONS_IOPTIONSCONTAINER_H
44 #define GMX_OPTIONS_IOPTIONSCONTAINER_H
46 #include "gromacs/options/abstractoption.h"
47 #include "gromacs/utility/gmxassert.h"
53 * Interface for adding input options.
55 * This interface provides methods to add new options.
56 * Standard usage is for code to receive this interface and populate it with
59 // <as class attributes>
63 void MyClass::initOptions(gmx::IOptionsContainer *options)
65 options->addOption(gmx::StringOption("arg1").store(&arg1));
66 options->addOption(gmx::IntegerOption("arg2").store(&arg2));
69 * The caller can collect options from multiple sources into a single container
70 * (a gmx::Options), and use a parser implementation such as CommandLineParser
71 * to provide values for the options.
73 * Header basicoptions.h provides declarations of several standard
74 * option types for use with addOption(). Documentation of those classes
75 * also give more examples of how to define options.
78 * \ingroup module_options
80 class IOptionsContainer
84 * Adds a recognized option.
86 * \param[in] settings Option description.
87 * \returns OptionInfo object for the created option (never NULL).
88 * \throws APIError if invalid option settings are provided.
90 * This method provides the internal implementation, but in most cases
91 * the templated method is called from user code.
92 * See the templated method for more details.
94 virtual OptionInfo *addOption(const AbstractOption &settings) = 0;
96 * Adds a recognized option.
98 * \tparam OptionType Type of the options description object.
99 * \param[in] settings Option description.
100 * \returns OptionInfo object for the created option (never NULL).
101 * \throws APIError if invalid option settings are provided.
103 * The return value is a pointer for more convenient use in callers:
104 * often callers need to declare the variable that will hold the return
105 * value in wider scope than would be achieved by declaring it at the
106 * site where addOption() is called.
107 * The returned pointer must not be freed.
109 * See \link Options class documentation \endlink for example usage.
112 * \p OptionType::InfoType must specify a type that derives from
113 * OptionInfo and matches the type that is returned by
114 * AbstractOptionStorage::optionInfo() for the storage object that
115 * corresponds to \p OptionType.
117 template <class OptionType>
118 typename OptionType::InfoType *addOption(const OptionType &settings)
121 = addOption(static_cast<const AbstractOption &>(settings));
122 GMX_ASSERT(info->isType<typename OptionType::InfoType>(),
123 "Mismatching option info type declaration and implementation");
124 return info->toType<typename OptionType::InfoType>();
128 // Disallow deletion through the interface.
129 // (no need for the virtual, but some compilers warn otherwise)
130 virtual ~IOptionsContainer();