FEDEM Solver  R8.0
Source code of the dynamics solver
FFaCheckSum.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 FFA_CHECK_SUM_H
9 #define FFA_CHECK_SUM_H
10 
11 #include <vector>
12 #include <string>
13 #include <iostream>
14 
15 class FaVec3;
16 
17 
19 {
20 public:
21  FFaCheckSum();
22  FFaCheckSum(const FFaCheckSum&) = delete;
23  ~FFaCheckSum() { delete[] crc32_table; }
24 
25  FFaCheckSum& operator=(const FFaCheckSum& cs);
26  bool operator==(const FFaCheckSum& cs) const;
27 
28  void reset() { checksum = addval = 0; }
29  unsigned int getCurrent() const { return checksum; }
30 
31  void add(const std::string& e) { for (char c : e) checksum += doCRC(c); }
32  void add(char e) { checksum += doCRC(e); }
33  void add(unsigned char e) { checksum += doCRC(e); }
34  void add(short int e) { checksum += doCRC(e); }
35  void add(unsigned short int e) { checksum += doCRC(e); }
36  void add(int e) { checksum += doCRC(e); }
37  void add(unsigned int e) { checksum += doCRC(e); }
38  void add(float e);
39  void add(double e, int precision = 0);
40  void add(const FaVec3& e, int precision = 0);
41 
42  template<class T> void add(const std::vector<T>& v)
43  {
44  for (const T& e : v) this->add(e);
45  }
46 
47 private:
48  unsigned int doCRC(unsigned int data);
49 
50  friend std::ostream& operator<<(std::ostream& s, const FFaCheckSum& cs);
51  friend std::istream& operator>>(std::istream& s, FFaCheckSum& cs);
52 
53  unsigned int* crc32_table;
54  unsigned int checksum, addval;
56 };
57 
58 #if FFA_DEBUG > 2
59 template<> void FFaCheckSum::add(const std::vector<double>& v);
60 #endif
61 #endif
Definition: FFaCheckSum.H:19
unsigned int addval
Definition: FFaCheckSum.H:54
bool isBigEndian
Definition: FFaCheckSum.H:55
~FFaCheckSum()
Definition: FFaCheckSum.H:23
void add(unsigned short int e)
Definition: FFaCheckSum.H:35
friend std::ostream & operator<<(std::ostream &s, const FFaCheckSum &cs)
Definition: FFaCheckSum.C:201
unsigned int doCRC(unsigned int data)
Definition: FFaCheckSum.C:64
unsigned int * crc32_table
Definition: FFaCheckSum.H:53
void reset()
Definition: FFaCheckSum.H:28
void add(char e)
Definition: FFaCheckSum.H:32
friend std::istream & operator>>(std::istream &s, FFaCheckSum &cs)
Definition: FFaCheckSum.C:207
FFaCheckSum & operator=(const FFaCheckSum &cs)
Definition: FFaCheckSum.C:43
bool operator==(const FFaCheckSum &cs) const
Definition: FFaCheckSum.C:55
void add(unsigned int e)
Definition: FFaCheckSum.H:37
FFaCheckSum()
Definition: FFaCheckSum.C:14
unsigned int checksum
Definition: FFaCheckSum.H:54
FFaCheckSum(const FFaCheckSum &)=delete
void add(int e)
Definition: FFaCheckSum.H:36
void add(unsigned char e)
Definition: FFaCheckSum.H:33
unsigned int getCurrent() const
Definition: FFaCheckSum.H:29
void add(const std::vector< T > &v)
Definition: FFaCheckSum.H:42
void add(short int e)
Definition: FFaCheckSum.H:34
void add(const std::string &e)
Definition: FFaCheckSum.H:31
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
real(dp), dimension(:,:), allocatable c
Definition: inverseModule.f90:39