Merge remote-tracking branch 'gerrit/release-4-5-patches' into release-4-6
[gromacs.git] / include / gmx_system_xdr.h
blob8538ab371abcfc9107558dbabf26dad4c310aaed
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 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Gromacs Runs On Most of All Computer Systems
36 #ifndef _gmx_system_xdr_h
37 #define _gmx_system_xdr_h
39 #include <limits.h>
40 #include <stdio.h>
41 #include <stdlib.h>
45 * This header file is ONLY used on windows systems, since these do
46 * not include the XDR routines present on a unix machine. It will
47 * most probably work on other platforms too, but make sure you
48 * test that the xtc files produced are ok before using it.
50 * This header file contains Gromacs versions of the definitions for
51 * Sun External Data Representation (XDR) headers and routines.
53 * On most UNIX systems this is already present as part of your
54 * system libraries, but since we want to make Gromacs portable to
55 * platforms like Microsoft Windows we have created a private version
56 * of the necessary routines and distribute them with the Gromacs source.
58 * Although the rest of Gromacs is GPL, you can copy and use the XDR
59 * routines in any way you want as long as you obey Sun's license:
61 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
62 * unrestricted use provided that this legend is included on all tape
63 * media and as a part of the software program in whole or part. Users
64 * may copy or modify Sun RPC without charge, but are not authorized
65 * to license or distribute it to anyone else except as part of a product or
66 * program developed by the user.
68 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
69 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
70 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
72 * Sun RPC is provided with no support and without any obligation on the
73 * part of Sun Microsystems, Inc. to assist in its use, correction,
74 * modification or enhancement.
76 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
77 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
78 * OR ANY PART THEREOF.
80 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
81 * or profits or other special, indirect and consequential damages, even if
82 * Sun has been advised of the possibility of such damages.
84 * Sun Microsystems, Inc.
85 * 2550 Garcia Avenue
86 * Mountain View, California 94043
87 */
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
94 * Xdr operations. XDR_ENCODE causes the type to be encoded into the
95 * stream. XDR_DECODE causes the type to be extracted from the stream.
96 * XDR_FREE can be used to release the space allocated by an
97 * XDR_DECODE request.
100 /* We already have a boolean type in Gromacs, but the XDR library
101 * one has a slightly different name (the calls should be identical).
103 typedef int bool_t;
106 * Aninteger type that is 32 bits wide. Check if int,
107 * long or short is 32 bits and die if none of them is :-)
109 #if (INT_MAX == 2147483647)
110 typedef int xdr_int32_t;
111 typedef unsigned int xdr_uint32_t;
112 #elif (LONG_MAX == 2147483647L)
113 typedef long xdr_int32_t;
114 typedef unsigned long xdr_uint32_t;
115 #elif (SHRT_MAX == 2147483647)
116 typedef short xdr_int32_t;
117 typedef unsigned short xdr_uint32_t;
118 #else
119 # error ERROR: No 32 bit wide integer type found!
120 #endif
122 enum xdr_op {
123 XDR_ENCODE = 0,
124 XDR_DECODE = 1,
125 XDR_FREE = 2
128 #ifndef FALSE
129 # define FALSE (0)
130 #endif
131 #ifndef TRUE
132 # define TRUE (1)
133 #endif
136 #define BYTES_PER_XDR_UNIT (4)
137 /* Macro to round up to units of 4. */
138 #define XDR_RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1))
142 * The XDR handle.
143 * Contains operation which is being applied to the stream,
144 * an operations vector for the particular implementation (e.g. see xdr_mem.c),
145 * and two private fields for the use of the particular implementation.
147 typedef struct XDR XDR;
148 struct XDR
150 enum xdr_op x_op; /* operation; fast additional param */
151 struct xdr_ops
153 bool_t (*x_getbytes) (XDR *__xdrs, char *__addr, unsigned int __len);
154 /* get some bytes from " */
155 bool_t (*x_putbytes) (XDR *__xdrs, char *__addr, unsigned int __len);
156 /* put some bytes to " */
157 unsigned int (*x_getpostn) (XDR *__xdrs);
158 /* returns bytes off from beginning */
159 bool_t (*x_setpostn) (XDR *__xdrs, unsigned int __pos);
160 /* lets you reposition the stream */
161 xdr_int32_t *(*x_inline) (XDR *__xdrs, int __len);
162 /* buf quick ptr to buffered data */
163 void (*x_destroy) (XDR *__xdrs);
164 /* free privates of this xdr_stream */
165 bool_t (*x_getint32) (XDR *__xdrs, xdr_int32_t *__ip);
166 /* get a int from underlying stream */
167 bool_t (*x_putint32) (XDR *__xdrs, xdr_int32_t *__ip);
168 /* put a int to " */
169 bool_t (*x_getuint32) (XDR *__xdrs, xdr_uint32_t *__ip);
170 /* get a unsigned int from underlying stream */
171 bool_t (*x_putuint32) (XDR *__xdrs, xdr_uint32_t *__ip);
172 /* put a int to " */
174 *x_ops;
175 char *x_public; /* users' data */
176 char *x_private; /* pointer to private data */
177 char *x_base; /* private used for position info */
178 int x_handy; /* extra private word */
182 * A xdrproc_t exists for each data type which is to be encoded or decoded.
184 * The second argument to the xdrproc_t is a pointer to an opaque pointer.
185 * The opaque pointer generally points to a structure of the data type
186 * to be decoded. If this pointer is 0, then the type routines should
187 * allocate dynamic storage of the appropriate size and return it.
190 typedef bool_t (*xdrproc_t) (XDR *, void *,...);
193 * Operations defined on a XDR handle
195 * XDR *xdrs;
196 * xdr_int32_t *int32p;
197 * long *longp;
198 * char *addr;
199 * unsigned int len;
200 * unsigned int pos;
204 #define xdr_getint32(xdrs, int32p) \
205 (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
207 #define xdr_putint32(xdrs, int32p) \
208 (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
210 #define xdr_getuint32(xdrs, uint32p) \
211 (*(xdrs)->x_ops->x_getuint32)(xdrs, uint32p)
213 #define xdr_putuint32(xdrs, uint32p) \
214 (*(xdrs)->x_ops->x_putuint32)(xdrs, uint32p)
216 #define xdr_getbytes(xdrs, addr, len) \
217 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
219 #define xdr_putbytes(xdrs, addr, len) \
220 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
222 #define xdr_getpos(xdrs) \
223 (*(xdrs)->x_ops->x_getpostn)(xdrs)
225 #define xdr_setpos(xdrs, pos) \
226 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
228 #define xdr_inline(xdrs, len) \
229 (*(xdrs)->x_ops->x_inline)(xdrs, len)
231 #define xdr_destroy(xdrs) \
232 do { \
233 if ((xdrs)->x_ops->x_destroy) \
234 (*(xdrs)->x_ops->x_destroy)(xdrs); \
235 } while (0)
238 bool_t xdr_int (XDR *__xdrs, int *__ip);
239 bool_t xdr_u_int (XDR *__xdrs, unsigned int *__ip);
240 bool_t xdr_short (XDR *__xdrs, short *__ip);
241 bool_t xdr_u_short (XDR *__xdrs, unsigned short *__ip);
242 bool_t xdr_bool (XDR *__xdrs, int *__bp);
243 bool_t xdr_opaque (XDR *__xdrs, char *__cp, unsigned int __cnt);
244 bool_t xdr_string (XDR *__xdrs, char **__cpp, unsigned int __maxsize);
245 bool_t xdr_char (XDR *__xdrs, char *__cp);
246 bool_t xdr_u_char (XDR *__xdrs, unsigned char *__cp);
247 bool_t xdr_vector (XDR *__xdrs, char *__basep, unsigned int __nelem,
248 unsigned int __elemsize, xdrproc_t __xdr_elem);
249 bool_t xdr_float (XDR *__xdrs, float *__fp);
250 bool_t xdr_double (XDR *__xdrs, double *__dp);
251 void xdrstdio_create (XDR *__xdrs, FILE *__file, enum xdr_op __xop);
253 /* free memory buffers for xdr */
254 void xdr_free (xdrproc_t __proc, char *__objp);
256 #ifdef __cplusplus
258 #endif
260 #endif /* _gmx_system_xdr_h */