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::SelectionOptionManager.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_selection
39 #ifndef GMX_SELECTION_SELECTIONOPTIONMANAGER_H
40 #define GMX_SELECTION_SELECTIONOPTIONMANAGER_H
44 #include "../utility/common.h"
50 class SelectionCollection;
51 class SelectionOptionStorage;
54 * Handles interaction of selection options with other options and user input.
56 * This class implements interaction of SelectionOption with
57 * SelectionCollection, and also implements features of SelectionOption that
58 * require actions outside options parsing.
59 * It also implements the coupling between SelectionOption and
60 * SelectionFileOption.
62 * The main features of this class are:
63 * - convertOptionValue(), which is used to convert string values into
64 * selections for options.
65 * - requestOptionDelayedParsing(), which is called by the internal
66 * implementation of selection options when an option is provided on the
67 * command line without a value. Such calls are remembered, and the value
68 * for all requested options can be later provided by calling one of
69 * parseRequestedFromStdin(), parseRequestedFromFile() or
70 * parseRequstedFromString().
72 * \see setManagerForSelectionOptions()
75 * \ingroup module_selection
77 class SelectionOptionManager
81 * Creates a manager for selection options.
83 * \throws std::bad_alloc if out of memory.
85 explicit SelectionOptionManager(SelectionCollection *selections);
86 ~SelectionOptionManager();
89 * Adds a selection option to be managed.
91 * \param storage Storage object for the option to register.
92 * \throws std::bad_alloc if out of memory.
94 * This is only for internal use by the selection module.
95 * It is not possible to obtain a SelectionOptionStorage pointer
96 * through any public or library API.
98 * Strong exception safety.
100 void registerOption(SelectionOptionStorage *storage);
102 * Converts a string value to selections for an option.
104 * \param storage Storage object to receive the selections.
105 * \param[in] value Value to convert.
106 * \throws std::bad_alloc if out of memory.
107 * \throws InvalidInputError if the selection string is not valid,
108 * or uses a feature not supported by the option.
110 * This is only for internal use by the selection module.
111 * It is not possible to obtain a SelectionOptionStorage pointer
112 * through any public or library API.
114 void convertOptionValue(SelectionOptionStorage *storage,
115 const std::string &value);
117 * Adds a selection option for delayed user input.
119 * \param storage Storage object for the option to request.
120 * \throws std::bad_alloc if out of memory.
122 * This is only for internal use by the selection module.
123 * It is not possible to obtain a SelectionOptionStorage pointer
124 * through any public or library API.
126 * Strong exception safety.
128 void requestOptionDelayedParsing(SelectionOptionStorage *storage);
131 * Parses selection(s) from standard input for options not yet
134 * \param[in] bInteractive Whether the parser should behave
136 * \throws unspecified Can throw any exception thrown by
137 * SelectionCollection::parseFromStdin().
138 * \throws std::bad_alloc if out of memory.
140 * This method cooperates with SelectionOption to allow interactive
141 * input of requested selections after all options have been processed.
142 * It should be called after the Options::finish() method has been
143 * called on all options that add selections to this collection.
144 * For each required selection option that has not been given, as well
145 * as for optional selection options that have been specified without
146 * values, it will prompt the user to input the necessary selections.
148 void parseRequestedFromStdin(bool bInteractive);
150 * Parses selection(s) from a file for options not yet provided.
152 * \param[in] filename Name of the file to parse selections from.
153 * \throws unspecified Can throw any exception thrown by
154 * SelectionCollection::parseFromFile().
155 * \throws std::bad_alloc if out of memory.
156 * \throws InvalidInputError if
157 * - the number of selections in \p filename doesn't match the
159 * - any selection uses a feature that is not allowed for the
160 * corresponding option.
161 * - if there is a request for any number of selections that is
162 * not the last (in which case it is not possible to determine
163 * which selections belong to which request).
165 * This method behaves as parseRequestedFromStdin(), with two
167 * -# It reads the selections from a file instead of standard input.
168 * -# If no requests are pending, assigns values to all required
169 * options that have not yet been set.
171 * This method used to implement SelectionFileOption.
173 * \see parseRequestedFromStdin()
175 void parseRequestedFromFile(const std::string &filename);
177 * Parses selection(s) from a string for options not yet provided.
179 * \param[in] str String to parse.
180 * \throws unspecified Can throw any exception thrown by
181 * SelectionCollection::parseFromString().
182 * \throws std::bad_alloc if out of memory.
183 * \throws InvalidInputError in same conditions as
184 * parseRequestedFromFile().
186 * This method behaves as parseRequestedFromFile(), but reads the
187 * selections from a string instead of a file.
188 * This method is mainly used for testing.
190 * \see parseRequestedFromFile()
192 void parseRequestedFromString(const std::string &str);
197 PrivateImplPointer<Impl> impl_;
200 * Needed for handling delayed selection parsing requests.
202 friend class SelectionOptionStorage;
206 * Set manager for all selection options.
208 * Recursively sets the manager to \p manager for all selection options in
210 * Must be called before value assignment starts for \p options.
216 void setManagerForSelectionOptions(Options *options,
217 SelectionOptionManager *manager);