2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2014, 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/common.h"
58 /*! \libinternal \brief
59 * Pure interface for visiting options in a Options object.
61 * \see OptionsIterator
64 * \ingroup module_options
69 virtual ~OptionsVisitor() {}
72 * Called for each subsection in Options.
74 virtual void visitSubSection(const Options §ion) = 0;
76 * Called for each option in Options.
78 virtual void visitOption(const OptionInfo &option) = 0;
81 /*! \libinternal \brief
82 * Abstract base class for visiting options of a particular type.
84 * \see OptionsIterator
88 * \ingroup module_options
90 template <class InfoType>
91 class OptionsTypeVisitor : public OptionsVisitor
94 virtual ~OptionsTypeVisitor() {}
96 virtual void visitSubSection(const Options §ion) = 0;
98 * Called for each option of type \p InfoType.
100 virtual void visitOptionType(const InfoType &option) = 0;
103 virtual void visitOption(const OptionInfo &option)
105 const InfoType *subtype = option.toType<InfoType>();
108 visitOptionType(*subtype);
113 /*! \libinternal \brief
114 * Decorator class for visiting options in a Options object.
116 * This class provides an interface for looping through subsections and
117 * options in a Options object.
119 * Typical use (loop over all options, iteratively descending into
122 class Visitor : public gmx::OptionsVisitor
125 void visitSubSection(const Options §ion)
127 OptionsIterator iterator(section);
128 iterator.acceptSubSections(this);
129 iterator.acceptOptions(this);
132 void visitOption(const OptionInfo &option)
138 Visitor().visitSubSection(options);
142 * \ingroup module_options
144 class OptionsIterator
148 * Creates an object for visiting options in a Options object.
150 explicit OptionsIterator(const Options &options);
153 * Visits each subsection in the wrapped Options object.
155 void acceptSubSections(OptionsVisitor *visitor) const;
157 * Visits each option in the wrapped Options object.
159 void acceptOptions(OptionsVisitor *visitor) const;
162 //! The wrapped Options object.
163 const Options &options_;
165 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsIterator);
168 /*! \libinternal \brief
169 * Pure interface for visiting options in a Options object, allowing
172 * \see OptionsModifyingIterator
175 * \ingroup module_options
177 class OptionsModifyingVisitor
180 virtual ~OptionsModifyingVisitor() {}
183 * Called for each subsection in Options.
185 virtual void visitSubSection(Options *section) = 0;
187 * Called for each option in Options.
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 virtual ~OptionsModifyingTypeVisitor() {}
208 virtual void visitSubSection(Options *section) = 0;
210 * Called for each option of type \p InfoType.
212 virtual void visitOptionType(InfoType *option) = 0;
215 virtual void visitOption(OptionInfo *option)
217 InfoType *subtype = option->toType<InfoType>();
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 explicit OptionsModifyingIterator(Options *options);
245 * Visits each subsection in the wrapped Options object.
247 void acceptSubSections(OptionsModifyingVisitor *visitor) const;
249 * Visits each option in the wrapped Options object.
251 void acceptOptions(OptionsModifyingVisitor *visitor) const;
254 //! The wrapped Options object.
257 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsModifyingIterator);