NeoPZ
TPZContBufferedStream.h
Go to the documentation of this file.
1 #ifndef TPZCONTBUFFEREDSTREAM_H
2 #define TPZCONTBUFFEREDSTREAM_H
3 #include "TPZStream.h"
4 #include <sstream>
5 
6 #ifdef _AUTODIFF
7 #include "Fad/fad.h"
8 #include "tfad.h"
9 #endif
10 
15  public:
21 
28 
33 
41 
50 
59 
63  void Print();
64 
71  void GetDataFromBuffer(char *dest) const;
72 
73  void clear();
74 
75  using TPZStream::Write;
76  virtual void Write(const int *p, int howMany=1);
77  virtual void Write(const unsigned int *p, int howMany=1);
78  virtual void Write(const uint64_t *p, int howMany=1);
79  virtual void Write(const int64_t *p, int howMany=1);
80  virtual void Write(const float *p, int howMany=1);
81  virtual void Write(const double *p, int howMany=1);
82  virtual void Write(const unsigned char *p, int howMany=1);
83  virtual void Write(const char *p, int howMany=1);
84  virtual void Write(const std::complex<float> *p, int howMany=1);
85  virtual void Write(const std::complex<double> *p, int howMany=1);
86 
87 #ifdef _AUTODIFF
88  virtual void Write(const TFad<1,REAL> *p, int howMany=1);
89  virtual void Write(const TFad<6,REAL> *p, int howMany=1);
90  virtual void Write(const TFad<8,REAL> *p, int howMany=1);
91  virtual void Write(const TFad<9,REAL> *p, int howMany=1);
92  virtual void Write(const TFad<10,REAL> *p, int howMany=1);
93  virtual void Write(const TFad<14,REAL> *p, int howMany=1);
94  virtual void Write(const Fad<float> *p, int howMany=1);
95  virtual void Write(const Fad<double> *p, int howMany=1);
96 #endif
97 
98  using TPZStream::Read;
99  virtual void Read(int *p, int howMany=1);
100  virtual void Read(unsigned int *p, int howMany=1);
101  virtual void Read(uint64_t *p, int howMany=1);
102  virtual void Read(int64_t *p, int howMany=1);
103  virtual void Read(float *p, int howMany=1);
104  virtual void Read(double *p, int howMany=1);
105  virtual void Read(unsigned char *p, int howMany=1);
106  virtual void Read(char *p, int howMany=1);
107  virtual void Read(std::complex<float> *p, int howMany=1);
108  virtual void Read(std::complex<double> *p, int howMany=1);
109 
110 #ifdef _AUTODIFF
111  virtual void Read(TFad<1,REAL> *p, int howMany=1);
112  virtual void Read(TFad<6,REAL> *p, int howMany=1);
113  virtual void Read(TFad<8,REAL> *p, int howMany=1);
114  virtual void Read(TFad<9,REAL> *p, int howMany=1);
115  virtual void Read(TFad<10,REAL> *p, int howMany=1);
116  virtual void Read(TFad<14,REAL> *p, int howMany=1);
117  virtual void Read(Fad<float> *p, int howMany=1);
118  virtual void Read(Fad<double> *p, int howMany=1);
119 #endif
120 
121  size_t Size() const;
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 TPZContBufferedStream::ReadData(T *p, int howMany) {
178  ReadFromBuffer(reinterpret_cast<char *> (p), howMany * sizeof (T));
179 }
180 
181 template <typename T>
182 void TPZContBufferedStream::WriteData(const T *p, int howMany) {
183  WriteToBuffer(reinterpret_cast<const char *> (p), howMany * sizeof (T));
184 }
185 
186 template void TPZContBufferedStream::WriteData(const int *, int howMany);
187 template void TPZContBufferedStream::WriteData(const unsigned int* p, int howMany);
188 template void TPZContBufferedStream::WriteData(const uint64_t *p, int howMany);
189 template void TPZContBufferedStream::WriteData(const int64_t *p, int howMany);
190 template void TPZContBufferedStream::WriteData(const float *p, int howMany);
191 template void TPZContBufferedStream::WriteData(const double *p, int howMany);
192 template void TPZContBufferedStream::WriteData(const char *p, int howMany);
193 template void TPZContBufferedStream::WriteData(const std::complex<float> *p, int howMany);
194 template void TPZContBufferedStream::WriteData(const std::complex<double> *p, int howMany);
195 
196 #ifdef _AUTODIFF
197 template void TPZContBufferedStream::WriteData(const TFad<1,REAL> *p, int howMany);
198 template void TPZContBufferedStream::WriteData(const TFad<6,REAL> *p, int howMany);
199 template void TPZContBufferedStream::WriteData(const TFad<8,REAL> *p, int howMany);
200 template void TPZContBufferedStream::WriteData(const TFad<9,REAL> *p, int howMany);
201 template void TPZContBufferedStream::WriteData(const TFad<10,REAL> *p, int howMany);
202 template void TPZContBufferedStream::WriteData(const TFad<14,REAL> *p, int howMany);
203 template void TPZContBufferedStream::WriteData(const Fad<float> *p, int howMany);
204 template void TPZContBufferedStream::WriteData(const Fad<double> *p, int howMany);
205 #endif
206 
207 template void TPZContBufferedStream::ReadData(int *p, int howMany);
208 template void TPZContBufferedStream::ReadData(unsigned int *p, int howMany);
209 template void TPZContBufferedStream::ReadData(uint64_t *p, int howMany);
210 template void TPZContBufferedStream::ReadData(int64_t *p, int howMany);
211 template void TPZContBufferedStream::ReadData(float *p, int howMany);
212 template void TPZContBufferedStream::ReadData(double *p, int howMany);
213 template void TPZContBufferedStream::ReadData(char *p, int howMany);
214 template void TPZContBufferedStream::ReadData(std::complex<float> *p, int howMany);
215 template void TPZContBufferedStream::ReadData(std::complex<double> *p, int howMany);
216 
217 #ifdef _AUTODIFF
218 template void TPZContBufferedStream::ReadData(TFad<1,REAL> *p, int howMany);
219 template void TPZContBufferedStream::ReadData(TFad<6,REAL> *p, int howMany);
220 template void TPZContBufferedStream::ReadData(TFad<8,REAL> *p, int howMany);
221 template void TPZContBufferedStream::ReadData(TFad<9,REAL> *p, int howMany);
222 template void TPZContBufferedStream::ReadData(TFad<10,REAL> *p, int howMany);
223 template void TPZContBufferedStream::ReadData(TFad<14,REAL> *p, int howMany);
224 template void TPZContBufferedStream::ReadData(Fad<float> *p, int howMany);
225 template void TPZContBufferedStream::ReadData(Fad<double> *p, int howMany);
226 #endif
227 
228 #endif // TPZCONTBUFFEREDSTREAM_H
TPZContBufferedStream & operator=(const TPZContBufferedStream &other)
Assingment operator.
Class for creating a bidirectional circular buffer.
virtual void Read(int *p, int howMany=1)
virtual void Write(const int *p, int howMany=1)
void WriteData(const T *p, int howMany)
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 ReadData(T *p, int howMany)
virtual void ReadFromBuffer(char *dest, const size_t &nBytes)
Reads from buffer.
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
Definition: tfad.h:64
~TPZContBufferedStream()
Destroys the object.
virtual void ConstReadFromBuffer(char *dest, const size_t &nBytes) const
Reads from buffer WITHOUT consuming it.
void Print()
Prints buffer info and data.
virtual void WriteToBuffer(const char *source, const size_t &nBytes)
Writes to buffer.
TPZContBufferedStream()
Creates a buffer.
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
static const size_t MIN_SIZE_INCREMENT
virtual TPZContBufferedStream & operator<<(TPZContBufferedStream &other)
It reads all data in a buffer, consuming it.
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 Read(bool &val)
Definition: TPZStream.cpp:91