3 * This source code is part of
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
32 * \brief Implementation of functions in selvalue.h.
40 #include <indexutil.h>
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.
51 _gmx_selvalue_clear(gmx_ana_selvalue_t
*val
)
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
69 * Similarly, for \ref STR_VALUE values, the pointers are set to NULL.
70 * For other values, the memory is uninitialized.
73 _gmx_selvalue_reserve(gmx_ana_selvalue_t
*val
, int n
)
77 if (val
->nalloc
== -1)
82 if (!val
->u
.ptr
|| val
->nalloc
< n
)
86 case INT_VALUE
: srenew(val
->u
.i
, n
); break;
87 case REAL_VALUE
: srenew(val
->u
.r
, n
); break;
90 for (i
= val
->nalloc
; i
< n
; ++i
)
97 for (i
= val
->nalloc
; i
< n
; ++i
)
99 gmx_ana_pos_clear(&val
->u
.p
[i
]);
104 for (i
= val
->nalloc
; i
< n
; ++i
)
106 gmx_ana_index_clear(&val
->u
.g
[i
]);
109 case NO_VALUE
: break;
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
)
127 val
->nalloc
= (ptr
? -1 : 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
)
141 val
->nalloc
= nalloc
;