Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
JIO::JFileStreamWriter Class Reference

Binary buffered file output. More...

#include <JFileStreamIO.hh>

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

Public Member Functions

 JFileStreamWriter ()
 Default constructor. More...
 
 JFileStreamWriter (const char *file_name, const int size=1048576)
 Constructor. More...
 
void open (const char *file_name)
 Open file. More...
 
void close ()
 Close file. More...
 
virtual bool getStatus () const
 Status of writer. More...
 
virtual int write (const char *zbuf, int n)
 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)
 
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

Binary buffered file output.

Definition at line 72 of file JFileStreamIO.hh.

Constructor & Destructor Documentation

JIO::JFileStreamWriter::JFileStreamWriter ( )
inline

Default constructor.

Definition at line 86 of file JFileStreamIO.hh.

86  :
87  std::ofstream(),
88  JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)))
89  {}
JBufferedWriter(JWriter *__out, const int __size=1048576)
Constructor.
Definition: JBufferedIO.hh:149
Binary output based on std::ostream.
Definition: JStreamIO.hh:81
JIO::JFileStreamWriter::JFileStreamWriter ( const char *  file_name,
const int  size = 1048576 
)
inline

Constructor.

Parameters
file_namefile name
sizesize of internal buffer

Definition at line 98 of file JFileStreamIO.hh.

99  :
100  std::ofstream(),
101  JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)), size)
102  {
103  open(file_name);
104  }
void open(const char *file_name)
Open file.
JBufferedWriter(JWriter *__out, const int __size=1048576)
Constructor.
Definition: JBufferedIO.hh:149
int size
size of internal buffer
Definition: JBufferedIO.hh:226
Binary output based on std::ostream.
Definition: JStreamIO.hh:81

Member Function Documentation

void JIO::JFileStreamWriter::open ( const char *  file_name)
inline

Open file.

Parameters
file_namefile name

Definition at line 112 of file JFileStreamIO.hh.

113  {
114  static_cast<std::ofstream*>(this)->open(file_name, std::ios::binary);
115  }
void open(const char *file_name)
Open file.
void JIO::JFileStreamWriter::close ( )
inline

Close file.

Definition at line 121 of file JFileStreamIO.hh.

122  {
123  static_cast<JBufferedWriter*>(this)->flush();
124  static_cast<std::ofstream*> (this)->close();
125  }
void close()
Close file.
Buffered binary output.
Definition: JBufferedIO.hh:138
void flush()
Write internal data to output.
Definition: JBufferedIO.hh:216
virtual bool JIO::JBufferedWriter::getStatus ( ) const
inlinevirtualinherited

Status of writer.

Returns
status of this writer

Implements JLANG::JAbstractObjectStatus.

Definition at line 175 of file JBufferedIO.hh.

176  {
177  return (bool) *out;
178  }
JLANG::JSinglePointer< JWriter > out
Definition: JBufferedIO.hh:223
virtual int JIO::JBufferedWriter::write ( const char *  zbuf,
int  n 
)
inlinevirtualinherited

Write byte array.

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

Implements JLANG::JBinaryOutput.

Definition at line 188 of file JBufferedIO.hh.

189  {
190  for (int i = 0; i != n; ) {
191 
192  int m = n - i;
193 
194  if (m > size - pos) {
195 
196  flush();
197 
198  if (m > size - pos) {
199  m = size - pos;
200  }
201  }
202 
203  memcpy(buffer + pos, zbuf + i, m);
204 
205  i += m;
206  pos += m;
207  }
208 
209  return n;
210  }
int pos
pointer to end of buffered data
Definition: JBufferedIO.hh:227
int size
size of internal buffer
Definition: JBufferedIO.hh:226
alias put_queue eval echo n
Definition: qlib.csh:19
char * buffer
internal buffer
Definition: JBufferedIO.hh:225
void flush()
Write internal data to output.
Definition: JBufferedIO.hh:216
void JIO::JBufferedWriter::flush ( )
inlineinherited

Write internal data to output.

Definition at line 216 of file JBufferedIO.hh.

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

Write serialisable data object.

Parameters
objectserialisable data object
Returns
JWriter

Definition at line 142 of file JSerialisable.hh.

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

Definition at line 148 of file JSerialisable.hh.

148 { 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 149 of file JSerialisable.hh.

149 { 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 150 of file JSerialisable.hh.

150 { 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 151 of file JSerialisable.hh.

151 { 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 152 of file JSerialisable.hh.

152 { 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 153 of file JSerialisable.hh.

153 { 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 154 of file JSerialisable.hh.

154 { 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 155 of file JSerialisable.hh.

155 { 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 156 of file JSerialisable.hh.

156 { 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 157 of file JSerialisable.hh.

157 { 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 158 of file JSerialisable.hh.

158 { 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 159 of file JSerialisable.hh.

159 { 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 160 of file JSerialisable.hh.

160 { 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 161 of file JSerialisable.hh.

161 { 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::store ( const JSerialisable object)
inlineinherited

Write object.

Parameters
objectobject
Returns
this writer

Definition at line 170 of file JSerialisable.hh.

171  {
172  return object.write(*this);
173  }
template<class T >
JWriter& JIO::JWriter::store ( const T object)
inlineinherited

Write object.

Parameters
objectobject
Returns
this writer

Definition at line 183 of file JSerialisable.hh.

184  {
185  return *this << object;
186  }
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
protectedinherited

Definition at line 223 of file JBufferedIO.hh.

char* JIO::JBufferedWriter::buffer
protectedinherited

internal buffer

Definition at line 225 of file JBufferedIO.hh.

int JIO::JBufferedWriter::size
protectedinherited

size of internal buffer

Definition at line 226 of file JBufferedIO.hh.

int JIO::JBufferedWriter::pos
protectedinherited

pointer to end of buffered data

Definition at line 227 of file JBufferedIO.hh.


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