128-bit AVX2 SIMD for AMD Ryzen
[gromacs.git] / src / gromacs / options / options-impl.h
blobd06ffb48d30a29c84e942f863a9a96f640cf7595
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014,2015,2016, 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.
35 /*! \internal \file
36 * \brief
37 * Declares private implementation class for gmx::Options.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_options
42 #ifndef GMX_OPTIONS_OPTIONS_IMPL_H
43 #define GMX_OPTIONS_OPTIONS_IMPL_H
45 #include <list>
46 #include <map>
47 #include <memory>
48 #include <string>
49 #include <vector>
51 #include "gromacs/options/abstractoption.h"
52 #include "gromacs/options/abstractoptionstorage.h"
53 #include "gromacs/options/ioptionscontainer.h"
54 #include "gromacs/options/ioptionscontainerwithsections.h"
55 #include "gromacs/options/isectionstorage.h"
56 #include "gromacs/options/optionmanagercontainer.h"
57 #include "gromacs/options/options.h"
58 #include "gromacs/options/optionsection.h"
60 namespace gmx
63 namespace internal
66 /*! \internal
67 * \brief
68 * Internal implementation class for storing an option section.
70 * All options are stored within a section: the top-level contents of an
71 * Options object are handled within an unnamed, "root" section.
72 * This class handles the common functionality for all sections, related to
73 * storing the options and subsections. Functionality specific to a section
74 * type is provided by IOptionSectionStorage.
76 * \ingroup module_options
78 class OptionSectionImpl : public IOptionsContainerWithSections
80 public:
81 /*! \internal \brief
82 * Describes a group of options (see Options::addGroup()).
84 * \ingroup module_options
86 class Group : public IOptionsContainer
88 public:
89 //! Convenience typedef for list of options.
90 typedef std::vector<AbstractOptionStorage *> OptionList;
91 //! Convenience typedef for list of subgroups.
92 typedef std::list<Group> SubgroupList;
94 //! Creates a group within the given Options.
95 explicit Group(OptionSectionImpl *parent) : parent_(parent) {}
97 // From IOptionsContainer
98 virtual IOptionsContainer &addGroup();
99 virtual OptionInfo *addOptionImpl(const AbstractOption &settings);
101 //! Containing options object.
102 OptionSectionImpl *parent_;
103 /*! \brief
104 * List of options, in insertion order.
106 * Pointers in this container point to the objects managed by
107 * Impl::optionsMap_.
109 OptionList options_;
110 //! List of groups, in insertion order.
111 SubgroupList subgroups_;
114 //! Smart pointer for managing an AbstractOptionStorage object.
115 typedef std::unique_ptr<AbstractOptionStorage>
116 AbstractOptionStoragePointer;
117 //! Convenience typedef for a map that contains all the options.
118 typedef std::map<std::string, AbstractOptionStoragePointer> OptionMap;
119 //! Smart pointer for managing subsections.
120 typedef std::unique_ptr<OptionSectionImpl> SectionPointer;
121 //! Convenience typedef for a container for subsections.
122 typedef std::vector<SectionPointer> SectionList;
124 //! Creates storage for a new section.
125 OptionSectionImpl(const OptionManagerContainer &managers,
126 std::unique_ptr<IOptionSectionStorage> storage,
127 const char *name)
128 : managers_(managers), storage_(std::move(storage)), info_(this),
129 name_(name), rootGroup_(this), storageInitialized_(false)
133 // From IOptionsContainerWithSections
134 virtual OptionSectionImpl *addSectionImpl(const AbstractOptionSection &section);
136 // From IOptionsContainer
137 virtual IOptionsContainer &addGroup();
138 virtual OptionInfo *addOptionImpl(const AbstractOption &settings);
140 //! Returns section info object for this section.
141 OptionSectionInfo &info() { return info_; }
142 //! Returns section info object for this section.
143 const OptionSectionInfo &info() const { return info_; }
145 /*! \brief
146 * Finds a subsection by name.
148 * \param[in] name Name to search for.
149 * \returns Pointer to the found subsection, or NULL if not found.
151 * Does not throw.
153 OptionSectionImpl *findSection(const char *name) const;
154 /*! \brief
155 * Finds an option by name.
157 * \param[in] name Name to search for.
158 * \returns Pointer to the found option, or NULL if not found.
160 * Does not throw.
162 AbstractOptionStorage *findOption(const char *name) const;
164 /*! \brief
165 * Called when entering the section.
167 * Calls AbstractOptionStorage::startSource() for all options.
169 void start();
170 /*! \brief
171 * Calls AbstractOptionStorage::finish() for all options.
173 void finish();
175 //! Reference to the option managers in the parent Options object.
176 const OptionManagerContainer &managers_;
177 //! Type-specific storage object for this section.
178 std::unique_ptr<IOptionSectionStorage> storage_;
179 //! Info object for this section.
180 OptionSectionInfo info_;
181 //! Name of this section (empty and unused for the root section).
182 std::string name_;
183 /*! \brief
184 * Group that contains all options (and subgroups).
186 * This is used to store the insertion order of options.
188 Group rootGroup_;
189 //! Map from option names to options; owns the option storage objects.
190 OptionMap optionMap_;
191 //! List of subsections, in insertion order.
192 SectionList subsections_;
193 //! Whether initStorage() has been called for `storage_`.
194 bool storageInitialized_;
196 GMX_DISALLOW_COPY_AND_ASSIGN(OptionSectionImpl);
199 /*! \internal
200 * \brief
201 * Private implementation class for Options.
203 * Note that in addition to Options, the OptionsAssigner class also directly
204 * accesses this class.
206 * \ingroup module_options
208 class OptionsImpl
210 public:
211 OptionsImpl();
213 //! Option managers set for this collection.
214 OptionManagerContainer managers_;
215 //! Root section for this collection.
216 OptionSectionImpl rootSection_;
219 } // namespace internal
221 } // namespace gmx
223 #endif