Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / selection / selvalue.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
33  * Declares ::gmx_ana_selvalue_t.
34  *
35  * There should be no need to use the data structures in this file directly
36  * unless implementing a custom selection routine.
37  *
38  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
39  * \ingroup module_selection
40  */
41 #ifndef GMX_SELECTION_SELVALUE_H
42 #define GMX_SELECTION_SELVALUE_H
43
44 #include "../legacyheaders/types/simple.h"
45
46 /** Defines the value type of a different selection objects. */
47 typedef enum
48 {
49     NO_VALUE,           /**< No value; either an error condition or an boolean 
50                              parameter. */
51     INT_VALUE,          /**< One or more integer values. */
52     REAL_VALUE,         /**< One or more real values. */
53     STR_VALUE,          /**< One or more string values. */
54     POS_VALUE,          /**< One or more position values. */
55     GROUP_VALUE         /**< One group of atoms. */
56 } e_selvalue_t;
57
58 /*! \brief
59  * Describes a value of a selection expression or of a selection method
60  * parameter.
61  *
62  * Which field in the union is used depends on the \p type.
63  */
64 typedef struct gmx_ana_selvalue_t
65 {
66     /** Type of the value. */
67     e_selvalue_t                type;
68     /*! \brief
69      * Number of values in the array pointed by the union.
70      *
71      * Note that for position and group values, it is the number of
72      * data structures in the array, not the number of positions or
73      * the number of atoms in the group.
74      */
75     int                         nr;
76     /** Pointer to the value. */
77     union {
78         /*! \brief
79          * Generic pointer for operations that do not need type information.
80          *
81          * Needs to be the first member to be able to use initialized arrays.
82          */
83         void                   *ptr;
84         /** Integer value(s) (type \ref INT_VALUE). */
85         int                    *i;
86         /** Real value(s) (type \ref REAL_VALUE). */
87         real                   *r;
88         /** String value(s) (type \ref STR_VALUE). */
89         char                  **s;
90         /** Structure for the position value(s) (type \ref POS_VALUE). */
91         struct gmx_ana_pos_t   *p;
92         /** Group value (type \ref GROUP_VALUE). */
93         struct gmx_ana_index_t *g;
94         /** Boolean value (only parameters of type \ref NO_VALUE); */
95         bool                   *b;
96     }                           u;
97     /*! \brief
98      * Number of elements allocated for the value array.
99      */
100     int                         nalloc;
101 } gmx_ana_selvalue_t;
102
103 /** Initializes an empty selection value structure. */
104 void
105 _gmx_selvalue_clear(gmx_ana_selvalue_t *val);
106 /** Reserve memory for storing selection values. */
107 int
108 _gmx_selvalue_reserve(gmx_ana_selvalue_t *val, int n);
109 /** Sets the memory for storing selection values. */
110 int
111 _gmx_selvalue_setstore(gmx_ana_selvalue_t *val, void *ptr);
112 /** Sets the memory for storing selection values and marks it for automatic freeing. */
113 int
114 _gmx_selvalue_setstore_alloc(gmx_ana_selvalue_t *val, void *ptr, int nalloc);
115
116 #endif