37 const unsigned int nBytesOther = other.
fSize;
38 char *temp =
new char[nBytesOther];
47 const unsigned int nBytesOther = other.
fSize;
48 char *temp =
new char[nBytesOther];
57 std::string msg(
"TPZCircBufferedStream: Cannot read ");
59 msg.append(
" bytes; there are only ");
61 msg.append(
" available.");
67 if (
fFirst + nBytes < endBuffer) {
70 memcpy(dest,
fFirst, nBytes);
74 const size_t nBytesRead(endBuffer -
fFirst);
75 memcpy(dest,
fFirst, nBytesRead);
76 if (nBytes != nBytesRead) {
77 memcpy(dest + nBytesRead,
fBuffer, nBytes - nBytesRead);
90 const size_t &nBytes)
const {
92 std::string msg(
"TPZCircBufferedStream: Cannot read ");
94 msg.append(
" bytes; there are only ");
96 msg.append(
" available.");
102 if (
fFirst + nBytes < endBuffer) {
105 memcpy(dest,
fFirst, nBytes);
108 const size_t nBytesRead(endBuffer -
fFirst);
109 memcpy(dest,
fFirst, nBytesRead);
110 if (nBytes != nBytesRead) {
111 memcpy(dest + nBytesRead,
fBuffer, nBytes - nBytesRead);
117 const size_t &nBytes) {
119 const size_t oldSize =
fSize;
120 const size_t newAllocatedBytes =
121 oldSize * 1.1 + nBytes +
123 char *temp =
new char[newAllocatedBytes];
125 memcpy(temp + oldSize, source, nBytes);
130 fSize = oldSize + nBytes;
135 if (
fLast + nBytes < endBuffer) {
138 memcpy(
fLast + 1, source, nBytes);
142 const size_t nBytesWritten(endBuffer -
fLast - 1);
143 memcpy(
fLast + 1, source, nBytesWritten);
144 if (nBytes != nBytesWritten) {
145 memcpy(
fBuffer, source + nBytesWritten, nBytes - nBytesWritten);
155 std::cout <<
"fSize=" <<
fSize << std::endl;
156 double *temp =
new double[
fSize / 8];
158 for (
unsigned int i = 0; i <
fSize / 8; ++i) {
159 std::cout << temp[i] <<
" ";
162 std::cout << std::endl;
167 WriteData<int>(p, howMany);
171 WriteData<unsigned int>(p, howMany);
175 WriteData<uint64_t>(p, howMany);
179 WriteData<int64_t>(p, howMany);
183 WriteData<float>(p, howMany);
187 WriteData<double>(p, howMany);
191 WriteData<unsigned char>(p, howMany);
195 WriteData<char>(p, howMany);
199 WriteData<std::complex<float>>(p, howMany);
203 WriteData<std::complex<double>>(p, howMany);
209 WriteData<TFad<1,REAL>>(p, howMany);
213 WriteData<TFad<6,REAL>>(p, howMany);
217 WriteData<TFad<8,REAL>>(p, howMany);
221 WriteData<TFad<9,REAL>>(p, howMany);
225 WriteData<TFad<10,REAL>>(p, howMany);
229 WriteData<TFad<14,REAL>>(p, howMany);
233 WriteData<Fad<float>>(p, howMany);
237 WriteData<Fad<double>>(p, howMany);
243 ReadData<int>(p, howMany);
247 ReadData<unsigned int>(p, howMany);
251 ReadData<uint64_t>(p, howMany);
255 ReadData<int64_t>(p, howMany);
259 ReadData<float>(p, howMany);
263 ReadData<double>(p, howMany);
267 ReadData<unsigned char>(p, howMany);
271 ReadData<char>(p, howMany);
275 ReadData<std::complex<float>>(p, howMany);
279 ReadData<std::complex<double>>(p, howMany);
285 ReadData<TFad<1,REAL>>(p, howMany);
289 ReadData<TFad<6,REAL>>(p, howMany);
293 ReadData<TFad<8,REAL>>(p, howMany);
297 ReadData<TFad<9,REAL>>(p, howMany);
301 ReadData<TFad<10,REAL>>(p, howMany);
305 ReadData<TFad<14,REAL>>(p, howMany);
309 ReadData<Fad<float>>(p, howMany);
313 ReadData<Fad<double>>(p, howMany);
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...
virtual void ConstReadFromBuffer(char *dest, const size_t &nBytes) const
Reads from buffer WITHOUT consuming it.
~TPZCircBufferedStream()
Destroys the object.
virtual void ReadFromBuffer(char *dest, const size_t &nBytes)
Reads from buffer.
#define DebugStop()
Returns a message to user put a breakpoint in.
Class for creating a bidirectional circular buffer.
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
string to_string(const string &value)
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...
Defines the interface for saving and reading data. Persistency.
#define PZError
Defines the output device to error messages and the DebugStop() function.