3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
31 /*! \libinternal \file
33 * Declares gmx::OptionsVisitor interface and supporting classes.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_options
39 #ifndef GMX_OPTIONS_OPTIONSVISITOR_H
40 #define GMX_OPTIONS_OPTIONSVISITOR_H
46 #include "../utility/common.h"
48 #include "abstractoption.h"
55 /*! \libinternal \brief
56 * Pure interface for visiting options in a Options object.
58 * \see OptionsIterator
61 * \ingroup module_options
66 virtual ~OptionsVisitor() {}
69 * Called for each subsection in Options.
71 virtual void visitSubSection(const Options §ion) = 0;
73 * Called for each option in Options.
75 virtual void visitOption(const OptionInfo &option) = 0;
78 /*! \libinternal \brief
79 * Abstract base class for visiting options of a particular type.
81 * \see OptionsIterator
85 * \ingroup module_options
87 template <class InfoType>
88 class OptionsTypeVisitor : public OptionsVisitor
91 virtual ~OptionsTypeVisitor() {}
93 virtual void visitSubSection(const Options §ion) = 0;
95 * Called for each option of type \p InfoType.
97 virtual void visitOptionType(const InfoType &option) = 0;
100 virtual void visitOption(const OptionInfo &option)
102 const InfoType *subtype = option.toType<InfoType>();
105 visitOptionType(*subtype);
110 /*! \libinternal \brief
111 * Decorator class for visiting options in a Options object.
113 * This class provides an interface for looping through subsections and
114 * options in a Options object.
116 * Typical use (loop over all options, iteratively descending into
119 class Visitor : public gmx::OptionsVisitor
122 void visitSubSection(const Options §ion)
124 OptionsIterator iterator(section);
125 iterator.acceptSubSections(this);
126 iterator.acceptOptions(this);
129 void visitOption(const OptionInfo &option)
135 Visitor().visitSubSection(options);
139 * \ingroup module_options
141 class OptionsIterator
145 * Creates an object for visiting options in a Options object.
147 explicit OptionsIterator(const Options &options);
150 * Visits each subsection in the wrapped Options object.
152 void acceptSubSections(OptionsVisitor *visitor) const;
154 * Visits each option in the wrapped Options object.
156 void acceptOptions(OptionsVisitor *visitor) const;
159 //! The wrapped Options object.
160 const Options &options_;
162 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsIterator);
165 /*! \libinternal \brief
166 * Pure interface for visiting options in a Options object, allowing
169 * \see OptionsModifyingIterator
172 * \ingroup module_options
174 class OptionsModifyingVisitor
177 virtual ~OptionsModifyingVisitor() {}
180 * Called for each subsection in Options.
182 virtual void visitSubSection(Options *section) = 0;
184 * Called for each option in Options.
186 virtual void visitOption(OptionInfo *option) = 0;
189 /*! \libinternal \brief
190 * Abstract base class for visiting options of a particular type, allowing
193 * \see OptionsModifyingIterator
194 * \see OptionsModifyingVisitor
197 * \ingroup module_options
199 template <class InfoType>
200 class OptionsModifyingTypeVisitor : public OptionsModifyingVisitor
203 virtual ~OptionsModifyingTypeVisitor() {}
205 virtual void visitSubSection(Options *section) = 0;
207 * Called for each option of type \p InfoType.
209 virtual void visitOptionType(InfoType *option) = 0;
212 virtual void visitOption(OptionInfo *option)
214 InfoType *subtype = option->toType<InfoType>();
217 visitOptionType(subtype);
222 /*! \libinternal \brief
223 * Decorator class for visiting options in a Options object, allowing changes.
225 * This class works exactly like OptionsIterator, except that it uses
226 * OptionsModifyingVisitor interface, which allows modifying the options.
228 * \see OptionsIterator
231 * \ingroup module_options
233 class OptionsModifyingIterator
237 * Creates an object for visiting options in a Options object.
239 explicit OptionsModifyingIterator(Options *options);
242 * Visits each subsection in the wrapped Options object.
244 void acceptSubSections(OptionsModifyingVisitor *visitor) const;
246 * Visits each option in the wrapped Options object.
248 void acceptOptions(OptionsModifyingVisitor *visitor) const;
251 //! The wrapped Options object.
254 GMX_DISALLOW_COPY_AND_ASSIGN(OptionsModifyingIterator);