Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / fileio / gmxfio_xdr.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #include "gmxpre.h"
38
39 #include "gmxfio_xdr.h"
40
41 #include <cstdio>
42 #include <cstring>
43
44 #include "gromacs/fileio/gmxfio.h"
45 #include "gromacs/fileio/xdrf.h"
46 #include "gromacs/utility/fatalerror.h"
47 #include "gromacs/utility/gmxassert.h"
48 #include "gromacs/utility/smalloc.h"
49
50 #include "gmxfio_impl.h"
51
52 /* Enumerated for data types in files */
53 enum
54 {
55     eioREAL,
56     eioFLOAT,
57     eioDOUBLE,
58     eioINT,
59     eioINT32,
60     eioINT64,
61     eioUCHAR,
62     eioCHAR,
63     eioNCHAR,
64     eioNUCHAR,
65     eioUSHORT,
66     eioRVEC,
67     eioNRVEC,
68     eioIVEC,
69     eioSTRING,
70     eioNR
71 };
72
73 static const char* eioNames[eioNR] = { "REAL",   "FLOAT", "DOUBLE", "INT",   "INT32",
74                                        "INT64",  "UCHAR", "CHAR",   "NCHAR", "NUCHAR",
75                                        "USHORT", "RVEC",  "NRVEC",  "IVEC",  "STRING" };
76
77 void gmx_fio_setprecision(t_fileio* fio, gmx_bool bDouble)
78 {
79     gmx_fio_lock(fio);
80     fio->bDouble = bDouble;
81     gmx_fio_unlock(fio);
82 }
83
84 bool gmx_fio_is_double(t_fileio* fio)
85 {
86     bool isDouble = false;
87     gmx_fio_lock(fio);
88     isDouble = fio->bDouble;
89     gmx_fio_unlock(fio);
90     return isDouble;
91 }
92
93 XDR* gmx_fio_getxdr(t_fileio* fio)
94 {
95     XDR* ret = nullptr;
96     gmx_fio_lock(fio);
97     GMX_RELEASE_ASSERT(fio->xdr != nullptr, "Implementation error: NULL XDR pointers");
98     ret = fio->xdr;
99     gmx_fio_unlock(fio);
100     return ret;
101 }
102
103 /* check the number of items given against the type */
104 static void gmx_fio_check_nitem(int eio, int nitem, const char* file, int line)
105 {
106     if ((nitem != 1) && !((eio == eioNRVEC) || (eio == eioNUCHAR) || (eio == eioNCHAR)))
107     {
108         gmx_fatal(FARGS,
109                   "nitem (%d) may differ from 1 only for %s, %s or %s, not   for %s"
110                   "(%s, %d)",
111                   nitem, eioNames[eioNUCHAR], eioNames[eioNRVEC], eioNames[eioNCHAR], eioNames[eio],
112                   file, line);
113     }
114 }
115
116 /* output a data type error. */
117 [[noreturn]] static void gmx_fio_fe(t_fileio* fio, int eio, const char* desc, const char* srcfile, int line)
118 {
119     gmx_fatal(FARGS, "Trying to %s %s type %d (%s), src %s, line %d", fio->bRead ? "read" : "write",
120               desc, eio, ((eio >= 0) && (eio < eioNR)) ? eioNames[eio] : "unknown", srcfile, line);
121 }
122
123 /* This is the part that reads xdr files.  */
124
125 static gmx_bool do_xdr(t_fileio* fio, void* item, int nitem, int eio, const char* desc, const char* srcfile, int line)
126 {
127     unsigned char  ucdum, *ucptr;
128     char           cdum, *cptr;
129     bool_t         res = 0;
130     float          fvec[DIM];
131     double         dvec[DIM];
132     int            j, m, *iptr, idum;
133     int32_t        s32dum;
134     int64_t        s64dum;
135     real*          ptr;
136     unsigned short us;
137     double         d = 0;
138     float          f = 0;
139
140     GMX_RELEASE_ASSERT(fio->xdr != nullptr, "Implementation error: NULL XDR pointers");
141     gmx_fio_check_nitem(eio, nitem, srcfile, line);
142     switch (eio)
143     {
144         case eioREAL:
145             if (fio->bDouble)
146             {
147                 if (item && !fio->bRead)
148                 {
149                     d = *(static_cast<real*>(item));
150                 }
151                 res = xdr_double(fio->xdr, &d);
152                 if (item)
153                 {
154                     *(static_cast<real*>(item)) = d;
155                 }
156             }
157             else
158             {
159                 if (item && !fio->bRead)
160                 {
161                     f = *(static_cast<real*>(item));
162                 }
163                 res = xdr_float(fio->xdr, &f);
164                 if (item)
165                 {
166                     *(static_cast<real*>(item)) = f;
167                 }
168             }
169             break;
170         case eioFLOAT:
171             if (item && !fio->bRead)
172             {
173                 f = *(static_cast<float*>(item));
174             }
175             res = xdr_float(fio->xdr, &f);
176             if (item)
177             {
178                 *(static_cast<float*>(item)) = f;
179             }
180             break;
181         case eioDOUBLE:
182             if (item && !fio->bRead)
183             {
184                 d = *(static_cast<double*>(item));
185             }
186             res = xdr_double(fio->xdr, &d);
187             if (item)
188             {
189                 *(static_cast<double*>(item)) = d;
190             }
191             break;
192         case eioINT:
193             if (item && !fio->bRead)
194             {
195                 idum = *static_cast<int*>(item);
196             }
197             res = xdr_int(fio->xdr, &idum);
198             if (item)
199             {
200                 *static_cast<int*>(item) = idum;
201             }
202             break;
203         case eioINT32:
204             if (item && !fio->bRead)
205             {
206                 s32dum = *static_cast<int32_t*>(item);
207             }
208             res = xdr_int32(fio->xdr, &s32dum);
209             if (item)
210             {
211                 *static_cast<int32_t*>(item) = s32dum;
212             }
213             break;
214         case eioINT64:
215             if (item && !fio->bRead)
216             {
217                 s64dum = *static_cast<int64_t*>(item);
218             }
219             res = xdr_int64(fio->xdr, &s64dum);
220             if (item)
221             {
222                 *static_cast<int64_t*>(item) = s64dum;
223             }
224             break;
225         case eioUCHAR:
226             if (item && !fio->bRead)
227             {
228                 ucdum = *static_cast<unsigned char*>(item);
229             }
230             res = xdr_u_char(fio->xdr, &ucdum);
231             if (item)
232             {
233                 *static_cast<unsigned char*>(item) = ucdum;
234             }
235             break;
236         case eioCHAR:
237             if (item && !fio->bRead)
238             {
239                 cdum = *static_cast<char*>(item);
240             }
241             res = xdr_char(fio->xdr, &cdum);
242             if (item)
243             {
244                 *static_cast<char*>(item) = cdum;
245             }
246             break;
247         case eioNCHAR:
248             cptr = static_cast<char*>(item);
249             res  = xdr_vector(fio->xdr, cptr, nitem, static_cast<unsigned int>(sizeof(char)),
250                              reinterpret_cast<xdrproc_t>(xdr_char));
251             break;
252         case eioNUCHAR:
253             ucptr = static_cast<unsigned char*>(item);
254             res   = xdr_vector(fio->xdr, reinterpret_cast<char*>(ucptr), nitem,
255                              static_cast<unsigned int>(sizeof(unsigned char)),
256                              reinterpret_cast<xdrproc_t>(xdr_u_char));
257             break;
258         case eioUSHORT:
259             if (item && !fio->bRead)
260             {
261                 us = *static_cast<unsigned short*>(item);
262             }
263             res = xdr_u_short(fio->xdr, &us);
264             if (item)
265             {
266                 *static_cast<unsigned short*>(item) = us;
267             }
268             break;
269         case eioRVEC:
270             if (fio->bDouble)
271             {
272                 if (item && !fio->bRead)
273                 {
274                     for (m = 0; (m < DIM); m++)
275                     {
276                         dvec[m] = (static_cast<real*>(item))[m];
277                     }
278                 }
279                 res = xdr_vector(fio->xdr, reinterpret_cast<char*>(dvec), DIM,
280                                  static_cast<unsigned int>(sizeof(double)),
281                                  reinterpret_cast<xdrproc_t>(xdr_double));
282                 if (item)
283                 {
284                     for (m = 0; (m < DIM); m++)
285                     {
286                         (static_cast<real*>(item))[m] = dvec[m];
287                     }
288                 }
289             }
290             else
291             {
292                 if (item && !fio->bRead)
293                 {
294                     for (m = 0; (m < DIM); m++)
295                     {
296                         fvec[m] = (static_cast<real*>(item))[m];
297                     }
298                 }
299                 res = xdr_vector(fio->xdr, reinterpret_cast<char*>(fvec), DIM,
300                                  static_cast<unsigned int>(sizeof(float)),
301                                  reinterpret_cast<xdrproc_t>(xdr_float));
302                 if (item)
303                 {
304                     for (m = 0; (m < DIM); m++)
305                     {
306                         (static_cast<real*>(item))[m] = fvec[m];
307                     }
308                 }
309             }
310             break;
311         case eioNRVEC:
312             ptr = nullptr;
313             res = 1;
314             for (j = 0; (j < nitem) && res; j++)
315             {
316                 if (item)
317                 {
318                     ptr = (static_cast<rvec*>(item))[j];
319                 }
320                 res = static_cast<bool_t>(do_xdr(fio, ptr, 1, eioRVEC, desc, srcfile, line));
321             }
322             break;
323         case eioIVEC:
324             iptr = static_cast<int*>(item);
325             res  = 1;
326             for (m = 0; (m < DIM) && res; m++)
327             {
328                 if (item && !fio->bRead)
329                 {
330                     idum = iptr[m];
331                 }
332                 res = xdr_int(fio->xdr, &idum);
333                 if (item)
334                 {
335                     iptr[m] = idum;
336                 }
337             }
338             break;
339         case eioSTRING:
340         {
341             char* cptr;
342             int   slen;
343
344             if (item)
345             {
346                 if (!fio->bRead)
347                 {
348                     slen = strlen(static_cast<char*>(item)) + 1;
349                 }
350                 else
351                 {
352                     slen = 0;
353                 }
354             }
355             else
356             {
357                 slen = 0;
358             }
359
360             if (xdr_int(fio->xdr, &slen) <= 0)
361             {
362                 gmx_fatal(FARGS,
363                           "wrong string length %d for string %s"
364                           " (source %s, line %d)",
365                           slen, desc, srcfile, line);
366             }
367             if (!item && fio->bRead)
368             {
369                 snew(cptr, slen);
370             }
371             else
372             {
373                 cptr = static_cast<char*>(item);
374             }
375             if (cptr)
376             {
377                 res = xdr_string(fio->xdr, &cptr, slen);
378             }
379             else
380             {
381                 res = 1;
382             }
383             if (!item && fio->bRead)
384             {
385                 sfree(cptr);
386             }
387             break;
388         }
389         default: gmx_fio_fe(fio, eio, desc, srcfile, line);
390     }
391
392     return (res != 0);
393 }
394
395 /*******************************************************************
396  *
397  * READ/WRITE FUNCTIONS
398  *
399  *******************************************************************/
400
401 gmx_bool gmx_fio_writee_string(t_fileio* fio, const char* item, const char* desc, const char* srcfile, int line)
402 {
403     gmx_bool ret;
404     void*    it = const_cast<char*>(item); /* ugh.. */
405     gmx_fio_lock(fio);
406     ret = do_xdr(fio, it, 1, eioSTRING, desc, srcfile, line);
407     gmx_fio_unlock(fio);
408     return ret;
409 }
410
411 gmx_bool gmx_fio_doe_real(t_fileio* fio, real* item, const char* desc, const char* srcfile, int line)
412 {
413     gmx_bool ret;
414     gmx_fio_lock(fio);
415     ret = do_xdr(fio, item, 1, eioREAL, desc, srcfile, line);
416     gmx_fio_unlock(fio);
417     return ret;
418 }
419
420 gmx_bool gmx_fio_doe_float(t_fileio* fio, float* item, const char* desc, const char* srcfile, int line)
421 {
422     gmx_bool ret;
423     gmx_fio_lock(fio);
424     ret = do_xdr(fio, item, 1, eioFLOAT, desc, srcfile, line);
425     gmx_fio_unlock(fio);
426     return ret;
427 }
428
429 gmx_bool gmx_fio_doe_double(t_fileio* fio, double* item, const char* desc, const char* srcfile, int line)
430 {
431     gmx_bool ret;
432     gmx_fio_lock(fio);
433     ret = do_xdr(fio, item, 1, eioDOUBLE, desc, srcfile, line);
434     gmx_fio_unlock(fio);
435     return ret;
436 }
437
438
439 gmx_bool gmx_fio_doe_gmx_bool(t_fileio* fio, gmx_bool* item, const char* desc, const char* srcfile, int line)
440 {
441     gmx_bool ret;
442
443     gmx_fio_lock(fio);
444     if (fio->bRead)
445     {
446         int itmp = 0;
447         ret      = do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
448         *item    = (itmp != 0);
449     }
450     else
451     {
452         int itmp = static_cast<int>(*item);
453         ret      = do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
454     }
455     gmx_fio_unlock(fio);
456     return ret;
457 }
458
459 gmx_bool gmx_fio_doe_int(t_fileio* fio, int* item, const char* desc, const char* srcfile, int line)
460 {
461     gmx_bool ret;
462     gmx_fio_lock(fio);
463     ret = do_xdr(fio, item, 1, eioINT, desc, srcfile, line);
464     gmx_fio_unlock(fio);
465     return ret;
466 }
467
468 gmx_bool gmx_fio_doe_int32(t_fileio* fio, int32_t* item, const char* desc, const char* srcfile, int line)
469 {
470     gmx_bool ret;
471     gmx_fio_lock(fio);
472     ret = do_xdr(fio, item, 1, eioINT32, desc, srcfile, line);
473     gmx_fio_unlock(fio);
474     return ret;
475 }
476
477 gmx_bool gmx_fio_doe_int64(t_fileio* fio, int64_t* item, const char* desc, const char* srcfile, int line)
478 {
479     gmx_bool ret;
480     gmx_fio_lock(fio);
481     ret = do_xdr(fio, item, 1, eioINT64, desc, srcfile, line);
482     gmx_fio_unlock(fio);
483     return ret;
484 }
485
486 gmx_bool gmx_fio_doe_uchar(t_fileio* fio, unsigned char* item, const char* desc, const char* srcfile, int line)
487 {
488     gmx_bool ret;
489     gmx_fio_lock(fio);
490     ret = do_xdr(fio, item, 1, eioUCHAR, desc, srcfile, line);
491     gmx_fio_unlock(fio);
492     return ret;
493 }
494
495 gmx_bool gmx_fio_doe_char(t_fileio* fio, char* item, const char* desc, const char* srcfile, int line)
496 {
497     gmx_bool ret;
498     gmx_fio_lock(fio);
499     ret = do_xdr(fio, item, 1, eioCHAR, desc, srcfile, line);
500     gmx_fio_unlock(fio);
501     return ret;
502 }
503
504 gmx_bool gmx_fio_doe_ushort(t_fileio* fio, unsigned short* item, const char* desc, const char* srcfile, int line)
505 {
506     gmx_bool ret;
507     gmx_fio_lock(fio);
508     ret = do_xdr(fio, item, 1, eioUSHORT, desc, srcfile, line);
509     gmx_fio_unlock(fio);
510     return ret;
511 }
512
513 gmx_bool gmx_fio_doe_rvec(t_fileio* fio, rvec* item, const char* desc, const char* srcfile, int line)
514 {
515     gmx_bool ret;
516     gmx_fio_lock(fio);
517     ret = do_xdr(fio, item, 1, eioRVEC, desc, srcfile, line);
518     gmx_fio_unlock(fio);
519     return ret;
520 }
521
522 gmx_bool gmx_fio_doe_ivec(t_fileio* fio, ivec* item, const char* desc, const char* srcfile, int line)
523 {
524     gmx_bool ret;
525     gmx_fio_lock(fio);
526     ret = do_xdr(fio, item, 1, eioIVEC, desc, srcfile, line);
527     gmx_fio_unlock(fio);
528     return ret;
529 }
530
531 gmx_bool gmx_fio_doe_string(t_fileio* fio, char* item, const char* desc, const char* srcfile, int line)
532 {
533     gmx_bool ret;
534     gmx_fio_lock(fio);
535     ret = do_xdr(fio, item, 1, eioSTRING, desc, srcfile, line);
536     gmx_fio_unlock(fio);
537     return ret;
538 }
539
540
541 /* Array reading & writing */
542
543 gmx_bool gmx_fio_ndoe_real(t_fileio* fio, real* item, int n, const char* desc, const char* srcfile, int line)
544 {
545     gmx_bool ret = TRUE;
546     int      i;
547     gmx_fio_lock(fio);
548     for (i = 0; i < n; i++)
549     {
550         ret = ret && do_xdr(fio, &(item[i]), 1, eioREAL, desc, srcfile, line);
551     }
552     gmx_fio_unlock(fio);
553     return ret;
554 }
555
556
557 gmx_bool gmx_fio_ndoe_float(t_fileio* fio, float* item, int n, const char* desc, const char* srcfile, int line)
558 {
559     gmx_bool ret = TRUE;
560     int      i;
561     gmx_fio_lock(fio);
562     for (i = 0; i < n; i++)
563     {
564         ret = ret && do_xdr(fio, &(item[i]), 1, eioFLOAT, desc, srcfile, line);
565     }
566     gmx_fio_unlock(fio);
567     return ret;
568 }
569
570
571 gmx_bool gmx_fio_ndoe_double(t_fileio* fio, double* item, int n, const char* desc, const char* srcfile, int line)
572 {
573     gmx_bool ret = TRUE;
574     int      i;
575     gmx_fio_lock(fio);
576     for (i = 0; i < n; i++)
577     {
578         ret = ret && do_xdr(fio, &(item[i]), 1, eioDOUBLE, desc, srcfile, line);
579     }
580     gmx_fio_unlock(fio);
581     return ret;
582 }
583
584
585 gmx_bool gmx_fio_ndoe_gmx_bool(t_fileio* fio, gmx_bool* item, int n, const char* desc, const char* srcfile, int line)
586 {
587     gmx_bool ret = TRUE;
588     int      i;
589
590     gmx_fio_lock(fio);
591     for (i = 0; i < n; i++)
592     {
593         if (fio->bRead)
594         {
595             int itmp = 0;
596             ret      = ret && do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
597             item[i]  = (itmp != 0);
598         }
599         else
600         {
601             int itmp = static_cast<int>(item[i]);
602             ret      = ret && do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
603         }
604     }
605     gmx_fio_unlock(fio);
606     return ret;
607 }
608
609 gmx_bool gmx_fio_ndoe_int(t_fileio* fio, int* item, int n, const char* desc, const char* srcfile, int line)
610 {
611     gmx_bool ret = TRUE;
612     int      i;
613     gmx_fio_lock(fio);
614     for (i = 0; i < n; i++)
615     {
616         ret = ret && do_xdr(fio, &(item[i]), 1, eioINT, desc, srcfile, line);
617     }
618     gmx_fio_unlock(fio);
619     return ret;
620 }
621
622
623 gmx_bool gmx_fio_ndoe_int64(t_fileio* fio, int64_t* item, int n, const char* desc, const char* srcfile, int line)
624 {
625     gmx_bool ret = TRUE;
626     int      i;
627     gmx_fio_lock(fio);
628     for (i = 0; i < n; i++)
629     {
630         ret = ret && do_xdr(fio, &(item[i]), 1, eioINT64, desc, srcfile, line);
631     }
632     gmx_fio_unlock(fio);
633     return ret;
634 }
635
636
637 gmx_bool gmx_fio_ndoe_uchar(t_fileio* fio, unsigned char* item, int n, const char* desc, const char* srcfile, int line)
638 {
639     gmx_bool ret = TRUE;
640     gmx_fio_lock(fio);
641     ret = ret && do_xdr(fio, item, n, eioNUCHAR, desc, srcfile, line);
642     gmx_fio_unlock(fio);
643     return ret;
644 }
645
646 gmx_bool gmx_fio_ndoe_char(t_fileio* fio, char* item, int n, const char* desc, const char* srcfile, int line)
647 {
648     gmx_bool ret = TRUE;
649     gmx_fio_lock(fio);
650     ret = ret && do_xdr(fio, item, n, eioNCHAR, desc, srcfile, line);
651     gmx_fio_unlock(fio);
652     return ret;
653 }
654
655
656 gmx_bool gmx_fio_ndoe_ushort(t_fileio* fio, unsigned short* item, int n, const char* desc, const char* srcfile, int line)
657 {
658     gmx_bool ret = TRUE;
659     int      i;
660     gmx_fio_lock(fio);
661     for (i = 0; i < n; i++)
662     {
663         ret = ret && do_xdr(fio, &(item[i]), 1, eioUSHORT, desc, srcfile, line);
664     }
665     gmx_fio_unlock(fio);
666     return ret;
667 }
668
669
670 gmx_bool gmx_fio_ndoe_rvec(t_fileio* fio, rvec* item, int n, const char* desc, const char* srcfile, int line)
671 {
672     gmx_bool ret = TRUE;
673     gmx_fio_lock(fio);
674     ret = ret && do_xdr(fio, item, n, eioNRVEC, desc, srcfile, line);
675     gmx_fio_unlock(fio);
676     return ret;
677 }
678
679
680 gmx_bool gmx_fio_ndoe_ivec(t_fileio* fio, ivec* item, int n, const char* desc, const char* srcfile, int line)
681 {
682     gmx_bool ret = TRUE;
683     int      i;
684     gmx_fio_lock(fio);
685     for (i = 0; i < n; i++)
686     {
687         ret = ret && do_xdr(fio, &(item[i]), 1, eioIVEC, desc, srcfile, line);
688     }
689     gmx_fio_unlock(fio);
690     return ret;
691 }
692
693
694 gmx_bool gmx_fio_ndoe_string(t_fileio* fio, char* item[], int n, const char* desc, const char* srcfile, int line)
695 {
696     gmx_bool ret = TRUE;
697     int      i;
698     gmx_fio_lock(fio);
699     for (i = 0; i < n; i++)
700     {
701         ret = ret && do_xdr(fio, &(item[i]), 1, eioSTRING, desc, srcfile, line);
702     }
703     gmx_fio_unlock(fio);
704     return ret;
705 }
706
707 namespace gmx
708 {
709
710 FileIOXdrSerializer::FileIOXdrSerializer(t_fileio* fio) : fio_(fio)
711 {
712     GMX_RELEASE_ASSERT(fio, "Need valid file io handle");
713 }
714
715 bool FileIOXdrSerializer::reading() const
716 {
717     return fio_->bRead;
718 }
719
720 void FileIOXdrSerializer::doBool(bool* value)
721 {
722     gmx_fio_do_gmx_bool(fio_, *value);
723 }
724
725 void FileIOXdrSerializer::doUChar(unsigned char* value)
726 {
727     gmx_fio_do_uchar(fio_, *value);
728 }
729
730 void FileIOXdrSerializer::doChar(char* value)
731 {
732     gmx_fio_do_char(fio_, *value);
733 }
734
735 void FileIOXdrSerializer::doUShort(unsigned short* value)
736 {
737     gmx_fio_do_ushort(fio_, *value);
738 }
739
740 void FileIOXdrSerializer::doInt(int* value)
741 {
742     gmx_fio_do_int(fio_, *value);
743 }
744
745 void FileIOXdrSerializer::doInt32(int32_t* value)
746 {
747     gmx_fio_do_int32(fio_, *value);
748 }
749
750 void FileIOXdrSerializer::doInt64(int64_t* value)
751 {
752     gmx_fio_do_int64(fio_, *value);
753 }
754
755 void FileIOXdrSerializer::doFloat(float* value)
756 {
757     gmx_fio_do_float(fio_, *value);
758 }
759
760 void FileIOXdrSerializer::doDouble(double* value)
761 {
762     gmx_fio_do_double(fio_, *value);
763 }
764
765 void FileIOXdrSerializer::doReal(real* value)
766 {
767     gmx_fio_do_real(fio_, *value);
768 }
769
770 void FileIOXdrSerializer::doIvec(ivec* value)
771 {
772     gmx_fio_do_ivec(fio_, *value);
773 }
774
775 void FileIOXdrSerializer::doRvec(rvec* value)
776 {
777     gmx_fio_do_rvec(fio_, *value);
778 }
779
780 void FileIOXdrSerializer::doCharArray(char* values, int elements)
781 {
782     gmx_fio_ndo_char(fio_, values, elements);
783 }
784
785 void FileIOXdrSerializer::doUCharArray(unsigned char* values, int elements)
786 {
787     gmx_fio_ndo_uchar(fio_, values, elements);
788 }
789
790 void FileIOXdrSerializer::doRvecArray(rvec* values, int elements)
791 {
792     gmx_fio_ndo_rvec(fio_, values, elements);
793 }
794
795 void FileIOXdrSerializer::doString(std::string* value)
796 {
797     // TODO: Use an arbitrary length buffer (but that is not supported in
798     // gmx_fio, either).
799     char buf[STRLEN];
800     if (!fio_->bRead)
801     {
802         std::strncpy(buf, value->c_str(), STRLEN);
803         buf[STRLEN - 1] = 0;
804     }
805     gmx_fio_do_string(fio_, buf);
806     if (fio_->bRead)
807     {
808         *value = buf;
809     }
810 }
811
812 } // namespace gmx