2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012, 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 "../utility/common.h"
52 #include "abstractoption.h"
59 /*! \libinternal \brief
60 * Pure interface for visiting options in a Options object.
62 * \see OptionsIterator
65 * \ingroup module_options
70 virtual ~OptionsVisitor() {}
73 * Called for each subsection in Options.
75 virtual void visitSubSection(const Options §ion) = 0;
77 * Called for each option in Options.
79 virtual void visitOption(const OptionInfo &option) = 0;
82 /*! \libinternal \brief
83 * Abstract base class for visiting options of a particular type.
85 * \see OptionsIterator
89 * \ingroup module_options
91 template <class InfoType>
92 class OptionsTypeVisitor : public OptionsVisitor
95 virtual ~OptionsTypeVisitor() {}
97 virtual void visitSubSection(const Options §ion) = 0;
99 * Called for each option of type \p InfoType.
101 virtual void visitOptionType(const InfoType &option) = 0;
104 virtual void visitOption(const OptionInfo &option)
106 const InfoType *subtype = option.toType<InfoType>();
109 visitOptionType(*subtype);
114 /*! \libinternal \brief
115 * Decorator class for visiting options in a Options object.
117 * This class provides an interface for looping through subsections and
118 * options in a Options object.
120 * Typical use (loop over all options, iteratively descending into
123 class Visitor : public gmx::OptionsVisitor
126 void visitSubSection(const Options §ion)
128 OptionsIterator iterator(section);
129 iterator.acceptSubSections(this);
130 iterator.acceptOptions(this);
133 void visitOption(const OptionInfo &option)
139 Visitor().visitSubSection(options);
143 * \ingroup module_options
145 class OptionsIterator
149 * Creates an object for visiting options in a Options object.
151 explicit OptionsIterator(const Options &options);
154 * Visits each subsection in the wrapped Options object.
156 void acceptSubSections(OptionsVisitor *visitor) const;
158 * Visits each option in the wrapped Options object.
160 void acceptOptions(OptionsVisitor *visitor) const;
163 //! The wrapped Options object.
164 const Options &options_;
166 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsIterator);
169 /*! \libinternal \brief
170 * Pure interface for visiting options in a Options object, allowing
173 * \see OptionsModifyingIterator
176 * \ingroup module_options
178 class OptionsModifyingVisitor
181 virtual ~OptionsModifyingVisitor() {}
184 * Called for each subsection in Options.
186 virtual void visitSubSection(Options *section) = 0;
188 * Called for each option in Options.
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 virtual ~OptionsModifyingTypeVisitor() {}
209 virtual void visitSubSection(Options *section) = 0;
211 * Called for each option of type \p InfoType.
213 virtual void visitOptionType(InfoType *option) = 0;
216 virtual void visitOption(OptionInfo *option)
218 InfoType *subtype = option->toType<InfoType>();
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 explicit OptionsModifyingIterator(Options *options);
246 * Visits each subsection in the wrapped Options object.
248 void acceptSubSections(OptionsModifyingVisitor *visitor) const;
250 * Visits each option in the wrapped Options object.
252 void acceptOptions(OptionsModifyingVisitor *visitor) const;
255 //! The wrapped Options object.
258 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsModifyingIterator);