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 
13 #ifndef FFA_CHECK_SUM_H
14 #define FFA_CHECK_SUM_H
15 
16 #include <vector>
17 #include <string>
18 #include <iostream>
19 
20 class FaVec3;
21 
22 
30 {
31 public:
33  FFaCheckSum();
35  FFaCheckSum(const FFaCheckSum&) = delete;
37  ~FFaCheckSum() { delete[] crc32_table; }
38 
40  FFaCheckSum& operator=(const FFaCheckSum& cs);
42  bool operator==(const FFaCheckSum& cs) const;
43 
45  void reset() { checksum = addval = 0; }
47  unsigned int getCurrent() const { return checksum; }
48 
50  void add(const std::string& e) { for (char c : e) checksum += doCRC(c); }
52  void add(char e) { checksum += doCRC(e); }
54  void add(unsigned char e) { checksum += doCRC(e); }
56  void add(short int e) { checksum += doCRC(e); }
58  void add(unsigned short int e) { checksum += doCRC(e); }
60  void add(int e) { checksum += doCRC(e); }
62  void add(unsigned int e) { checksum += doCRC(e); }
64  void add(float e);
66  void add(double e, int precision = 0);
68  void add(const FaVec3& e, int precision = 0);
69 
71  template<class T> void add(const std::vector<T>& v)
72  {
73  for (const T& e : v) this->add(e);
74  }
75 
76 private:
78  unsigned int doCRC(unsigned int data);
79 
81  friend std::ostream& operator<<(std::ostream& s, const FFaCheckSum& cs);
83  friend std::istream& operator>>(std::istream& s, FFaCheckSum& cs);
84 
85  unsigned int* crc32_table;
86  unsigned int checksum;
87  unsigned int addval;
88  bool isBigEndian;
89 };
90 
91 #if FFA_DEBUG > 2
92 template<> void FFaCheckSum::add(const std::vector<double>& v);
93 #endif
94 #endif
Class for holding and calculation of checksum value of objects.
Definition: FFaCheckSum.H:30
unsigned int addval
Incremented and added to data on each doCRC() call.
Definition: FFaCheckSum.H:87
bool isBigEndian
Determines the Endianness of the computer.
Definition: FFaCheckSum.H:88
~FFaCheckSum()
The destructor deletes the heap-allocated member crc32_table.
Definition: FFaCheckSum.H:37
void add(unsigned short int e)
Adds the checksum of an unsigned short int value to checksum.
Definition: FFaCheckSum.H:58
friend std::ostream & operator<<(std::ostream &s, const FFaCheckSum &cs)
Printing operator.
Definition: FFaCheckSum.C:225
unsigned int doCRC(unsigned int data)
Calculates the checksum value of a variable casted to unsigned int.
Definition: FFaCheckSum.C:69
unsigned int * crc32_table
32-bit Cyclic Redundancy Check hashing values
Definition: FFaCheckSum.H:85
void reset()
Initializes checksum and addval.
Definition: FFaCheckSum.H:45
void add(char e)
Adds the checksum of a char value to checksum.
Definition: FFaCheckSum.H:52
friend std::istream & operator>>(std::istream &s, FFaCheckSum &cs)
Reading operator.
Definition: FFaCheckSum.C:231
FFaCheckSum & operator=(const FFaCheckSum &cs)
Assignment operator.
Definition: FFaCheckSum.C:48
bool operator==(const FFaCheckSum &cs) const
Equality operator,.
Definition: FFaCheckSum.C:60
void add(unsigned int e)
Adds the checksum of an unsigned int value to checksum.
Definition: FFaCheckSum.H:62
FFaCheckSum()
The default constructor initializes crc32_table.
Definition: FFaCheckSum.C:19
unsigned int checksum
Current checksum value.
Definition: FFaCheckSum.H:86
FFaCheckSum(const FFaCheckSum &)=delete
The default copy constructor is deleted.
void add(int e)
Adds the checksum of an int value to checksum.
Definition: FFaCheckSum.H:60
void add(unsigned char e)
Adds the checksum of an unsigned char value to checksum.
Definition: FFaCheckSum.H:54
unsigned int getCurrent() const
Returns the current checksum value.
Definition: FFaCheckSum.H:47
void add(const std::vector< T > &v)
Adds the checksum of a std::vector value to checksum.
Definition: FFaCheckSum.H:71
void add(short int e)
Adds the checksum of a short int value to checksum.
Definition: FFaCheckSum.H:56
void add(const std::string &e)
Adds the checksum of a std::string value to checksum.
Definition: FFaCheckSum.H:50
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
real(dp), dimension(:,:), allocatable c
Definition: inverseModule.f90:39