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