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