2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014 by the GROMACS development team.
5 * Copyright (c) 2015,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
36 /*! \defgroup module_options Extensible Handling of Options (options)
37 * \ingroup group_utilitymodules
39 * Provides functionality for handling options.
43 * Code that provides options does so using methods in gmx::IOptionsContainer
44 * and classes defined in basicoptions.h.
45 * Only these are needed if a class wants to provide a set of standard options
46 * (other modules can provide additional option types, such as
47 * gmx::SelectionOption).
48 * For each option, the caller provides an output variable that will receive
49 * the final value of the option once user input has been parsed.
50 * When adding options, it is possible to also provide descriptions for the
51 * options for use in generated help text.
53 * Generic code that handles the user input does so by creating a gmx::Options
54 * instance and passing it (as gmx::IOptionsContainer) to the classes that add
55 * the actual options. It can then use a parser to set values to the options.
56 * Final values for the options can be inspected in the code that added the
57 * individual options, from the provided output variables.
59 * The sequence charts below provides an overview of how the options work from
60 * usage perspective. They include two fictional modules, A and B, that provide
61 * options, and a main routine that manages these. The first chart shows a
62 * typical initialization sequence, where the main routine creates an options
63 * object, and calls an initOptions() method in each module that can provide
64 * options (the modules may also request their submodules to add their own
65 * options). Each module uses gmx::IOptionsContainer::addOption() to add the
66 * options they require, and specify output variables into which the options
70 * options [ label="Options", URL="\ref gmx::Options" ],
71 * A [ label="module A" ],
72 * B [ label="module B" ];
74 * main box B [ label="main owns all objects" ];
75 * main => options [ label="create", URL="\ref gmx::Options::Options()" ];
76 * main => A [ label="initOptions()" ];
77 * A => options [ label="addOption()", URL="\ref gmx::IOptionsContainer::addOption()" ];
80 * main => B [ label="initOptions()" ];
81 * B => options [ label="addOption()", URL="\ref gmx::IOptionsContainer::addOption()" ];
86 * After all options have been specified, they can be parsed. A parser splits
87 * the input into option-value pairs (one option may have multiple values), and
88 * passes these into the gmx::Options object, which is responsible for
89 * converting them into the appropriate types and storing the values into the
90 * variables provided in the calls to gmx::IOptionsContainer::addOption().
93 * parser [ label="parser" ],
94 * options [ label="Options", URL="\ref gmx::Options" ],
95 * A [ label="module A" ],
96 * B [ label="module B" ];
98 * main => parser [ label="parse()" ];
99 * parser => options [ label="assign(string)" ];
100 * options -> A [ label="set variable" ];
101 * parser => options [ label="assign(string)" ];
102 * options -> B [ label="set variable" ];
106 * After all options have been parsed (possibly using multiple different
107 * parsers), gmx::Options::finish() is called. This performs final
108 * validation of the options and may further adjust the values stored in the
109 * output variables (see documentation on individual option types on when this
113 * options [ label="Options", URL="\ref gmx::Options" ],
114 * A [ label="module A" ],
115 * B [ label="module B" ];
117 * main => options [ label="finish()", URL="\ref gmx::Options::finish()" ];
118 * options -> A [ label="set variable" ];
119 * options -> B [ label="set variable" ];
123 * Module \ref module_commandline implements classes that assign option values
124 * from command line and produce help for programs that use the command line
128 * <H3>Advanced Use (in library API)</H3>
130 * It is possible to extend the module with new option types and/or parsers for
133 * To implement new option types, it is necessary to subclass the templates
134 * OptionTemplate and OptionStorageTemplate with the type of the values that
135 * the option should provide as the template argument. After this is done, it
136 * is possible to add options of this new type using IOptionsContainer::addOption().
138 * To implement new parsers, one can use OptionsAssigner, which provides an
139 * interface to set values in an Options object.
141 * There is also an interface to iterate over all options in an Options object.
142 * One should implement the OptionsVisitor interface, and then use
143 * OptionsIterator to apply this visitor to the Options object.
146 * \author Teemu Murtola <teemu.murtola@gmail.com>
150 * Public API convenience header for handling of options.
152 * \author Teemu Murtola <teemu.murtola@gmail.com>
154 * \ingroup module_options
156 #ifndef GMX_OPTIONS_H
157 #define GMX_OPTIONS_H
159 #include "gromacs/fileio/filetypes.h"
160 #include "gromacs/options/basicoptions.h"
161 #include "gromacs/options/filenameoption.h"
162 #include "gromacs/options/filenameoptionmanager.h"
163 #include "gromacs/options/ioptionsbehavior.h"
164 #include "gromacs/options/ioptionscontainer.h"
165 #include "gromacs/options/options.h"