Merge release-4-6 (commit 'Ic142a690')
[alexxy/gromacs.git] / src / gromacs / selection / selectionoptionstorage.h
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
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.
13
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.
18  *
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.
25  *
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.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \file
32  * \brief
33  * Declares gmx::SelectionOptionStorage.
34  *
35  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36  * \ingroup module_selection
37  */
38 #ifndef GMX_SELECTION_SELECTIONOPTIONSTORAGE_H
39 #define GMX_SELECTION_SELECTIONOPTIONSTORAGE_H
40
41 #include "../options/optionstoragetemplate.h"
42 #include "selection.h"
43 #include "selectionenums.h"
44 #include "selectionoptioninfo.h"
45
46 namespace gmx
47 {
48
49 class SelectionCollection;
50 class SelectionOption;
51
52 /*! \internal \brief
53  * Converts, validates, and stores selection values.
54  *
55  * \ingroup module_selection
56  */
57 class SelectionOptionStorage : public OptionStorageTemplate<Selection>
58 {
59     public:
60         /*! \brief
61          * Initializes the storage from option settings.
62          *
63          * \param[in] settings   Storage settings.
64          */
65         SelectionOptionStorage(const SelectionOption &settings);
66
67         virtual OptionInfo &optionInfo() { return _info; }
68         virtual const char *typeString() const { return "sel"; }
69         virtual std::string formatSingleValue(const Selection &value) const;
70
71         //! \copydoc SelectionOptionInfo::setSelectionCollection()
72         void setSelectionCollection(SelectionCollection *selections)
73         {
74             _sc = selections;
75         }
76
77         /*! \brief
78          * Adds selections to the storage.
79          *
80          * \param[in] selections  List of selections to add.
81          * \param[in] bFullValue  If true, the provided selections are the full
82          *      value of the option, and additional checks are performed.
83          * \throws  std::bad_alloc if out of memory.
84          * \throws  InvalidInputError if
85          *      - There is an incorrect number of selections in \p selections.
86          *      - Any selection in \p selections is not allowed for this
87          *        option.
88          *
89          * This function is used to implement the methods
90          * SelectionCollection::parseRequestedFromStdin() and
91          * SelectionCollection::parseRequestedFromString() (called with
92          * \p bFullValue set to true), as well as internally by the storage
93          * class (called with \p bFullValue set to false).
94          */
95         void addSelections(const SelectionList &selections,
96                            bool bFullValue);
97
98         // Required to access the number of values in selection requests.
99         // See SelectionCollection::Impl.
100         using MyBase::maxValueCount;
101         //! \copydoc SelectionOptionInfo::setValueCount()
102         void setAllowedValueCount(int count);
103         /*! \brief
104          * Alters flags for the selections created by this option.
105          *
106          * \param[in] flag        Flag to change.
107          * \param[in] bSet        Whether to set or clear the flag.
108          * \throws    std::bad_alloc if out of memory.
109          * \throws    InvalidInputError if selections have already been
110          *      provided and conflict with the given flags.
111          *
112          * If selections have already been provided, it is checked that they
113          * match the limitations enforced by the flags.  Pending requests are
114          * also affected.
115          *
116          * Strong exception safety guarantee.
117          */
118         void setSelectionFlag(SelectionFlag flag, bool bSet);
119
120     private:
121         virtual void convertValue(const std::string &value);
122         virtual void processSetValues(ValueList *values);
123         virtual void processAll();
124
125         SelectionOptionInfo     _info;
126         SelectionCollection    *_sc;
127         SelectionFlags          _selectionFlags;
128 };
129
130 } // namespace gmx
131
132 #endif