2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2014,2016 by the GROMACS development team.
5 * Copyright (c) 2017,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 /*! \libinternal \file
38 * Declares gmx::OptionsVisitor interface and supporting classes.
40 * \author Teemu Murtola <teemu.murtola@gmail.com>
42 * \ingroup module_options
44 #ifndef GMX_OPTIONS_OPTIONSVISITOR_H
45 #define GMX_OPTIONS_OPTIONSVISITOR_H
51 #include "gromacs/options/abstractoption.h"
52 #include "gromacs/utility/classhelpers.h"
58 class OptionSectionInfo;
62 class OptionSectionImpl;
65 /*! \libinternal \brief
66 * Pure interface for visiting options in a Options object.
68 * \see OptionsIterator
71 * \ingroup module_options
76 virtual ~OptionsVisitor() {}
78 //! Called for each section.
79 virtual void visitSection(const OptionSectionInfo& section) = 0;
80 //! Called for each option.
81 virtual void visitOption(const OptionInfo& option) = 0;
84 /*! \libinternal \brief
85 * Abstract base class for visiting options of a particular type.
87 * \see OptionsIterator
91 * \ingroup module_options
93 template<class InfoType>
94 class OptionsTypeVisitor : public OptionsVisitor
97 ~OptionsTypeVisitor() override {}
99 void visitSection(const OptionSectionInfo& section) override = 0;
101 * Called for each option of type \p InfoType.
103 virtual void visitOptionType(const InfoType& option) = 0;
106 void visitOption(const OptionInfo& option) override
108 const InfoType* subtype = option.toType<InfoType>();
111 visitOptionType(*subtype);
116 /*! \libinternal \brief
117 * Decorator class for visiting options in a Options object.
119 * This class provides an interface for looping through sections and
120 * options in a Options object.
122 * Typical use (loop over all options, iteratively descending into
125 class Visitor : public gmx::OptionsVisitor
128 virtual void visitSection(const OptionSectionInfo §ion)
130 OptionsIterator iterator(section);
131 iterator.acceptSections(this);
132 iterator.acceptOptions(this);
135 virtual void visitOption(const OptionInfo &option)
141 Visitor().visitSection(options.rootSection());
145 * \ingroup module_options
147 class OptionsIterator
151 * Creates an object for visiting options in a Options object.
153 * The created iterator iterates over the "root" section in the Options
156 explicit OptionsIterator(const Options& options);
157 //! Creates an object for visiting options in an options section.
158 explicit OptionsIterator(const OptionSectionInfo& section);
160 //! Visits each section in the wrapped section.
161 void acceptSections(OptionsVisitor* visitor) const;
162 //! Visits each option in the wrapped section.
163 void acceptOptions(OptionsVisitor* visitor) const;
166 //! The wrapped section object.
167 const internal::OptionSectionImpl& section_;
169 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsIterator);
172 /*! \libinternal \brief
173 * Pure interface for visiting options in a Options object, allowing
176 * \see OptionsModifyingIterator
179 * \ingroup module_options
181 class OptionsModifyingVisitor
184 virtual ~OptionsModifyingVisitor() {}
186 //! Called for each section.
187 virtual void visitSection(OptionSectionInfo* section) = 0;
188 //! Called for each option.
189 virtual void visitOption(OptionInfo* option) = 0;
192 /*! \libinternal \brief
193 * Abstract base class for visiting options of a particular type, allowing
196 * \see OptionsModifyingIterator
197 * \see OptionsModifyingVisitor
200 * \ingroup module_options
202 template<class InfoType>
203 class OptionsModifyingTypeVisitor : public OptionsModifyingVisitor
206 ~OptionsModifyingTypeVisitor() override {}
208 void visitSection(OptionSectionInfo* section) override = 0;
210 * Called for each option of type \p InfoType.
212 virtual void visitOptionType(InfoType* option) = 0;
215 void visitOption(OptionInfo* option) override
217 InfoType* subtype = option->toType<InfoType>();
218 if (subtype != nullptr)
220 visitOptionType(subtype);
225 /*! \libinternal \brief
226 * Decorator class for visiting options in a Options object, allowing changes.
228 * This class works exactly like OptionsIterator, except that it uses
229 * OptionsModifyingVisitor interface, which allows modifying the options.
231 * \see OptionsIterator
234 * \ingroup module_options
236 class OptionsModifyingIterator
240 * Creates an object for visiting options in a Options object.
242 * The created iterator iterates over the "root" section in the Options
245 explicit OptionsModifyingIterator(Options* options);
246 //! Creates an object for visiting options in an options section.
247 explicit OptionsModifyingIterator(OptionSectionInfo* section);
249 //! Visits each section in the wrapped section.
250 void acceptSections(OptionsModifyingVisitor* visitor) const;
251 //! Visits each option in the wrapped section.
252 void acceptOptions(OptionsModifyingVisitor* visitor) const;
255 //! The wrapped section object.
256 internal::OptionSectionImpl& section_;
258 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsModifyingIterator);