2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifndef GMX_FILEIO_GMX_SYSTEM_XDR_H
39 #define GMX_FILEIO_GMX_SYSTEM_XDR_H
47 * This header file is ONLY used on windows systems, since these do
48 * not include the XDR routines present on a unix machine. It will
49 * most probably work on other platforms too, but make sure you
50 * test that the xtc files produced are ok before using it.
52 * This header file contains Gromacs versions of the definitions for
53 * Sun External Data Representation (XDR) headers and routines.
55 * On most UNIX systems this is already present as part of your
56 * system libraries, but since we want to make Gromacs portable to
57 * platforms like Microsoft Windows we have created a private version
58 * of the necessary routines and distribute them with the Gromacs source.
60 * Although the rest of Gromacs is LGPL, you can copy and use the XDR
61 * routines in any way you want as long as you obey Sun's license:
63 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
64 * unrestricted use provided that this legend is included on all tape
65 * media and as a part of the software program in whole or part. Users
66 * may copy or modify Sun RPC without charge, but are not authorized
67 * to license or distribute it to anyone else except as part of a product or
68 * program developed by the user.
70 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
71 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
72 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
74 * Sun RPC is provided with no support and without any obligation on the
75 * part of Sun Microsystems, Inc. to assist in its use, correction,
76 * modification or enhancement.
78 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
79 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
80 * OR ANY PART THEREOF.
82 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
83 * or profits or other special, indirect and consequential damages, even if
84 * Sun has been advised of the possibility of such damages.
86 * Sun Microsystems, Inc.
88 * Mountain View, California 94043
96 * Xdr operations. XDR_ENCODE causes the type to be encoded into the
97 * stream. XDR_DECODE causes the type to be extracted from the stream.
98 * XDR_FREE can be used to release the space allocated by an
102 /* We already have a boolean type in Gromacs, but the XDR library
103 * one has a slightly different name (the calls should be identical).
108 * Aninteger type that is 32 bits wide. Check if int,
109 * long or short is 32 bits and die if none of them is :-)
111 #if (INT_MAX == 2147483647)
112 typedef int xdr_int32_t;
113 typedef unsigned int xdr_uint32_t;
114 #elif (LONG_MAX == 2147483647L)
115 typedef long xdr_int32_t;
116 typedef unsigned long xdr_uint32_t;
117 #elif (SHRT_MAX == 2147483647)
118 typedef short xdr_int32_t;
119 typedef unsigned short xdr_uint32_t;
121 # error ERROR: No 32 bit wide integer type found!
138 #define BYTES_PER_XDR_UNIT (4)
139 /* Macro to round up to units of 4. */
140 #define XDR_RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1))
145 * Contains operation which is being applied to the stream,
146 * an operations vector for the particular implementation (e.g. see xdr_mem.c),
147 * and two private fields for the use of the particular implementation.
149 typedef struct XDR XDR;
152 enum xdr_op x_op; /* operation; fast additional param */
155 bool_t (*x_getbytes) (XDR *__xdrs, char *__addr, unsigned int __len);
156 /* get some bytes from " */
157 bool_t (*x_putbytes) (XDR *__xdrs, char *__addr, unsigned int __len);
158 /* put some bytes to " */
159 unsigned int (*x_getpostn) (XDR *__xdrs);
160 /* returns bytes off from beginning */
161 bool_t (*x_setpostn) (XDR *__xdrs, unsigned int __pos);
162 /* lets you reposition the stream */
163 xdr_int32_t *(*x_inline) (XDR *__xdrs, int __len);
164 /* buf quick ptr to buffered data */
165 void (*x_destroy) (XDR *__xdrs);
166 /* free privates of this xdr_stream */
167 bool_t (*x_getint32) (XDR *__xdrs, xdr_int32_t *__ip);
168 /* get a int from underlying stream */
169 bool_t (*x_putint32) (XDR *__xdrs, xdr_int32_t *__ip);
171 bool_t (*x_getuint32) (XDR *__xdrs, xdr_uint32_t *__ip);
172 /* get a unsigned int from underlying stream */
173 bool_t (*x_putuint32) (XDR *__xdrs, xdr_uint32_t *__ip);
177 char *x_public; /* users' data */
178 char *x_private; /* pointer to private data */
179 char *x_base; /* private used for position info */
180 int x_handy; /* extra private word */
184 * A xdrproc_t exists for each data type which is to be encoded or decoded.
186 * The second argument to the xdrproc_t is a pointer to an opaque pointer.
187 * The opaque pointer generally points to a structure of the data type
188 * to be decoded. If this pointer is 0, then the type routines should
189 * allocate dynamic storage of the appropriate size and return it.
192 typedef bool_t (*xdrproc_t) (XDR *, void *, ...);
195 * Operations defined on a XDR handle
198 * xdr_int32_t *int32p;
206 #define xdr_getint32(xdrs, int32p) \
207 (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
209 #define xdr_putint32(xdrs, int32p) \
210 (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
212 #define xdr_getuint32(xdrs, uint32p) \
213 (*(xdrs)->x_ops->x_getuint32)(xdrs, uint32p)
215 #define xdr_putuint32(xdrs, uint32p) \
216 (*(xdrs)->x_ops->x_putuint32)(xdrs, uint32p)
218 #define xdr_getbytes(xdrs, addr, len) \
219 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
221 #define xdr_putbytes(xdrs, addr, len) \
222 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
224 #define xdr_getpos(xdrs) \
225 (*(xdrs)->x_ops->x_getpostn)(xdrs)
227 #define xdr_setpos(xdrs, pos) \
228 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
230 #define xdr_inline(xdrs, len) \
231 (*(xdrs)->x_ops->x_inline)(xdrs, len)
233 #define xdr_destroy(xdrs) \
235 if ((xdrs)->x_ops->x_destroy) { \
236 (*(xdrs)->x_ops->x_destroy)(xdrs); } \
240 bool_t xdr_int (XDR *__xdrs, int *__ip);
241 bool_t xdr_u_int (XDR *__xdrs, unsigned int *__ip);
242 bool_t xdr_short (XDR *__xdrs, short *__ip);
243 bool_t xdr_u_short (XDR *__xdrs, unsigned short *__ip);
244 bool_t xdr_bool (XDR *__xdrs, int *__bp);
245 bool_t xdr_opaque (XDR *__xdrs, char *__cp, unsigned int __cnt);
246 bool_t xdr_string (XDR *__xdrs, char **__cpp, unsigned int __maxsize);
247 bool_t xdr_char (XDR *__xdrs, char *__cp);
248 bool_t xdr_u_char (XDR *__xdrs, unsigned char *__cp);
249 bool_t xdr_vector (XDR *__xdrs, char *__basep, unsigned int __nelem,
250 unsigned int __elemsize, xdrproc_t __xdr_elem);
251 bool_t xdr_float (XDR *__xdrs, float *__fp);
252 bool_t xdr_double (XDR *__xdrs, double *__dp);
253 void xdrstdio_create (XDR *__xdrs, FILE *__file, enum xdr_op __xop);
255 /* free memory buffers for xdr */
256 void xdr_free (xdrproc_t __proc, char *__objp);
262 #endif /* GMX_FILEIO_GMX_SYSTEM_XDR_H */