NeoPZ
TPZStream.cpp
Go to the documentation of this file.
1 #include "TPZStream.h"
3 
4 #ifdef _AUTODIFF
5 #include "fad.h"
6 #endif
7 
8 void TPZStream::Write(const bool val) {
9  int ival = (val == true) ? 1 : 0;
10  Write(&ival);
11 }
12 
13 #if defined WIN32
14 void TPZStream::Write(const long *p, int howMany){ //weird but necessary for working between different OSs
15  int64_t *copy = new int64_t[howMany];
16  for (unsigned int i = 0; i < howMany; ++i) {
17  copy[i] = (int64_t) p[i];
18  }
19  Write(copy, howMany);
20  delete[] copy;
21 }
22 
23 void TPZStream::Write(const long unsigned int *p, int howMany){ //weird but necessary for working between different OSs
24  uint64_t *copy = new uint64_t[howMany];
25  for (unsigned int i = 0; i < howMany; ++i) {
26  copy[i] = (uint64_t) p[i];
27  }
28  Write(copy, howMany);
29  delete[] copy;
30 }
31 #elif defined __APPLE__
32 
33 void TPZStream::Write(const long *p, int howMany){ //weird but necessary for working between different OSs
34  const int64_t *alias = reinterpret_cast<const int64_t *> (p);
35  Write(alias, howMany);
36 }
37 
38 void TPZStream::Write(const long unsigned int *p, int howMany){ //weird but necessary for working between different OSs
39  const uint64_t *alias = reinterpret_cast<const uint64_t *>(p);
40  Write(alias, howMany);
41 }
42 #endif
43 
45 void TPZStream::Write(const long double *p, int howMany) {//weird but necessary for working between different OSs
46  double *copy = new double[howMany];
47  for (unsigned int i = 0; i < howMany; ++i) {
48  copy[i] = (double) p[i];
49  }
50  Write(copy, howMany);
51  delete[] copy;
52 }
53 
55 void TPZStream::Write(const std::complex <long double> *p, int howMany) {//weird but necessary for working between different OSs
56  std::complex<double> *copy = new std::complex<double>[howMany];
57  for (int i = 0; i < howMany; i++) {
58  copy[i] = (std::complex<double>)p[i];
59  }
60  Write(copy, howMany);
61  delete[] copy;
62 }
63 
64 void TPZStream::Write(const std::string *p, int howMany) {
65  int c;
66  for (c = 0; c < howMany; c++) {
67  int sz = p[c].size();
68  Write(&sz, 1);
69  Write(p[c].c_str(), sz);
70  }
71 }
72 
73 void TPZStream::Write(const TPZFlopCounter *p, int howMany) {
74  int i;
75  for (i = 0; i < howMany; i++)
76  Write(&(p[i].fVal), 1);
77 }
78 
79 #ifdef _AUTODIFF
80 
81 void TPZStream::Write(const Fad <long double> *p, int howMany) {//weird but necessary for working between different OSs
82  Fad<double> *copy = new Fad<double>[howMany];
83  for (int i = 0; i < howMany; i++) {
84  copy[i] = (Fad<double>)p[i];
85  }
86  Write(copy, howMany);
87  delete[] copy;
88 }
89 #endif
90 
91 void TPZStream::Read(bool &val) {
92  int ival;
93  Read(&ival);
94  val = (ival == 0) ? false : true;
95 }
96 
97 #if defined WIN32
98 void TPZStream::Read(long *p, int howMany) { //weird but necessary for working between different OSs
99  int64_t *copy = new int64_t[howMany];
100  Read(copy, howMany);
101  for (unsigned int i = 0; i < howMany; ++i) {
102  p[i] = (long) copy[i];
103  }
104  delete[] copy;
105 }
106 
107 void TPZStream::Read(long unsigned int *p, int howMany) { //weird but necessary for working between different OSs
108  uint64_t *copy = new uint64_t[howMany];
109  Read(copy, howMany);
110  for (unsigned int i = 0; i < howMany; ++i) {
111  p[i] = (long unsigned int) copy[i];
112  }
113  delete[] copy;
114 }
115 
116 #elif defined __APPLE__
117 
118 void TPZStream::Read(long *p, int howMany) { //weird but necessary for working between different OSs
119  int64_t *alias = reinterpret_cast<int64_t *>(p);
120  Read(alias, howMany);
121 }
122 
123 void TPZStream::Read(long unsigned int *p, int howMany) { //weird but necessary for working between different OSs
124  uint64_t *alias = reinterpret_cast<uint64_t *>(p);
125  Read(alias, howMany);
126 }
127 #endif
128 
129 void TPZStream::Read(long double *p, int howMany) {//weird but necessary for working between different OSs
130  double *copy = new double[howMany];
131  Read(copy, howMany);
132  for (unsigned int i = 0; i < howMany; ++i) {
133  p[i] = (long double)copy[i];
134  }
135  delete[] copy;
136 }
137 
139 void TPZStream::Read(std::complex<long double> *p, int howMany) {//weird but necessary for working between different OSs
140  std::complex<double> *copy = new std::complex<double>[howMany];
141  Read(copy, howMany);
142  for (unsigned int i = 0; i < howMany; ++i) {
143  p[i] = (std::complex<long double>)copy[i];
144  }
145  delete[] copy;
146 }
147 
148 void TPZStream::Read(std::string *p, int howMany) {
149  char *temp;
150  for (int c = 0; c < howMany; c++) {
151  p[c].clear();
152  int stringSize = -1;
153  Read(&stringSize, 1);
154  temp = new char[stringSize+1];
155  Read(temp, stringSize);
156  temp[stringSize] = 0;
157  p[c] = temp;
158  delete temp;
159  }
160 }
161 
162 void TPZStream::Read(TPZFlopCounter *p, int howMany) {
163  int i;
164  for (i = 0; i < howMany; i++) {
165  Read(&(p[i].fVal), 1);
166  }
167 }
168 
169 #ifdef _AUTODIFF
170 
171 void TPZStream::Read(Fad<long double> *p, int howMany) {//weird but necessary for working between different OSs
172  Fad<double> *copy = new Fad<double>[howMany];
173  Read(copy, howMany);
174  for (unsigned int i = 0; i < howMany; ++i) {
175  p[i] = (Fad<long double>)copy[i];
176  }
177  delete[] copy;
178 }
179 #endif
180 
181 #ifdef _AUTODIFF
182 void TPZStream::Read(Fad<std::complex< float >> *p, int howMany)
183 {
184  std::cout << __PRETTY_FUNCTION__ << " PLEASE IMPLEMENT ME\n";
185  DebugStop();
186 }
187 
188 void TPZStream::Read(Fad<std::complex< double >> *p, int howMany)
189 {
190  std::cout << __PRETTY_FUNCTION__ << " PLEASE IMPLEMENT ME\n";
191  DebugStop();
192 }
193 
194 void TPZStream::Read(Fad<std::complex< long double >> *p, int howMany)
195 {
196  std::cout << __PRETTY_FUNCTION__ << " PLEASE IMPLEMENT ME\n";
197  DebugStop();
198 }
199 
200 void TPZStream::Write(const Fad<std::complex< float > > *p, int howMany)
201 {
202  std::cout << __PRETTY_FUNCTION__ << " PLEASE IMPLEMENT ME\n";
203  DebugStop();
204 }
205 
206 void TPZStream::Write(const Fad<std::complex< double > >*p, int howMany)
207 {
208  std::cout << __PRETTY_FUNCTION__ << " PLEASE IMPLEMENT ME\n";
209  DebugStop();
210 }
211 
212 void TPZStream::Write(const Fad<std::complex< long double >> *p, int howMany)
213 {
214  std::cout << __PRETTY_FUNCTION__ << " PLEASE IMPLEMENT ME\n";
215  DebugStop();
216 }
217 
218 
219 #endif
Definition: fad.h:54
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
This class implements floating point number associated with a counter of the operations performed wit...
Definition: pzreal.h:261
Contains declaration of the abstract TPZStream class. TPZStream defines the interface for saving and ...
virtual void Read(bool &val)
Definition: TPZStream.cpp:91