Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / selparam.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009,2010,2011,2013,2014, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \internal \file
36  * \brief API for handling parameters used in selections.
37  *
38  * There should be no need to use the data structures or call the
39  * functions in this file directly unless implementing a custom selection
40  * method.
41  *
42  * More details can be found on the page discussing
43  * \ref page_module_selection_custom "custom selection methods".
44  *
45  * \author Teemu Murtola <teemu.murtola@gmail.com>
46  * \ingroup module_selection
47  */
48 #ifndef GMX_SELECTION_SELPARAM_H
49 #define GMX_SELECTION_SELPARAM_H
50
51 #include "gromacs/selection/indexutil.h"
52
53 #include "selvalue.h"
54
55 /*! \name Parameter flags
56  * \anchor selparam_flags
57  */
58 /*@{*/
59 /*! \brief
60  * This flag is set if the user has provided the parameter.
61  *
62  * This flag is set automatically, and should not be set by the user.
63  */
64 #define SPAR_SET      1
65 /*! \brief
66  * If not set, an error is reported if the parameter is not specified by the
67  * user.
68  */
69 #define SPAR_OPTIONAL 2
70 /*! \brief
71  * If set, the parameter value can be dynamic, i.e., be different for
72  * different frames.
73  *
74  * If set, the parameter value should only be accessed in the update function
75  * of \c gmx_ana_selmethod_t.
76  * The flag is cleared before sel_initfunc() if the value provided is actually
77  * static.
78  */
79 #define SPAR_DYNAMIC  4
80 /*! \brief
81  * If set, the parameter value is parsed into sorted ranges.
82  *
83  * Can only be specified for integer parameters.
84  * If specified, the value of the parameter (\c gmx_ana_selparam_t::val)
85  * consists of sets of two integers, each specifying a range.
86  * The values give the endpoints of the ranges (inclusive).
87  * The ranges are sorted and overlapping/continuous ranges are merged into
88  * a single range to minimize the number of ranges.
89  *
90  * If this flag is specified, \c gmx_ana_selparam_t::nval gives the number of
91  * ranges. \p gmx_ana_selparam_t::nval should be 1 or \ref SPAR_VARNUM should be
92  * specified; other values would lead to unpredictable behavior.
93  */
94 #define SPAR_RANGES   8
95 /*! \brief
96  * If set, the parameter can have any number of values.
97  *
98  * If specified, the data pointer in \c gmx_ana_selparam_t::val should be NULL;
99  * the memory is allocated by the parameter parser.
100  * The implementation of the method should ensure that the pointer to the
101  * allocated memory is stored somewhere in sel_initfunc();
102  * otherwise, the memory is lost.
103  *
104  * The initial value of \c gmx_ana_selparam_t::nval is not used with this flag.
105  * Instead, it will give the number of actual values provided by the user
106  * after the parameters have been parsed.
107  * For consistency, it should be initialized to -1.
108  *
109  * Cannot be combined with \ref GROUP_VALUE parameters.
110  */
111 #define SPAR_VARNUM   16
112 /*! \brief
113  * If set, the parameter can have a separate value for each atom.
114  *
115  * The flag is cleared before sel_initfunc() if the value provided is actually
116  * a single value.
117  *
118  * Cannot be combined with \ref POS_VALUE or \ref GROUP_VALUE parameters.
119  */
120 #define SPAR_ATOMVAL  32
121 /*! \brief
122  * If set, the parameter takes one of a set of predefined strings.
123  *
124  * Can only be specified for a \ref STR_VALUE parameter that takes a single
125  * string.
126  * The data pointer in \c gmx_ana_selparam_t::val should be initialized into an
127  * array of strings such that the first and last elements are NULL, and the
128  * rest give the possible values. For optional values, the second element in
129  * the array should give the default value. The string given by the user is
130  * matched against the beginnings of the given strings, and if a unique match
131  * is found, the first pointer in the array will be initialized to point to
132  * the matching string.
133  * The data pointer can be initialized as a static array; duplication of the
134  * array for multiple instances of the same method is automatically taken care
135  * of.
136  */
137 #define SPAR_ENUMVAL  128
138 /*@}*/
139
140 /*! \internal \brief
141  * Describes a single parameter for a selection method.
142  */
143 typedef struct gmx_ana_selparam_t
144 {
145     /** Name of the parameter. */
146     const char         *name;
147     /*! \brief
148      * The parameter value.
149      *
150      * Type \ref NO_VALUE can be used to define a boolean parameter.
151      * The number of values should be 0 for boolean parameters.
152      *
153      * The value pointer be initialized to NULL in the definition of a
154      * \c gmx_ana_selmethod_t and initialized in the
155      * \c gmx_ana_selmethod_t::init_data call
156      * (see sel_datafunc()).
157      * However, if \ref SPAR_VARNUM is provided and the parameter is not
158      * \ref POS_VALUE, this field should not be initialized. Instead,
159      * sufficient memory is allocated automatically and the pointer should be
160      * stored in \c gmx_ana_selmethod_t::init
161      * (see sel_initfunc()).
162      *
163      * The values cannot be accessed outside these two functions: the compiler
164      * makes a copy of the parameter structure for each instance of the
165      * method, and the original parameter array is not changed.
166      */
167     gmx_ana_selvalue_t  val;
168     /*! \brief
169      * Pointer to store the number of values.
170      *
171      * If not NULL, the number of values for the parameter is stored in the
172      * pointed value.
173      * Should be specified if \ref SPAR_VARNUM and \ref SPAR_DYNAMIC are both
174      * set.
175      *
176      * Should be initialized to NULL in the definition a \c gmx_ana_selmethod_t
177      * and initialized in sel_datafunc().
178      */
179     int                *nvalptr;
180     /*! \brief
181      * Flags that alter the way the parameter is parsed/handled.
182      *
183      * See \ref selparam_flags for allowed values.
184      */
185     int                 flags;
186 } gmx_ana_selparam_t;
187
188 /** Finds a parameter from an array by name. */
189 gmx_ana_selparam_t *
190 gmx_ana_selparam_find(const char *name, int nparam, gmx_ana_selparam_t *param);
191
192 #endif