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,2021, 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
52 #include "gromacs/options/abstractoption.h"
53 #include "gromacs/utility/classhelpers.h"
59 class OptionSectionInfo;
63 class OptionSectionImpl;
66 /*! \libinternal \brief
67 * Pure interface for visiting options in a Options object.
69 * \see OptionsIterator
72 * \ingroup module_options
77 virtual ~OptionsVisitor() {}
79 //! Called for each section.
80 virtual void visitSection(const OptionSectionInfo& section) = 0;
81 //! Called for each option.
82 virtual void visitOption(const OptionInfo& option) = 0;
85 /*! \libinternal \brief
86 * Abstract base class for visiting options of a particular type.
88 * \see OptionsIterator
92 * \ingroup module_options
94 template<class InfoType>
95 class OptionsTypeVisitor : public OptionsVisitor
98 ~OptionsTypeVisitor() override {}
100 void visitSection(const OptionSectionInfo& section) override = 0;
102 * Called for each option of type \p InfoType.
104 virtual void visitOptionType(const InfoType& option) = 0;
107 void visitOption(const OptionInfo& option) override
109 const InfoType* subtype = option.toType<InfoType>();
112 visitOptionType(*subtype);
117 /*! \libinternal \brief
118 * Decorator class for visiting options in a Options object.
120 * This class provides an interface for looping through sections and
121 * options in a Options object.
123 * Typical use (loop over all options, iteratively descending into
126 class Visitor : public gmx::OptionsVisitor
129 virtual void visitSection(const OptionSectionInfo §ion)
131 OptionsIterator iterator(section);
132 iterator.acceptSections(this);
133 iterator.acceptOptions(this);
136 virtual void visitOption(const OptionInfo &option)
142 Visitor().visitSection(options.rootSection());
146 * \ingroup module_options
148 class OptionsIterator
152 * Creates an object for visiting options in a Options object.
154 * The created iterator iterates over the "root" section in the Options
157 explicit OptionsIterator(const Options& options);
158 //! Creates an object for visiting options in an options section.
159 explicit OptionsIterator(const OptionSectionInfo& section);
161 //! Visits each section in the wrapped section.
162 void acceptSections(OptionsVisitor* visitor) const;
163 //! Visits each option in the wrapped section.
164 void acceptOptions(OptionsVisitor* visitor) const;
167 //! The wrapped section object.
168 const internal::OptionSectionImpl& section_;
170 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsIterator);
173 /*! \libinternal \brief
174 * Pure interface for visiting options in a Options object, allowing
177 * \see OptionsModifyingIterator
180 * \ingroup module_options
182 class OptionsModifyingVisitor
185 virtual ~OptionsModifyingVisitor() {}
187 //! Called for each section.
188 virtual void visitSection(OptionSectionInfo* section) = 0;
189 //! Called for each option.
190 virtual void visitOption(OptionInfo* option) = 0;
193 /*! \libinternal \brief
194 * Abstract base class for visiting options of a particular type, allowing
197 * \see OptionsModifyingIterator
198 * \see OptionsModifyingVisitor
201 * \ingroup module_options
203 template<class InfoType>
204 class OptionsModifyingTypeVisitor : public OptionsModifyingVisitor
207 ~OptionsModifyingTypeVisitor() override {}
209 void visitSection(OptionSectionInfo* section) override = 0;
211 * Called for each option of type \p InfoType.
213 virtual void visitOptionType(InfoType* option) = 0;
216 void visitOption(OptionInfo* option) override
218 InfoType* subtype = option->toType<InfoType>();
219 if (subtype != nullptr)
221 visitOptionType(subtype);
226 /*! \libinternal \brief
227 * Decorator class for visiting options in a Options object, allowing changes.
229 * This class works exactly like OptionsIterator, except that it uses
230 * OptionsModifyingVisitor interface, which allows modifying the options.
232 * \see OptionsIterator
235 * \ingroup module_options
237 class OptionsModifyingIterator
241 * Creates an object for visiting options in a Options object.
243 * The created iterator iterates over the "root" section in the Options
246 explicit OptionsModifyingIterator(Options* options);
247 //! Creates an object for visiting options in an options section.
248 explicit OptionsModifyingIterator(OptionSectionInfo* section);
250 //! Visits each section in the wrapped section.
251 void acceptSections(OptionsModifyingVisitor* visitor) const;
252 //! Visits each option in the wrapped section.
253 void acceptOptions(OptionsModifyingVisitor* visitor) const;
256 //! The wrapped section object.
257 internal::OptionSectionImpl& section_;
259 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsModifyingIterator);