NeoPZ
TPZFileStream.h
Go to the documentation of this file.
1 #ifndef TPZFILESTREAM_H
2 #define TPZFILESTREAM_H
3 
4 #include <complex> // for complex, operator<<, operator>>
5 #include <sstream> // for basic_stringbuf<>::int_type, basic_st...
6 #include "TPZGeneralFStream.h" // for TPZGeneralFStream
7 #ifdef _AUTODIFF
8 template <class T> class Fad;
9 template <int Num, class T> class TFad;
10 #endif//_AUTODIFF
11 
16  private:
17  std::ifstream fIn;
18  std::ofstream fOut;
19 
20  template<class T>
21  void ReadData(T *p, int howMany);
22 
23  template<class T>
24  void WriteData(const T *p, int howMany);
25 
26  public:
27  TPZFileStream();
28  virtual ~TPZFileStream();
29 
30  void OpenRead(const std::string &fileName);
31  void OpenWrite(const std::string &fileName);
32 
33  virtual bool AmIOpenForRead();
34  virtual bool AmIOpenForWrite();
35 
36  void CloseRead();
37  void CloseWrite();
38 
39  bool eof() {
40  return fIn.eof();
41  }
42 
43  using TPZStream::Write;
44 
45  virtual void Write(const int *p, int howMany) {
46  WriteData<int>(p,howMany);
47  }
48 
49  virtual void Write(const unsigned int *p, int howMany) {
50  WriteData<unsigned int>(p,howMany);
51  }
52 
53  virtual void Write(const uint64_t *p, int howMany) {
54  WriteData<uint64_t>(p,howMany);
55  }
56 
57  virtual void Write(const int64_t *p, int howMany) {
58  WriteData<int64_t>(p,howMany);
59  }
60 
61  virtual void Write(const float *p, int howMany) {
62  WriteData<float>(p,howMany);
63  }
64 
65  virtual void Write(const double *p, int howMany) {
66  WriteData<double>(p,howMany);
67  }
68 
69  virtual void Write(const unsigned char *p, int howMany) {
70  WriteData<unsigned char>(p,howMany);
71  }
72 
73  virtual void Write(const char *p, int howMany) {
74  WriteData<char>(p,howMany);
75  }
76 
77  virtual void Write(const std::complex <float> *p, int howMany) {
78  WriteData< std::complex <float> >(p,howMany);
79  }
80 
81  virtual void Write(const std::complex <double> *p, int howMany) {
82  WriteData< std::complex <double> >(p,howMany);
83  }
84 
85 #ifdef _AUTODIFF
86 
87  virtual void Write(const TFad <1,REAL> *p, int howMany) {
88  WriteData< TFad <1,REAL> >(p,howMany);
89  }
90 
91  virtual void Write(const TFad <6,REAL> *p, int howMany) {
92  WriteData< TFad <6,REAL> >(p,howMany);
93  }
94 
95  virtual void Write(const TFad <8,REAL> *p, int howMany) {
96  WriteData< TFad <8,REAL> >(p,howMany);
97  }
98 
99  virtual void Write(const TFad <9,REAL> *p, int howMany) {
100  WriteData< TFad <9,REAL> >(p,howMany);
101  }
102 
103  virtual void Write(const TFad <10,REAL> *p, int howMany) {
104  WriteData< TFad <10,REAL> >(p,howMany);
105  }
106 
107  virtual void Write(const TFad <14,REAL> *p, int howMany) {
108  WriteData< TFad <14,REAL> >(p,howMany);
109  }
110 
111  virtual void Write(const Fad <float> *p, int howMany) {
112  WriteData< Fad <float> >(p,howMany);
113  }
114 
115  virtual void Write(const Fad <double> *p, int howMany) {
116  WriteData< Fad <double> >(p,howMany);
117  }
118 
119 #endif
120 
121  using TPZStream::Read;
122 
123  virtual void Read(int *p, int howMany) {
124  ReadData<int>(p,howMany);
125  }
126 
127  virtual void Read(unsigned int *p, int howMany) {
128  ReadData<unsigned int>(p,howMany);
129  }
130 
131  virtual void Read(uint64_t *p, int howMany) {
132  ReadData<uint64_t>(p,howMany);
133  }
134 
135  virtual void Read(int64_t *p, int howMany) {
136  ReadData<int64_t>(p,howMany);
137  }
138 
139  virtual void Read(float *p, int howMany) {
140  ReadData<float>(p,howMany);
141  }
142 
143  virtual void Read(double *p, int howMany) {
144  ReadData<double>(p,howMany);
145  }
146 
147  virtual void Read(unsigned char *p, int howMany) {
148  ReadData<unsigned char>(p,howMany);
149  }
150 
151  virtual void Read(char *p, int howMany) {
152  ReadData<char>(p,howMany);
153  }
154 
155  virtual void Read(std::complex <float> *p, int howMany) {
156  ReadData< std::complex <float> >(p,howMany);
157  }
158 
159  virtual void Read(std::complex <double> *p, int howMany) {
160  ReadData< std::complex <double> >(p,howMany);
161  }
162 
163 #ifdef _AUTODIFF
164 
165  virtual void Read(TFad <1,REAL> *p, int howMany) {
166  ReadData< TFad <1,REAL> >(p,howMany);
167  }
168 
169  virtual void Read(TFad <6,REAL> *p, int howMany) {
170  ReadData< TFad <6,REAL> >(p,howMany);
171  }
172 
173  virtual void Read(TFad <8,REAL> *p, int howMany) {
174  ReadData< TFad <8,REAL> >(p,howMany);
175  }
176 
177  virtual void Read(TFad <9,REAL> *p, int howMany) {
178  ReadData< TFad <9,REAL> >(p,howMany);
179  }
180 
181  virtual void Read(TFad <10,REAL> *p, int howMany) {
182  ReadData< TFad <10,REAL> >(p,howMany);
183  }
184 
185  virtual void Read(TFad <14,REAL> *p, int howMany) {
186  ReadData< TFad <14,REAL> >(p,howMany);
187  }
188 
189  virtual void Read(Fad <float> *p, int howMany) {
190  ReadData< Fad <float> >(p,howMany);
191  }
192 
193  virtual void Read(Fad <double> *p, int howMany) {
194  ReadData< Fad <double> >(p,howMany);
195  }
196 
197 
198 #endif
199 };
200 #endif// TPZFILESTREAM_H
virtual void Write(const int *p, int howMany)
Definition: TPZFileStream.h:45
virtual void Write(const double *p, int howMany)
Definition: TPZFileStream.h:65
void ReadData(T *p, int howMany)
virtual void Write(const std::complex< double > *p, int howMany)
Definition: TPZFileStream.h:81
virtual void Read(unsigned int *p, int howMany)
virtual void Read(std::complex< double > *p, int howMany)
virtual ~TPZFileStream()
void OpenWrite(const std::string &fileName)
Definition: fad.h:54
virtual void Write(const char *p, int howMany)
Definition: TPZFileStream.h:73
virtual void Write(const float *p, int howMany)
Definition: TPZFileStream.h:61
virtual void Read(char *p, int howMany)
void OpenRead(const std::string &fileName)
virtual void Read(uint64_t *p, int howMany)
Implements reading from and writing to an ascii file. Persistency.
Definition: TPZFileStream.h:15
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
std::ifstream fIn
Definition: TPZFileStream.h:17
Definition: tfad.h:64
std::ofstream fOut
Definition: TPZFileStream.h:18
virtual void Read(int *p, int howMany)
void WriteData(const T *p, int howMany)
virtual void Read(float *p, int howMany)
virtual bool AmIOpenForWrite()
virtual void Read(unsigned char *p, int howMany)
virtual void Write(const unsigned char *p, int howMany)
Definition: TPZFileStream.h:69
virtual void Read(int64_t *p, int howMany)
virtual void Write(const uint64_t *p, int howMany)
Definition: TPZFileStream.h:53
virtual void Write(const int64_t *p, int howMany)
Definition: TPZFileStream.h:57
virtual void Write(const unsigned int *p, int howMany)
Definition: TPZFileStream.h:49
virtual void Write(const std::complex< float > *p, int howMany)
Definition: TPZFileStream.h:77
virtual void Read(std::complex< float > *p, int howMany)
virtual bool AmIOpenForRead()
virtual void Read(double *p, int howMany)
virtual void Read(bool &val)
Definition: TPZStream.cpp:91