2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2018, 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.
37 * Declares gmx::SelectionOptionManager.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_selection
43 #ifndef GMX_SELECTION_SELECTIONOPTIONMANAGER_H
44 #define GMX_SELECTION_SELECTIONOPTIONMANAGER_H
48 #include "gromacs/options/options.h"
49 #include "gromacs/utility/classhelpers.h"
54 class SelectionCollection
;
55 class SelectionOptionStorage
;
58 * Handles interaction of selection options with other options and user input.
60 * This class implements interaction of SelectionOption with
61 * SelectionCollection, and also implements features of SelectionOption that
62 * require actions outside options parsing.
63 * It also implements the coupling between SelectionOption and
64 * SelectionFileOption.
65 * It needs to be added using Options::addManager() before SelectionOption or
66 * SelectionFileOption options can be added to an Options collection.
68 * The main features of this class are:
69 * - convertOptionValue(), which is used to convert string values into
70 * selections for options.
71 * - requestOptionDelayedParsing(), which is called by the internal
72 * implementation of selection options when an option is provided on the
73 * command line without a value. Such calls are remembered, and the value
74 * for all requested options can be later provided by calling one of
75 * parseRequestedFromStdin(), parseRequestedFromFile() or
76 * parseRequstedFromString().
79 * \ingroup module_selection
81 class SelectionOptionManager
: public IOptionManager
85 * Creates a manager for selection options.
87 * \throws std::bad_alloc if out of memory.
89 explicit SelectionOptionManager(SelectionCollection
*selections
);
90 ~SelectionOptionManager() override
;
93 * Adds a selection option to be managed.
95 * \param storage Storage object for the option to register.
96 * \throws std::bad_alloc if out of memory.
98 * This is only for internal use by the selection module.
99 * It is not possible to obtain a SelectionOptionStorage pointer
100 * through any public or library API.
102 * Strong exception safety.
104 void registerOption(SelectionOptionStorage
*storage
);
106 * Converts a string value to selections for an option.
108 * \param storage Storage object to receive the selections.
109 * \param[in] value Value to convert.
110 * \param[in] bFullValue If true, the provided selections are the full
111 * value of the option, and additional checks are performed.
112 * \throws std::bad_alloc if out of memory.
113 * \throws InvalidInputError if the selection string is not valid,
114 * or uses a feature not supported by the option.
116 * This is only for internal use by the selection module.
117 * It is not possible to obtain a SelectionOptionStorage pointer
118 * through any public or library API.
120 void convertOptionValue(SelectionOptionStorage
*storage
,
121 const std::string
&value
,
124 * Adds a selection option for delayed user input.
126 * \param storage Storage object for the option to request.
127 * \throws std::bad_alloc if out of memory.
129 * This is only for internal use by the selection module.
130 * It is not possible to obtain a SelectionOptionStorage pointer
131 * through any public or library API.
133 * Strong exception safety.
135 void requestOptionDelayedParsing(SelectionOptionStorage
*storage
);
138 * Returns whether there are requested selections that need input from
139 * parseRequestedFrom*().
141 bool hasRequestedSelections() const;
144 * Initializes options for setting global selection properties.
146 * \param[in,out] options Options object to initialize.
147 * \throws std::bad_alloc if out of memory.
149 * \see SelectionCollection::initOptions()
151 void initOptions(IOptionsContainer
*options
);
154 * Parses selection(s) from standard input for options not yet
157 * \param[in] bInteractive Whether the parser should behave
159 * \throws unspecified Can throw any exception thrown by
160 * SelectionCollection::parseFromStdin().
161 * \throws std::bad_alloc if out of memory.
163 * This method cooperates with SelectionOption to allow interactive
164 * input of requested selections after all options have been processed.
165 * It should be called after the Options::finish() method has been
166 * called on all options that add selections to this collection.
167 * For each required selection option that has not been given, as well
168 * as for optional selection options that have been specified without
169 * values, it will prompt the user to input the necessary selections.
171 void parseRequestedFromStdin(bool bInteractive
);
173 * Parses selection(s) from a file for options not yet provided.
175 * \param[in] filename Name of the file to parse selections from.
176 * \throws unspecified Can throw any exception thrown by
177 * SelectionCollection::parseFromFile().
178 * \throws std::bad_alloc if out of memory.
179 * \throws InvalidInputError if
180 * - the number of selections in \p filename doesn't match the
182 * - any selection uses a feature that is not allowed for the
183 * corresponding option.
184 * - if there is a request for any number of selections that is
185 * not the last (in which case it is not possible to determine
186 * which selections belong to which request).
188 * This method behaves as parseRequestedFromStdin(), with two
190 * -# It reads the selections from a file instead of standard input.
191 * -# If no requests are pending, assigns values to all required
192 * options that have not yet been set.
194 * This method used to implement SelectionFileOption.
196 * \see parseRequestedFromStdin()
198 void parseRequestedFromFile(const std::string
&filename
);
200 * Parses selection(s) from a string for options not yet provided.
202 * \param[in] str String to parse.
203 * \throws unspecified Can throw any exception thrown by
204 * SelectionCollection::parseFromString().
205 * \throws std::bad_alloc if out of memory.
206 * \throws InvalidInputError in same conditions as
207 * parseRequestedFromFile().
209 * This method behaves as parseRequestedFromFile(), but reads the
210 * selections from a string instead of a file.
211 * This method is mainly used for testing.
213 * \see parseRequestedFromFile()
215 void parseRequestedFromString(const std::string
&str
);
220 PrivateImplPointer
<Impl
> impl_
;
223 * Needed for handling delayed selection parsing requests.
225 friend class SelectionOptionStorage
;