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