Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
JIO::JBufferedWriter Class Reference

Buffered binary output. More...

#include <JBufferedIO.hh>

Inheritance diagram for JIO::JBufferedWriter:
JIO::JWriter JLANG::JBinaryOutput JLANG::JAbstractObjectStatus JIO::JFileStreamWriter

Public Member Functions

 JBufferedWriter (JWriter *__out, const int __size=1048576)
 Constructor. More...
 
 ~JBufferedWriter ()
 Destructor. More...
 
virtual bool getStatus () const override
 Status of writer. More...
 
virtual int write (const char *zbuf, int n) override
 Write byte array. More...
 
void flush ()
 Write internal data to output. More...
 
JWriteroperator<< (const JSerialisable &object)
 Write serialisable data object. More...
 
JWriteroperator<< (const bool value)
 
JWriteroperator<< (const char value)
 
JWriteroperator<< (const unsigned char value)
 
JWriteroperator<< (const short value)
 
JWriteroperator<< (const unsigned short value)
 
JWriteroperator<< (const int value)
 
JWriteroperator<< (const unsigned int value)
 
JWriteroperator<< (const long int value)
 
JWriteroperator<< (const unsigned long int value)
 
JWriteroperator<< (const long long int value)
 
JWriteroperator<< (const unsigned long long int value)
 
JWriteroperator<< (const float value)
 
JWriteroperator<< (const double value)
 
JWriteroperator<< (const long double value)
 
JWriteroperator<< (const JLANG::JObjectID &value)
 
JWriterstore (const JSerialisable &object)
 Write object. More...
 
template<class T >
JWriterstore (const T &object)
 Write object. More...
 
 operator bool () const
 Type conversion operator. More...
 
bool operator! () const
 Negated status of this object. More...
 

Protected Attributes

JLANG::JSinglePointer< JWriterout
 
char * buffer
 internal buffer More...
 
int size
 size of internal buffer More...
 
int pos
 pointer to end of buffered data More...
 

Detailed Description

Buffered binary output.

This class implements the JWriter interface.

Definition at line 145 of file JBufferedIO.hh.

Constructor & Destructor Documentation

JIO::JBufferedWriter::JBufferedWriter ( JWriter __out,
const int  __size = 1048576 
)
inline

Constructor.

Note that this object owns the writer pointed to.

Parameters
__outpointer to writer
__sizesize of internal buffer

Definition at line 156 of file JBufferedIO.hh.

156  :
157  out(__out)
158  {
159  size = std::max(__size, 1024);
160  buffer = new char[size];
161 
162  pos = 0;
163  }
int pos
pointer to end of buffered data
Definition: JBufferedIO.hh:234
JLANG::JSinglePointer< JWriter > out
Definition: JBufferedIO.hh:230
int size
size of internal buffer
Definition: JBufferedIO.hh:233
char * buffer
internal buffer
Definition: JBufferedIO.hh:232
JIO::JBufferedWriter::~JBufferedWriter ( )
inline

Destructor.

Definition at line 169 of file JBufferedIO.hh.

170  {
171  flush();
172 
173  delete [] buffer;
174  }
char * buffer
internal buffer
Definition: JBufferedIO.hh:232
void flush()
Write internal data to output.
Definition: JBufferedIO.hh:223

Member Function Documentation

virtual bool JIO::JBufferedWriter::getStatus ( ) const
inlineoverridevirtual

Status of writer.

Returns
status of this writer

Implements JLANG::JAbstractObjectStatus.

Definition at line 182 of file JBufferedIO.hh.

183  {
184  return (bool) *out;
185  }
JLANG::JSinglePointer< JWriter > out
Definition: JBufferedIO.hh:230
virtual int JIO::JBufferedWriter::write ( const char *  zbuf,
int  n 
)
inlineoverridevirtual

Write byte array.

Parameters
zbufpointer to byte array
nnumber of bytes
Returns
number of bytes

Implements JLANG::JBinaryOutput.

Definition at line 195 of file JBufferedIO.hh.

196  {
197  for (int i = 0; i != n; ) {
198 
199  int m = n - i;
200 
201  if (m > size - pos) {
202 
203  flush();
204 
205  if (m > size - pos) {
206  m = size - pos;
207  }
208  }
209 
210  memcpy(buffer + pos, zbuf + i, m);
211 
212  i += m;
213  pos += m;
214  }
215 
216  return n;
217  }
int pos
pointer to end of buffered data
Definition: JBufferedIO.hh:234
const int n
Definition: JPolint.hh:660
int size
size of internal buffer
Definition: JBufferedIO.hh:233
char * buffer
internal buffer
Definition: JBufferedIO.hh:232
void flush()
Write internal data to output.
Definition: JBufferedIO.hh:223
void JIO::JBufferedWriter::flush ( )
inline

Write internal data to output.

Definition at line 223 of file JBufferedIO.hh.

224  {
225  pos -= out->write(buffer, pos);
226  }
int pos
pointer to end of buffered data
Definition: JBufferedIO.hh:234
JLANG::JSinglePointer< JWriter > out
Definition: JBufferedIO.hh:230
char * buffer
internal buffer
Definition: JBufferedIO.hh:232
JWriter& JIO::JWriter::operator<< ( const JSerialisable object)
inlineinherited

Write serialisable data object.

Parameters
objectserialisable data object
Returns
JWriter

Definition at line 144 of file JSerialisable.hh.

145  {
146  return object.write(*this);
147  }
JWriter& JIO::JWriter::operator<< ( const bool  value)
inlineinherited

Definition at line 150 of file JSerialisable.hh.

150 { write((const char*) &value, sizeof(bool)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const char  value)
inlineinherited

Definition at line 151 of file JSerialisable.hh.

151 { write((const char*) &value, sizeof(char)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned char  value)
inlineinherited

Definition at line 152 of file JSerialisable.hh.

152 { write((const char*) &value, sizeof(unsigned char)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const short  value)
inlineinherited

Definition at line 153 of file JSerialisable.hh.

153 { write((const char*) &value, sizeof(short)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned short  value)
inlineinherited

Definition at line 154 of file JSerialisable.hh.

154 { write((const char*) &value, sizeof(unsigned short)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const int  value)
inlineinherited

Definition at line 155 of file JSerialisable.hh.

155 { write((const char*) &value, sizeof(int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned int  value)
inlineinherited

Definition at line 156 of file JSerialisable.hh.

156 { write((const char*) &value, sizeof(unsigned int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const long int  value)
inlineinherited

Definition at line 157 of file JSerialisable.hh.

157 { write((const char*) &value, sizeof(long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned long int  value)
inlineinherited

Definition at line 158 of file JSerialisable.hh.

158 { write((const char*) &value, sizeof(unsigned long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const long long int  value)
inlineinherited

Definition at line 159 of file JSerialisable.hh.

159 { write((const char*) &value, sizeof(long long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned long long int  value)
inlineinherited

Definition at line 160 of file JSerialisable.hh.

160 { write((const char*) &value, sizeof(unsigned long long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const float  value)
inlineinherited

Definition at line 161 of file JSerialisable.hh.

161 { write((const char*) &value, sizeof(float)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const double  value)
inlineinherited

Definition at line 162 of file JSerialisable.hh.

162 { write((const char*) &value, sizeof(double)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const long double  value)
inlineinherited

Definition at line 163 of file JSerialisable.hh.

163 { write((const char*) &value, sizeof(long double)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const JLANG::JObjectID value)
inlineinherited

Definition at line 164 of file JSerialisable.hh.

164 { return (*this) << value.getID(); }
int getID() const
Get identifier.
Definition: JObjectID.hh:50
JWriter& JIO::JWriter::store ( const JSerialisable object)
inlineinherited

Write object.

Parameters
objectobject
Returns
this writer

Definition at line 173 of file JSerialisable.hh.

174  {
175  return object.write(*this);
176  }
template<class T >
JWriter& JIO::JWriter::store ( const T object)
inlineinherited

Write object.

Parameters
objectobject
Returns
this writer

Definition at line 186 of file JSerialisable.hh.

187  {
188  return *this << object;
189  }
JLANG::JAbstractObjectStatus::operator bool ( ) const
inlineinherited

Type conversion operator.

Returns
status of this object

Definition at line 33 of file JAbstractObjectStatus.hh.

34  {
35  return this->getStatus();
36  }
virtual bool getStatus() const =0
Get status of object.
bool JLANG::JAbstractObjectStatus::operator! ( ) const
inlineinherited

Negated status of this object.

Returns
negated status of this object

Definition at line 44 of file JAbstractObjectStatus.hh.

45  {
46  return !(this->getStatus());
47  }
virtual bool getStatus() const =0
Get status of object.

Member Data Documentation

JLANG::JSinglePointer<JWriter> JIO::JBufferedWriter::out
protected

Definition at line 230 of file JBufferedIO.hh.

char* JIO::JBufferedWriter::buffer
protected

internal buffer

Definition at line 232 of file JBufferedIO.hh.

int JIO::JBufferedWriter::size
protected

size of internal buffer

Definition at line 233 of file JBufferedIO.hh.

int JIO::JBufferedWriter::pos
protected

pointer to end of buffered data

Definition at line 234 of file JBufferedIO.hh.


The documentation for this class was generated from the following file: