Update instructions in containers.rst
[gromacs.git] / src / gromacs / options / options.h
blob69dcb4c52570ab7ad0043b550107555bc7355968
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2014,2015 by the GROMACS development team.
5 * Copyright (c) 2016,2018,2019,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
36 /*! \file
37 * \brief
38 * Declares gmx::Options.
40 * Together with basicoptions.h, this header forms the part of the public
41 * API that most classes will use to provide options.
43 * \author Teemu Murtola <teemu.murtola@gmail.com>
44 * \inpublicapi
45 * \ingroup module_options
47 #ifndef GMX_OPTIONS_OPTIONS_H
48 #define GMX_OPTIONS_OPTIONS_H
50 #include <string>
52 #include "gromacs/options/ioptionscontainerwithsections.h"
53 #include "gromacs/utility/classhelpers.h"
55 namespace gmx
58 class AbstractOption;
59 class OptionSection;
60 class OptionSectionInfo;
61 class OptionsAssigner;
63 namespace internal
65 class OptionsImpl;
68 /*! \brief
69 * Base class for option managers.
71 * This class is used as a marker for all classes that are used with
72 * Options::addManager(). It doesn't provide any methods, but only supports
73 * transporting these classes through the Options collection into the
74 * individual option implementation classes.
76 * The virtual destructor is present to make this class polymorphic, such that
77 * `dynamic_cast` can be used when retrieving a manager of a certain type for
78 * the individual options.
80 * \inlibraryapi
81 * \ingroup module_options
83 class IOptionManager
85 protected:
86 virtual ~IOptionManager();
89 /*! \brief
90 * Collection of options.
92 * See \ref module_options for an overview of how the options work.
93 * The IOptionsContainerWithSections interface documents how to add options.
95 * In order to keep the public interface of this class simple, functionality
96 * to assign values to options is provided by a separate OptionsAssigner class.
97 * Similarly, functionality for looping over all options (e.g., for writing out
98 * help) is provided by OptionsIterator.
100 * \inpublicapi
101 * \ingroup module_options
103 class Options : public IOptionsContainerWithSections
105 public:
106 //! Initializes an empty options root container.
107 Options();
108 ~Options() override;
110 /*! \brief
111 * Adds an option manager.
113 * \param manager Manager to add.
114 * \throws std::bad_alloc if out of memory.
116 * Option managers are used by some types of options that require
117 * interaction between different option instances (e.g., selection
118 * options), or need to support globally set properties (e.g., a global
119 * default file prefix). Option objects can retrieve the pointer to
120 * their manager when they are created, and the caller can alter the
121 * behavior of the options through the manager.
122 * See the individual managers for details.
124 * Caller is responsible for memory management of \p manager.
125 * The Options object (and its contained options) only stores a
126 * reference to the object.
128 * This method cannot be called after adding options or sections.
130 void addManager(IOptionManager* manager);
132 // From IOptionsContainer
133 IOptionsContainer& addGroup() override;
135 //! Returns a handle to the root section.
136 OptionSectionInfo& rootSection();
137 //! Returns a handle to the root section.
138 const OptionSectionInfo& rootSection() const;
140 /*! \brief
141 * Notifies the collection that all option values are assigned.
143 * \throws InvalidInputError if invalid user input is detected.
145 * This function should be called after no more option values are
146 * to be assigned. Values in storage variables are guaranteed to be
147 * available only after this call, although in most cases, they are
148 * available already during assignment.
150 * If invalid option values, e.g., missing required option, is detected
151 * at this point, this function throws. The thrown exception contains
152 * information on all errors detected during the call.
154 void finish();
156 private:
157 // From IOptionsContainerWithSections
158 internal::OptionSectionImpl* addSectionImpl(const AbstractOptionSection& section) override;
159 // From IOptionsContainer
160 OptionInfo* addOptionImpl(const AbstractOption& settings) override;
162 PrivateImplPointer<internal::OptionsImpl> impl_;
164 //! Needed to be able to extend the interface of this object.
165 friend class OptionsAssigner;
168 } // namespace gmx
170 #endif