NeoPZ
TPZCircBufferedStream.h
Go to the documentation of this file.
1 #ifndef TPZCIRCBUFFEREDSTREAM_H
2 #define TPZCIRCBUFFEREDSTREAM_H
3 #include "TPZStream.h"
4 #include <sstream>
5 
6 #ifdef _AUTODIFF
7 #include "fad.h"
8 #include "tfad.h"
9 #endif
10 
15  public:
20 
27  TPZCircBufferedStream(const TPZStream &readBuffer);
28 
33 
42 
51 
60 
64  void Print();
65 
72  void GetDataFromBuffer(char *dest) const{
74  }
75 
76  using TPZStream::Write;
77  virtual void Write(const int *p, int howMany);
78  virtual void Write(const unsigned int *p, int howMany);
79  virtual void Write(const uint64_t *p, int howMany);
80  virtual void Write(const int64_t *p, int howMany);
81  virtual void Write(const float *p, int howMany);
82  virtual void Write(const double *p, int howMany);
83  virtual void Write(const unsigned char *p, int howMany);
84  virtual void Write(const char *p, int howMany);
85  virtual void Write(const std::complex<float> *p, int howMany);
86  virtual void Write(const std::complex<double> *p, int howMany);
87 
88 #ifdef _AUTODIFF
89  virtual void Write(const TFad<1,REAL> *p, int howMany);
90  virtual void Write(const TFad<6,REAL> *p, int howMany);
91  virtual void Write(const TFad<8,REAL> *p, int howMany);
92  virtual void Write(const TFad<9,REAL> *p, int howMany);
93  virtual void Write(const TFad<10,REAL> *p, int howMany);
94  virtual void Write(const TFad<14,REAL> *p, int howMany);
95  virtual void Write(const Fad<float> *p, int howMany);
96  virtual void Write(const Fad<double> *p, int howMany);
97 #endif
98 
99  using TPZStream::Read;
100  virtual void Read(int *p, int howMany);
101  virtual void Read(unsigned int *p, int howMany);
102  virtual void Read(uint64_t *p, int howMany);
103  virtual void Read(int64_t *p, int howMany);
104  virtual void Read(float *p, int howMany);
105  virtual void Read(double *p, int howMany);
106  virtual void Read(long double *p, int howMany);
107  virtual void Read(unsigned char *p, int howMany);
108  virtual void Read(char *p, int howMany);
109  virtual void Read(std::complex<float> *p, int howMany);
110  virtual void Read(std::complex<double> *p, int howMany);
111 
112 #ifdef _AUTODIFF
113  virtual void Read(TFad<1,REAL> *p, int howMany);
114  virtual void Read(TFad<6,REAL> *p, int howMany);
115  virtual void Read(TFad<8,REAL> *p, int howMany);
116  virtual void Read(TFad<9,REAL> *p, int howMany);
117  virtual void Read(TFad<10,REAL> *p, int howMany);
118  virtual void Read(TFad<14,REAL> *p, int howMany);
119  virtual void Read(Fad<float> *p, int howMany);
120  virtual void Read(Fad<double> *p, int howMany);
121 #endif
122 
123  protected:
130  virtual void ReadFromBuffer(char *dest, const size_t &nBytes);
131 
140  virtual void ConstRead(char *dest, const size_t &nBytes) const;
141 
148  virtual void WriteToBuffer(const char *source, const size_t &nBytes);
149 
150  private:
151  char *fBuffer;
152 
153  char *fFirst;
154 
155  char *fLast;
156 
158 
159  size_t fSize;
160 
167  virtual void ConstReadFromBuffer(char *dest, const size_t &nBytes) const;
168 
169  template <class T> void ReadData(T *p, int howMany);
170 
171  template <class T> void WriteData(const T *p, int howMany);
172 
173  static const size_t MIN_SIZE_INCREMENT = size_t(1);
174 };
175 
176 template <typename T>
177 void TPZCircBufferedStream::ReadData(T *p, int howMany) {
178  ReadFromBuffer(reinterpret_cast<char *> (p), howMany * sizeof (T));
179 }
180 
181 template <typename T>
182 void TPZCircBufferedStream::WriteData(const T *p, int howMany) {
183  WriteToBuffer(reinterpret_cast<const char *> (p), howMany * sizeof (T));
184 }
185 
186 template void TPZCircBufferedStream::WriteData(const int *, int howMany);
187 template void TPZCircBufferedStream::WriteData(const unsigned int* p, int howMany);
188 template void TPZCircBufferedStream::WriteData(const uint64_t *p, int howMany);
189 template void TPZCircBufferedStream::WriteData(const int64_t *p, int howMany);
190 template void TPZCircBufferedStream::WriteData(const float *p, int howMany);
191 template void TPZCircBufferedStream::WriteData(const double *p, int howMany);
192 template void TPZCircBufferedStream::WriteData(const char *p, int howMany);
193 template void TPZCircBufferedStream::WriteData(const std::complex<float> *p, int howMany);
194 template void TPZCircBufferedStream::WriteData(const std::complex<double> *p, int howMany);
195 
196 #ifdef _AUTODIFF
197 template void TPZCircBufferedStream::WriteData(const TFad<1,REAL> *p, int howMany);
198 template void TPZCircBufferedStream::WriteData(const TFad<6,REAL> *p, int howMany);
199 template void TPZCircBufferedStream::WriteData(const TFad<8,REAL> *p, int howMany);
200 template void TPZCircBufferedStream::WriteData(const TFad<9,REAL> *p, int howMany);
201 template void TPZCircBufferedStream::WriteData(const TFad<10,REAL> *p, int howMany);
202 template void TPZCircBufferedStream::WriteData(const TFad<14,REAL> *p, int howMany);
203 template void TPZCircBufferedStream::WriteData(const Fad<float> *p, int howMany);
204 template void TPZCircBufferedStream::WriteData(const Fad<double> *p, int howMany);
205 #endif
206 
207 template void TPZCircBufferedStream::ReadData(int *p, int howMany);
208 template void TPZCircBufferedStream::ReadData(unsigned int *p, int howMany);
209 template void TPZCircBufferedStream::ReadData(uint64_t *p, int howMany);
210 template void TPZCircBufferedStream::ReadData(int64_t *p, int howMany);
211 template void TPZCircBufferedStream::ReadData(float *p, int howMany);
212 template void TPZCircBufferedStream::ReadData(double *p, int howMany);
213 template void TPZCircBufferedStream::ReadData(char *p, int howMany);
214 template void TPZCircBufferedStream::ReadData(std::complex<float> *p, int howMany);
215 template void TPZCircBufferedStream::ReadData(std::complex<double> *p, int howMany);
216 
217 #ifdef _AUTODIFF
218 template void TPZCircBufferedStream::ReadData(TFad<1,REAL> *p, int howMany);
219 template void TPZCircBufferedStream::ReadData(TFad<6,REAL> *p, int howMany);
220 template void TPZCircBufferedStream::ReadData(TFad<8,REAL> *p, int howMany);
221 template void TPZCircBufferedStream::ReadData(TFad<9,REAL> *p, int howMany);
222 template void TPZCircBufferedStream::ReadData(TFad<10,REAL> *p, int howMany);
223 template void TPZCircBufferedStream::ReadData(TFad<14,REAL> *p, int howMany);
224 template void TPZCircBufferedStream::ReadData(Fad<float> *p, int howMany);
225 template void TPZCircBufferedStream::ReadData(Fad<double> *p, int howMany);
226 #endif
227 
228 #endif // TPZCIRCBUFFEREDSTREAM_H
TPZCircBufferedStream()
Creates a bidirectional buffer.
void Print()
Prints buffer info and data.
virtual void ConstRead(char *dest, const size_t &nBytes) const
Reads from buffer WITHOUT consuming it. Unless it is still reading from its underlying stream...
Definition: fad.h:54
void GetDataFromBuffer(char *dest) const
Get all buffer data to a char* in a contiguous manner. May be interesting if one needs to this data t...
virtual void ConstReadFromBuffer(char *dest, const size_t &nBytes) const
Reads from buffer WITHOUT consuming it.
~TPZCircBufferedStream()
Destroys the object.
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
virtual void ReadFromBuffer(char *dest, const size_t &nBytes)
Reads from buffer.
Definition: tfad.h:64
Class for creating a bidirectional circular buffer.
void WriteData(const T *p, int howMany)
virtual void Read(int *p, int howMany)
virtual TPZCircBufferedStream & operator<<(TPZCircBufferedStream &other)
It reads all data in a buffer, consuming it.
virtual void WriteToBuffer(const char *source, const size_t &nBytes)
Writes to buffer.
static const size_t MIN_SIZE_INCREMENT
virtual void Write(const int *p, int howMany)
TPZCircBufferedStream & operator=(const TPZCircBufferedStream &other)
Assingment operator. Both buffers will have the same underlying stream, so this must be used with car...
Contains declaration of the abstract TPZStream class. TPZStream defines the interface for saving and ...
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
void ReadData(T *p, int howMany)
virtual void Read(bool &val)
Definition: TPZStream.cpp:91