FEDEM Solver  R8.0
Source code of the dynamics solver
FiSwappedIO.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
8 #ifndef FI_SWAPPED_IO_H
9 #define FI_SWAPPED_IO_H
10 
11 #include "FFaLib/FFaOS/FFaIO.H"
12 
13 
14 namespace Fi
15 {
16  template<class T> size_t readSwapped(char* q, T&, FT_FILE fd)
17  {
18  static char p[8];
19  int nChar = sizeof(T);
20  size_t nBytes = FT_read(p,nChar,1,fd);
21  for (int i = nChar-1; i > 0; i--, q++)
22  *q = p[i];
23  *q = p[0];
24 
25  return nBytes;
26  }
27 
28  template<class T> size_t writeSwapped(const T val, FT_FILE fd)
29  {
30  T swappedValue;
31  int nChar = sizeof(T);
32  char* p = (char*)&val;
33  char* q = (char*)(&swappedValue);
34  for (int i = nChar-1; i > 0; i--, q++)
35  *q = p[i];
36  *q = p[0];
37 
38  return FT_write(&swappedValue,nChar,1,fd);
39  }
40 }
41 
42 #endif
Functions and data type for direct access of large binary files.
#define FT_FILE
File pointer.
Definition: FFaIO.H:136
#define FT_read(buf, n, m, f)
Reads an array from file.
Definition: FFaIO.H:118
#define FT_write(buf, n, m, f)
Writes an array to file.
Definition: FFaIO.H:120
Definition: FiSwappedIO.H:15
size_t writeSwapped(const T val, FT_FILE fd)
Definition: FiSwappedIO.H:28
size_t readSwapped(char *q, T &, FT_FILE fd)
Definition: FiSwappedIO.H:16