2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2014,2016,2017, 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 /*! \libinternal \file
37 * Declares gmx::OptionsVisitor interface and supporting classes.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_options
43 #ifndef GMX_OPTIONS_OPTIONSVISITOR_H
44 #define GMX_OPTIONS_OPTIONSVISITOR_H
50 #include "gromacs/options/abstractoption.h"
51 #include "gromacs/utility/classhelpers.h"
57 class OptionSectionInfo;
61 class OptionSectionImpl;
64 /*! \libinternal \brief
65 * Pure interface for visiting options in a Options object.
67 * \see OptionsIterator
70 * \ingroup module_options
75 virtual ~OptionsVisitor() {}
77 //! Called for each section.
78 virtual void visitSection(const OptionSectionInfo §ion) = 0;
79 //! Called for each option.
80 virtual void visitOption(const OptionInfo &option) = 0;
83 /*! \libinternal \brief
84 * Abstract base class for visiting options of a particular type.
86 * \see OptionsIterator
90 * \ingroup module_options
92 template <class InfoType>
93 class OptionsTypeVisitor : public OptionsVisitor
96 virtual ~OptionsTypeVisitor() {}
98 virtual void visitSection(const OptionSectionInfo §ion) = 0;
100 * Called for each option of type \p InfoType.
102 virtual void visitOptionType(const InfoType &option) = 0;
105 virtual void visitOption(const OptionInfo &option)
107 const InfoType *subtype = option.toType<InfoType>();
110 visitOptionType(*subtype);
115 /*! \libinternal \brief
116 * Decorator class for visiting options in a Options object.
118 * This class provides an interface for looping through sections and
119 * options in a Options object.
121 * Typical use (loop over all options, iteratively descending into
124 class Visitor : public gmx::OptionsVisitor
127 virtual void visitSection(const OptionSectionInfo §ion)
129 OptionsIterator iterator(section);
130 iterator.acceptSections(this);
131 iterator.acceptOptions(this);
134 virtual void visitOption(const OptionInfo &option)
140 Visitor().visitSection(options.rootSection());
144 * \ingroup module_options
146 class OptionsIterator
150 * Creates an object for visiting options in a Options object.
152 * The created iterator iterates over the "root" section in the Options
155 explicit OptionsIterator(const Options &options);
156 //! Creates an object for visiting options in an options section.
157 explicit OptionsIterator(const OptionSectionInfo §ion);
159 //! Visits each section in the wrapped section.
160 void acceptSections(OptionsVisitor *visitor) const;
161 //! Visits each option in the wrapped section.
162 void acceptOptions(OptionsVisitor *visitor) const;
165 //! The wrapped section object.
166 const internal::OptionSectionImpl §ion_;
168 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsIterator);
171 /*! \libinternal \brief
172 * Pure interface for visiting options in a Options object, allowing
175 * \see OptionsModifyingIterator
178 * \ingroup module_options
180 class OptionsModifyingVisitor
183 virtual ~OptionsModifyingVisitor() {}
185 //! Called for each section.
186 virtual void visitSection(OptionSectionInfo *section) = 0;
187 //! Called for each option.
188 virtual void visitOption(OptionInfo *option) = 0;
191 /*! \libinternal \brief
192 * Abstract base class for visiting options of a particular type, allowing
195 * \see OptionsModifyingIterator
196 * \see OptionsModifyingVisitor
199 * \ingroup module_options
201 template <class InfoType>
202 class OptionsModifyingTypeVisitor : public OptionsModifyingVisitor
205 virtual ~OptionsModifyingTypeVisitor() {}
207 virtual void visitSection(OptionSectionInfo *section) = 0;
209 * Called for each option of type \p InfoType.
211 virtual void visitOptionType(InfoType *option) = 0;
214 virtual void visitOption(OptionInfo *option)
216 InfoType *subtype = option->toType<InfoType>();
217 if (subtype != nullptr)
219 visitOptionType(subtype);
224 /*! \libinternal \brief
225 * Decorator class for visiting options in a Options object, allowing changes.
227 * This class works exactly like OptionsIterator, except that it uses
228 * OptionsModifyingVisitor interface, which allows modifying the options.
230 * \see OptionsIterator
233 * \ingroup module_options
235 class OptionsModifyingIterator
239 * Creates an object for visiting options in a Options object.
241 * The created iterator iterates over the "root" section in the Options
244 explicit OptionsModifyingIterator(Options *options);
245 //! Creates an object for visiting options in an options section.
246 explicit OptionsModifyingIterator(OptionSectionInfo *section);
248 //! Visits each section in the wrapped section.
249 void acceptSections(OptionsModifyingVisitor *visitor) const;
250 //! Visits each option in the wrapped section.
251 void acceptOptions(OptionsModifyingVisitor *visitor) const;
254 //! The wrapped section object.
255 internal::OptionSectionImpl §ion_;
257 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsModifyingIterator);