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::OptionsAssigner.
35 * This header is only needed when implementing option parsers.
37 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
39 * \ingroup module_options
41 #ifndef GMX_OPTIONS_OPTIONSASSIGNER_H
42 #define GMX_OPTIONS_OPTIONSASSIGNER_H
51 /*! \libinternal \brief
52 * Decorator class for assigning values to Options.
54 * This class extends the interface of an Options object by providing methods
55 * to set values for options. It also keeps track of necessary state variables
56 * to assign values to options in subsections within the Options object.
57 * Typical use (without error checking):
59 gmx::options::Options options("name", "Title");
62 gmx::options::OptionsAssigner assigner(&options);
63 assigner.startOption("opt1");
64 assigner.appendValue("3");
65 assigner.startSubSection("section");
66 assigner.startOption("opt2"); // Now in the subsection
67 assigner.appendValue("yes");
68 assigner.finishSubSection()
69 assigner.startOption("opt3"); // Again in the main options
70 assigner.appendValue("2");
71 assigner.finish(); // At minimum, the return value of finish() should be checked.
74 * As shown in the example, calling finishOption() or finishSubSection() is
75 * optional; they are automatically called when appropriate by startOption(),
76 * startSubSection(), and finish().
77 * However, you need to call them explicitly if you want to act on the return
78 * value: these calls do not influence the return value of
79 * startOption() / startSubSection().
80 * They do influence the return value of finish(), however.
81 * The finish() method should always be called.
84 * \ingroup module_options
90 * Creates an object that assigns to the given object.
92 OptionsAssigner(Options *options);
96 * Sets the assigner to recognize boolean options with a "no" prefix.
98 * With this option set, \c startOption("noname") is interpreted as
99 * \c startOption("name") followed by \c appendValue("no"), if there is
100 * no option by the name "noname", but there is a boolean option with
103 * By default, the prefix is not recognized.
105 * Can be set or cleared at any time, and will have effect on all
106 * subsequent calls of startOption().
108 void setAcceptBooleanNoPrefix(bool enabled);
110 * Sets the assigner to find options in non-active sections.
112 * By default, options are only looked for in the currently active
113 * subsection. With this option set, if no matching option is found in
114 * the current section, a breadth-first search is performed, first on
115 * all subsections of the current section, and then going up one level
116 * at a time. The first matching option is used, and the current
117 * section is changed to the section that contains the matching option.
119 * Can be set or cleared at any time, and will have effect on all
120 * subsequent calls of startOption().
122 void setNoStrictSectioning(bool enabled);
125 * Start assigning values.
129 * Start assigning values to options in a subsection.
131 * \param[in] name Name of the subsection to start assigning to.
133 void startSubSection(const char *name);
135 * Start assigning values for an option.
137 * \param[in] name Name of the option to start assigning to.
139 void startOption(const char *name);
141 * Appends a value to the value list of the current option.
143 * \param[in] value String representation of the value to assign.
145 void appendValue(const std::string &value);
147 * Finish assigning values for the current option.
151 * Finish assigning values to a subsection.
153 void finishSubSection();
155 * Finish assigning options through the object.
164 // Disallow copy and assign.
165 OptionsAssigner(const OptionsAssigner &);
166 void operator =(const OptionsAssigner &);