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 * Declares gmx::Options.
35 * Together with basicoptions.h, this header forms the part of the public
36 * API that most classes will use to provide options.
38 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
40 * \ingroup module_options
42 #ifndef GMX_OPTIONS_OPTIONS_H
43 #define GMX_OPTIONS_OPTIONS_H
47 #include "../utility/common.h"
53 class OptionsAssigner;
54 class OptionsIterator;
57 * Collection of options.
59 * This class provides a standard interface for implementing input options.
60 * Standard usage is to write a method that creates an Options that is owned by
61 * the object, populates it with supported options, and then returns it:
63 // <as class attributes>
65 Options options("common", "Common Options");
70 using gmx::StringOption;
71 using gmx::IntegerOption;
72 options.addOption(StringOption("arg1").store(&arg1));
73 options.addOption(IntegerOption("arg2").store(&arg2));
76 * The caller of that method can then use a parser implementation such as
77 * CommandLineParser to provide values for the options.
79 * Header basicoptions.h provides declarations of several standard
80 * option types for use with addOption(). Documentation of those classes
81 * also give more examples of how to define options.
83 * In order to keep the public interface of this class simple and to reduce
84 * build dependencies on objects that simply provide options, functionality
85 * to assign values to options is provided by a separate OptionsAssigner class.
86 * Similarly, functionality for looping over all options (e.g., for writing out
87 * help) is provided by OptionsIterator.
90 * \ingroup module_options
96 * Initializes the name and title of an option collection.
98 * \param[in] name Single-word name.
99 * \param[in] title Descriptive title.
101 * Copies the input strings.
103 Options(const char *name, const char *title);
106 //! Returns the short name of the option collection.
107 const std::string &name() const;
108 //! Returns the title of the option collection.
109 const std::string &title() const;
110 //! Returns the full description of the option collection.
111 const std::string &description() const;
114 * Sets the full description of the option collection.
116 * \param[in] desc String to set as the description.
118 * concatenateStrings() is useful for forming the input string.
120 void setDescription(const std::string &desc);
121 //int addBugs(int nbugs, const char *const *bugs);
124 * Adds an option collection as a subsection of this collection.
126 * \param[in] section Subsection to add.
128 * The name() field of \p section is used as the name of the
129 * subsection. If an attempt is made to add two different subsections
130 * with the same name, this function asserts.
132 * For certain functionality to work properly, no options should
133 * be added to the subsection after it has been added to another
136 * Only a pointer to the provided object is stored. The caller is
137 * responsible that the object exists for the lifetime of the
139 * It is not possible to add the same Options object as a subsection to
140 * several different Options.
141 * If an attempt is made, the function asserts.
143 void addSubSection(Options *section);
145 * Adds a recognized option to the collection.
147 * \throws APIError if invalid option settings are provided.
149 * See \link Options class documentation \endlink for example usage.
151 void addOption(const AbstractOption &settings);
153 //! Returns true if option \p name is set.
154 bool isSet(const char *name) const;
156 * Notifies the collection that all option values are assigned.
158 * \throws InvalidInputError if invalid user input is detected.
160 * This function should be called after no more option values are
161 * to be assigned. Values in storage variables are guaranteed to be
162 * available only after this call, although in most cases, they are
163 * available already during assignment.
165 * If invalid option values, e.g., missing required option, is detected
166 * at this point, this function throws. The thrown exception contains
167 * information on all errors detected during the call.
174 PrivateImplPointer<Impl> _impl;
176 //! Needed to be able to extend the interface of this object.
177 friend class OptionsAssigner;
178 //! Needed to be able to extend the interface of this object.
179 friend class OptionsIterator;
180 //! Needed to be able to extend the interface of this object.
181 friend class OptionsModifyingIterator;