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 * Base class for option managers.
55 * This class is used as a marker for all classes that are used with
56 * Options::addManager(). It doesn't provide any methods, but only supports
57 * transporting these classes through the Options collection into the
58 * individual option implementation classes.
60 * The virtual destructor is present to make this class polymorphic, such that
61 * `dynamic_cast` can be used when retrieving a manager of a certain type for
62 * the individual options.
65 * \ingroup module_options
70 virtual ~IOptionManager();
74 * Interface for adding input options.
76 * This interface provides methods to add new options.
77 * Standard usage is for code to receive this interface and populate it with
80 // <as class attributes>
84 void MyClass::initOptions(gmx::IOptionsContainer *options)
86 options->addOption(gmx::StringOption("arg1").store(&arg1));
87 options->addOption(gmx::IntegerOption("arg2").store(&arg2));
90 * The caller can collect options from multiple sources into a single container
91 * (a gmx::Options), and use a parser implementation such as CommandLineParser
92 * to provide values for the options.
94 * Header basicoptions.h provides declarations of several standard
95 * option types for use with addOption(). Documentation of those classes
96 * also give more examples of how to define options.
99 * \ingroup module_options
101 class IOptionsContainer
105 * Adds a recognized option.
107 * \param[in] settings Option description.
108 * \returns OptionInfo object for the created option (never NULL).
109 * \throws APIError if invalid option settings are provided.
111 * This method provides the internal implementation, but in most cases
112 * the templated method is called from user code.
113 * See the templated method for more details.
115 virtual OptionInfo *addOption(const AbstractOption &settings) = 0;
117 * Adds a recognized option.
119 * \tparam OptionType Type of the options description object.
120 * \param[in] settings Option description.
121 * \returns OptionInfo object for the created option (never NULL).
122 * \throws APIError if invalid option settings are provided.
124 * The return value is a pointer for more convenient use in callers:
125 * often callers need to declare the variable that will hold the return
126 * value in wider scope than would be achieved by declaring it at the
127 * site where addOption() is called.
128 * The returned pointer must not be freed.
130 * See \link Options class documentation \endlink for example usage.
133 * \p OptionType::InfoType must specify a type that derives from
134 * OptionInfo and matches the type that is returned by
135 * AbstractOptionStorage::optionInfo() for the storage object that
136 * corresponds to \p OptionType.
138 template <class OptionType>
139 typename OptionType::InfoType *addOption(const OptionType &settings)
142 = addOption(static_cast<const AbstractOption &>(settings));
143 GMX_ASSERT(info->isType<typename OptionType::InfoType>(),
144 "Mismatching option info type declaration and implementation");
145 return info->toType<typename OptionType::InfoType>();
149 * Adds an option manager.
151 * \param manager Manager to add.
152 * \throws std::bad_alloc if out of memory.
154 * Option managers are used by some types of options that require
155 * interaction between different option instances (e.g., selection
156 * options), or need to support globally set properties (e.g., a global
157 * default file prefix). Option objects can retrieve the pointer to
158 * their manager when they are created, and the caller can alter the
159 * behavior of the options through the manager.
160 * See the individual managers for details.
162 * Caller is responsible for memory management of \p manager.
163 * The Options object (and its contained options) only stores a
164 * reference to the object.
166 * This method cannot be called after adding options or subsections.
168 virtual void addManager(IOptionManager *manager) = 0;
171 * Creates a subgroup of options within the current options.
173 * To add options to the group, use the returned interface.
175 * Currently, this is only used to influence the order of options:
176 * all options in a group appear before options in a group added after
177 * it, no matter in which order the options are added to the groups.
178 * In the future, the groups could also be used to influence the help
181 virtual IOptionsContainer &addGroup() = 0;
183 // Disallow deletion through the interface.
184 // (no need for the virtual, but some compilers warn otherwise)
185 virtual ~IOptionsContainer();