Removed obsolete selection code.
[gromacs/qmmm-gamess-us.git] / src / gmxlib / selection / selvalue.c
blob769bfa544caea4d957f9bcaea1e9fb286e9f2d6e
1 /*
3 * This source code is part of
5 * G R O M A C S
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
31 /*! \internal \file
32 * \brief Implementation of functions in selvalue.h.
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
38 #include <smalloc.h>
40 #include <indexutil.h>
41 #include <position.h>
42 #include <selvalue.h>
44 /*!
45 * \param[out] val Output structure
47 * The type of \p val is not touched.
48 * Any contents of \p val are discarded without freeing.
50 void
51 _gmx_selvalue_clear(gmx_ana_selvalue_t *val)
53 val->nr = 0;
54 val->u.ptr = NULL;
55 val->nalloc = 0;
58 /*!
59 * \param[in,out] val Value structure to allocate.
60 * \param[in] n Maximum number of values needed.
61 * \returns Zero on success.
63 * Reserves memory for the values within \p val to store at least \p n values,
64 * of the type specified in the \p val structure.
66 * If the type is \ref POS_VALUE or \ref GROUP_VALUE, memory is reserved for
67 * the data structures, but no memory is reserved inside these newly allocated
68 * data structures.
69 * Similarly, for \ref STR_VALUE values, the pointers are set to NULL.
70 * For other values, the memory is uninitialized.
72 int
73 _gmx_selvalue_reserve(gmx_ana_selvalue_t *val, int n)
75 int i;
77 if (val->nalloc == -1)
79 return 0;
82 if (!val->u.ptr || val->nalloc < n)
84 switch (val->type)
86 case INT_VALUE: srenew(val->u.i, n); break;
87 case REAL_VALUE: srenew(val->u.r, n); break;
88 case STR_VALUE:
89 srenew(val->u.s, n);
90 for (i = val->nalloc; i < n; ++i)
92 val->u.s[i] = NULL;
94 break;
95 case POS_VALUE:
96 srenew(val->u.p, n);
97 for (i = val->nalloc; i < n; ++i)
99 gmx_ana_pos_clear(&val->u.p[i]);
101 break;
102 case GROUP_VALUE:
103 srenew(val->u.g, n);
104 for (i = val->nalloc; i < n; ++i)
106 gmx_ana_index_clear(&val->u.g[i]);
108 break;
109 case NO_VALUE: break;
111 val->nalloc = n;
113 return 0;
117 * \param[in,out] val Value structure to allocate.
118 * \param[in] ptr Pointer where the values should be stored.
119 * \returns Zero on success.
121 * Automatic memory management is disabled for \p ptr, unless \p ptr is NULL.
124 _gmx_selvalue_setstore(gmx_ana_selvalue_t *val, void *ptr)
126 val->u.ptr = ptr;
127 val->nalloc = (ptr ? -1 : 0);
128 return 0;
132 * \param[in,out] val Value structure to allocate.
133 * \param[in] ptr Pointer where the values should be stored.
134 * \param[in] nalloc Number of values allocated for \p ptr.
135 * \returns Zero on success.
138 _gmx_selvalue_setstore_alloc(gmx_ana_selvalue_t *val, void *ptr, int nalloc)
140 val->u.ptr = ptr;
141 val->nalloc = nalloc;
142 return 0;