2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010-2018, The GROMACS development team.
5 * Copyright (c) 2019, 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.
38 * Declares private implementation class for gmx::Options.
40 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_options
43 #ifndef GMX_OPTIONS_OPTIONS_IMPL_H
44 #define GMX_OPTIONS_OPTIONS_IMPL_H
52 #include "gromacs/options/abstractoption.h"
53 #include "gromacs/options/abstractoptionstorage.h"
54 #include "gromacs/options/ioptionscontainer.h"
55 #include "gromacs/options/ioptionscontainerwithsections.h"
56 #include "gromacs/options/optionmanagercontainer.h"
57 #include "gromacs/options/options.h"
58 #include "gromacs/options/optionsection.h"
60 #include "isectionstorage.h"
70 * Internal implementation class for storing an option section.
72 * All options are stored within a section: the top-level contents of an
73 * Options object are handled within an unnamed, "root" section.
74 * This class handles the common functionality for all sections, related to
75 * storing the options and subsections. Functionality specific to a section
76 * type is provided by IOptionSectionStorage.
78 * \ingroup module_options
80 class OptionSectionImpl : public IOptionsContainerWithSections
84 * Describes a group of options (see Options::addGroup()).
86 * \ingroup module_options
88 class Group : public IOptionsContainer
91 //! Convenience typedef for list of options.
92 typedef std::vector<AbstractOptionStorage*> OptionList;
93 //! Convenience typedef for list of subgroups.
94 typedef std::list<Group> SubgroupList;
96 //! Creates a group within the given Options.
97 explicit Group(OptionSectionImpl* parent) : parent_(parent) {}
99 // From IOptionsContainer
100 IOptionsContainer& addGroup() override;
101 OptionInfo* addOptionImpl(const AbstractOption& settings) override;
103 //! Containing options object.
104 OptionSectionImpl* parent_;
106 * List of options, in insertion order.
108 * Pointers in this container point to the objects managed by
112 //! List of groups, in insertion order.
113 SubgroupList subgroups_;
116 //! Smart pointer for managing an AbstractOptionStorage object.
117 typedef std::unique_ptr<AbstractOptionStorage> AbstractOptionStoragePointer;
118 //! Convenience typedef for a map that contains all the options.
119 typedef std::map<std::string, AbstractOptionStoragePointer> OptionMap;
120 //! Smart pointer for managing subsections.
121 typedef std::unique_ptr<OptionSectionImpl> SectionPointer;
122 //! Convenience typedef for a container for subsections.
123 typedef std::vector<SectionPointer> SectionList;
125 //! Creates storage for a new section.
126 OptionSectionImpl(const OptionManagerContainer& managers,
127 std::unique_ptr<IOptionSectionStorage> storage,
130 storage_(std::move(storage)),
134 storageInitialized_(false)
138 // From IOptionsContainerWithSections
139 OptionSectionImpl* addSectionImpl(const AbstractOptionSection& section) override;
141 // From IOptionsContainer
142 IOptionsContainer& addGroup() override;
143 OptionInfo* addOptionImpl(const AbstractOption& settings) override;
145 //! Returns section info object for this section.
146 OptionSectionInfo& info() { return info_; }
147 //! Returns section info object for this section.
148 const OptionSectionInfo& info() const { return info_; }
151 * Finds a subsection by name.
153 * \param[in] name Name to search for.
154 * \returns Pointer to the found subsection, or NULL if not found.
158 OptionSectionImpl* findSection(const char* name) const;
160 * Finds an option by name.
162 * \param[in] name Name to search for.
163 * \returns Pointer to the found option, or NULL if not found.
167 AbstractOptionStorage* findOption(const char* name) const;
170 * Called when entering the section.
172 * Calls AbstractOptionStorage::startSource() for all options.
176 * Calls AbstractOptionStorage::finish() for all options.
180 //! Reference to the option managers in the parent Options object.
181 const OptionManagerContainer& managers_;
182 //! Type-specific storage object for this section.
183 std::unique_ptr<IOptionSectionStorage> storage_;
184 //! Info object for this section.
185 OptionSectionInfo info_;
186 //! Name of this section (empty and unused for the root section).
189 * Group that contains all options (and subgroups).
191 * This is used to store the insertion order of options.
194 //! Map from option names to options; owns the option storage objects.
195 OptionMap optionMap_;
196 //! List of subsections, in insertion order.
197 SectionList subsections_;
198 //! Whether initStorage() has been called for `storage_`.
199 bool storageInitialized_;
201 GMX_DISALLOW_COPY_AND_ASSIGN(OptionSectionImpl);
206 * Private implementation class for Options.
208 * Note that in addition to Options, the OptionsAssigner class also directly
209 * accesses this class.
211 * \ingroup module_options
218 //! Option managers set for this collection.
219 OptionManagerContainer managers_;
220 //! Root section for this collection.
221 OptionSectionImpl rootSection_;
224 } // namespace internal