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
47 class AbstractOptionStorage;
50 /*! \libinternal \brief
51 * Wrapper class for accessing option information.
53 * This class isolates the details of the internal option implementation
54 * from option visitors.
59 * \ingroup module_options
65 * Wraps a given option object.
67 OptionInfo(const AbstractOptionStorage &option);
69 //! Returns true if the option is a boolean option.
70 bool isBoolean() const;
71 //! Returns true if the option is a file name option.
73 //! Returns true if the option is a hidden option.
74 bool isHidden() const;
75 //! Returns the name of the option.
76 const std::string &name() const;
77 //! Returns the description of the option.
78 const std::string &description() const;
79 //! Returns the type of the option as a string.
80 const char *type() const;
81 //! Returns the number of values given for the option.
82 int valueCount() const;
83 //! Returns the i'th value of the option as a string.
84 std::string formatValue(int i) const;
85 //! Returns all the values of the option as a single string.
86 std::string formatValues() const;
89 //! The wrapped option.
90 const AbstractOptionStorage &_option;
92 // Disallow copy and assign.
93 OptionInfo(const OptionInfo &);
94 void operator =(const OptionInfo &);
96 friend class OptionsIterator;
99 /*! \libinternal \brief
100 * Pure interface for visiting options in a Options object.
102 * \see OptionsIterator
105 * \ingroup module_options
110 virtual ~OptionsVisitor() {}
113 * Called for each subsection in Options.
115 virtual void visitSubSection(const Options §ion) = 0;
117 * Called for each option in Options.
119 virtual void visitOption(const OptionInfo &option) = 0;
122 /*! \libinternal \brief
123 * Decorator class for visiting options in a Options object.
125 * This class provides an interface for looping through subsections and
126 * options in a Options object.
128 * Typical use (loop over all options, iteratively descending into
131 class Visitor : public gmx::options::OptionsVisitor
134 void visitSubSection(const Options §ion)
136 OptionsIterator iterator(section);
137 iterator.acceptSubSections(this);
138 iterator.acceptOptions(this);
141 void visitOption(const OptionInfo &option)
147 Visitor().visitSubSection(options);
151 * \ingroup module_options
153 class OptionsIterator
157 * Creates an object for visiting options in a Options object.
159 OptionsIterator(const Options &options);
162 * Visits each subsection in the wrapped Options object.
164 void acceptSubSections(OptionsVisitor *visitor) const;
166 * Visits each option in the wrapped Options object.
168 void acceptOptions(OptionsVisitor *visitor) const;
171 //! The wrapped Options object.
172 const Options &_options;
174 // Disallow copy and assign.
175 OptionsIterator(const OptionsIterator &);
176 void operator =(const OptionsIterator &);