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
33 * Implements classes in optionsvisitor.h.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_options
38 #include "gromacs/options/optionsvisitor.h"
40 #include "gromacs/options/abstractoptionstorage.h"
41 #include "gromacs/options/optioninfo.h"
42 #include "gromacs/options/options.h"
44 #include "options-impl.h"
49 /********************************************************************
54 OptionInfo::OptionInfo(AbstractOptionStorage *option)
60 OptionInfo::~OptionInfo()
64 bool OptionInfo::isSet() const
66 return _option.isSet();
69 bool OptionInfo::isHidden() const
71 return _option.isHidden();
74 bool OptionInfo::isRequired() const
76 return _option.isRequired();
79 const std::string &OptionInfo::name() const
81 return _option.name();
84 const std::string &OptionInfo::description() const
86 return _option.description();
89 const char *OptionInfo::type() const
91 return _option.typeString();
94 int OptionInfo::valueCount() const
96 return _option.valueCount();
99 std::string OptionInfo::formatValue(int i) const
101 return _option.formatValue(i);
104 std::string OptionInfo::formatValues() const
107 int count = valueCount();
108 for (int i = 0; i < count; ++i)
114 result.append(formatValue(i));
119 /********************************************************************
123 OptionsIterator::OptionsIterator(const Options &options)
128 void OptionsIterator::acceptSubSections(OptionsVisitor *visitor) const
130 const Options::Impl::SubSectionList &subSectionList =
131 _options._impl->_subSections;
132 Options::Impl::SubSectionList::const_iterator i;
133 for (i = subSectionList.begin(); i != subSectionList.end(); ++i)
135 visitor->visitSubSection(*(*i));
139 void OptionsIterator::acceptOptions(OptionsVisitor *visitor) const
141 const Options::Impl::OptionList &optionList =
142 _options._impl->_options;
143 Options::Impl::OptionList::const_iterator i;
144 for (i = optionList.begin(); i != optionList.end(); ++i)
146 // This is not strictly const-correct, since optionInfo() is
147 // not const (while the input options is), but this makes things much
149 visitor->visitOption((*i)->optionInfo());
153 /********************************************************************
154 * OptionsModifyingIterator
157 OptionsModifyingIterator::OptionsModifyingIterator(Options *options)
162 void OptionsModifyingIterator::acceptSubSections(OptionsModifyingVisitor *visitor) const
164 const Options::Impl::SubSectionList &subSectionList =
165 _options._impl->_subSections;
166 Options::Impl::SubSectionList::const_iterator i;
167 for (i = subSectionList.begin(); i != subSectionList.end(); ++i)
169 visitor->visitSubSection(*i);
173 void OptionsModifyingIterator::acceptOptions(OptionsModifyingVisitor *visitor) const
175 const Options::Impl::OptionList &optionList =
176 _options._impl->_options;
177 Options::Impl::OptionList::const_iterator i;
178 for (i = optionList.begin(); i != optionList.end(); ++i)
180 visitor->visitOption(&(*i)->optionInfo());