Fixed the config.h inclusion
[gromacs.git] / include / gmx_system_xdr.h
blob99ff38cca6d56c1d00b1cb38920403056f4e18b0
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * Gromacs Runs On Most of All Computer Systems
37 #ifndef _gmx_system_xdr_h
38 #define _gmx_system_xdr_h
40 #include <limits.h>
41 #include <stdio.h>
42 #include <stdlib.h>
46 * This header file is ONLY used on windows systems, since these do
47 * not include the XDR routines present on a unix machine. It will
48 * most probably work on other platforms too, but make sure you
49 * test that the xtc files produced are ok before using it.
51 * This header file contains Gromacs versions of the definitions for
52 * Sun External Data Representation (XDR) headers and routines.
54 * On most UNIX systems this is already present as part of your
55 * system libraries, but since we want to make Gromacs portable to
56 * platforms like Microsoft Windows we have created a private version
57 * of the necessary routines and distribute them with the Gromacs source.
59 * Although the rest of Gromacs is GPL, you can copy and use the XDR
60 * routines in any way you want as long as you obey Sun's license:
62 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
63 * unrestricted use provided that this legend is included on all tape
64 * media and as a part of the software program in whole or part. Users
65 * may copy or modify Sun RPC without charge, but are not authorized
66 * to license or distribute it to anyone else except as part of a product or
67 * program developed by the user.
69 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
70 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
71 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
73 * Sun RPC is provided with no support and without any obligation on the
74 * part of Sun Microsystems, Inc. to assist in its use, correction,
75 * modification or enhancement.
77 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
78 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
79 * OR ANY PART THEREOF.
81 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
82 * or profits or other special, indirect and consequential damages, even if
83 * Sun has been advised of the possibility of such damages.
85 * Sun Microsystems, Inc.
86 * 2550 Garcia Avenue
87 * Mountain View, California 94043
88 */
91 * Xdr operations. XDR_ENCODE causes the type to be encoded into the
92 * stream. XDR_DECODE causes the type to be extracted from the stream.
93 * XDR_FREE can be used to release the space allocated by an
94 * XDR_DECODE request.
97 /* We already have a boolean type in Gromacs, but the XDR library
98 * one has a slightly different name (the calls should be identical).
100 typedef int bool_t;
103 * Aninteger type that is 32 bits wide. Check if int,
104 * long or short is 32 bits and die if none of them is :-)
106 #if (INT_MAX == 2147483647)
107 typedef int xdr_int32_t;
108 typedef unsigned int xdr_uint32_t;
109 #elif (LONG_MAX == 2147483647L)
110 typedef long xdr_int32_t;
111 typedef unsigned long xdr_uint32_t;
112 #elif (SHRT_MAX == 2147483647)
113 typedef short xdr_int32_t;
114 typedef unsigned short xdr_uint32_t;
115 #else
116 # error ERROR: No 32 bit wide integer type found!
117 #endif
120 enum xdr_op {
121 XDR_ENCODE = 0,
122 XDR_DECODE = 1,
123 XDR_FREE = 2
126 #ifndef FALSE
127 # define FALSE (0)
128 #endif
129 #ifndef TRUE
130 # define TRUE (1)
131 #endif
134 #define BYTES_PER_XDR_UNIT (4)
135 /* Macro to round up to units of 4. */
136 #define XDR_RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1))
140 * The XDR handle.
141 * Contains operation which is being applied to the stream,
142 * an operations vector for the particular implementation (e.g. see xdr_mem.c),
143 * and two private fields for the use of the particular implementation.
145 typedef struct XDR XDR;
146 struct XDR
148 enum xdr_op x_op; /* operation; fast additional param */
149 struct xdr_ops
151 bool_t (*x_getlong) (XDR *__xdrs, long *__lp);
152 /* get a long from underlying stream */
153 bool_t (*x_putlong) (XDR *__xdrs, long *__lp);
154 /* put a long to " */
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);
170 /* put a int to " */
172 *x_ops;
173 char *x_public; /* users' data */
174 char *x_private; /* pointer to private data */
175 char *x_base; /* private used for position info */
176 int x_handy; /* extra private word */
180 * A xdrproc_t exists for each data type which is to be encoded or decoded.
182 * The second argument to the xdrproc_t is a pointer to an opaque pointer.
183 * The opaque pointer generally points to a structure of the data type
184 * to be decoded. If this pointer is 0, then the type routines should
185 * allocate dynamic storage of the appropriate size and return it.
188 typedef bool_t (*xdrproc_t) (XDR *, void *,...);
191 * Operations defined on a XDR handle
193 * XDR *xdrs;
194 * xdr_int32_t *int32p;
195 * long *longp;
196 * char *addr;
197 * unsigned int len;
198 * unsigned int pos;
202 #define xdr_getint32(xdrs, int32p) \
203 (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
205 #define xdr_putint32(xdrs, int32p) \
206 (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
208 #define xdr_getlong(xdrs, longp) \
209 (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
211 #define xdr_putlong(xdrs, longp) \
212 (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
214 #define xdr_getbytes(xdrs, addr, len) \
215 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
217 #define xdr_putbytes(xdrs, addr, len) \
218 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
220 #define xdr_getpos(xdrs) \
221 (*(xdrs)->x_ops->x_getpostn)(xdrs)
223 #define xdr_setpos(xdrs, pos) \
224 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
226 #define xdr_inline(xdrs, len) \
227 (*(xdrs)->x_ops->x_inline)(xdrs, len)
229 #define xdr_destroy(xdrs) \
230 do { \
231 if ((xdrs)->x_ops->x_destroy) \
232 (*(xdrs)->x_ops->x_destroy)(xdrs); \
233 } while (0)
236 extern bool_t xdr_u_short (XDR *__xdrs, unsigned short *__usp);
237 extern bool_t xdr_int (XDR *__xdrs, int *__ip);
238 extern bool_t xdr_long (XDR *__xdrs, long *__lp);
239 extern bool_t xdr_u_long (XDR *__xdrs, unsigned long *__ulp);
240 extern bool_t xdr_bool (XDR *__xdrs, int *__bp);
241 extern bool_t xdr_opaque (XDR *__xdrs, char *__cp, unsigned int __cnt);
242 extern bool_t xdr_string (XDR *__xdrs, char **__cpp, unsigned int __maxsize);
243 extern bool_t xdr_char (XDR *__xdrs, char *__cp);
244 extern bool_t xdr_u_char (XDR *__xdrs, unsigned char *__cp);
245 extern bool_t xdr_vector (XDR *__xdrs, char *__basep, unsigned int __nelem,
246 unsigned int __elemsize, xdrproc_t __xdr_elem);
247 extern bool_t xdr_float (XDR *__xdrs, float *__fp);
248 extern bool_t xdr_double (XDR *__xdrs, double *__dp);
249 extern void xdrstdio_create (XDR *__xdrs, FILE *__file, enum xdr_op __xop);
251 /* free memory buffers for xdr */
252 extern void xdr_free (xdrproc_t __proc, char *__objp);
255 #endif /* _gmx_system_xdr_h */