Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
 JFileStreamWriter (const char *file_name, const int size=1048576)
 Constructor.
 
void open (const char *file_name)
 Open file.
 
void close ()
 Close file.
 
bool operator! () const
 Negated status of this object.
 
JWriteroperator<< (const JSerialisable &object)
 Write serialisable data object.
 
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)
 
virtual bool getStatus () const override
 Status of writer.
 
virtual int write (const char *zbuf, int n) override
 Write byte array.
 
void flush ()
 Write internal data to output.
 
JWriterstore (const JSerialisable &object)
 Write object.
 
template<class T >
JWriterstore (const T &object)
 Write object.
 
 operator bool () const
 Type conversion operator.
 

Protected Attributes

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

Detailed Description

Binary buffered file output.

Definition at line 93 of file JFileStreamIO.hh.

Constructor & Destructor Documentation

◆ JFileStreamWriter() [1/2]

JIO::JFileStreamWriter::JFileStreamWriter ( )
inline

Default constructor.

Definition at line 107 of file JFileStreamIO.hh.

107 :
108 std::ofstream(),
109 JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)))
110 {}
JBufferedWriter(JWriter *__out, const int __size=1048576)
Constructor.

◆ JFileStreamWriter() [2/2]

JIO::JFileStreamWriter::JFileStreamWriter ( const char * file_name,
const int size = 1048576 )
inline

Constructor.

Parameters
file_namefile name
sizesize of internal buffer

Definition at line 119 of file JFileStreamIO.hh.

120 :
121 std::ofstream(),
122 JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)), size)
123 {
124 open(file_name);
125 }
int size
size of internal buffer
void open(const char *file_name)
Open file.

Member Function Documentation

◆ open()

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

Open file.

Parameters
file_namefile name

Definition at line 133 of file JFileStreamIO.hh.

134 {
135 static_cast<std::ofstream*>(this)->open(file_name, std::ios::binary);
136 }

◆ close()

void JIO::JFileStreamWriter::close ( )
inline

Close file.

Definition at line 142 of file JFileStreamIO.hh.

143 {
144 static_cast<JBufferedWriter*>(this)->flush();
145 static_cast<std::ofstream*> (this)->close();
146 }
void flush()
Write internal data to output.
void close()
Close file.

◆ operator!()

bool JLANG::JAbstractObjectStatus::operator! ( ) const
inline

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 override
Status of writer.

◆ operator<<() [1/16]

JWriter & JIO::JWriter::operator<< ( const JSerialisable & object)
inline

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 }

◆ operator<<() [2/16]

JWriter & JIO::JWriter::operator<< ( const bool value)
inline

Definition at line 150 of file JSerialisable.hh.

150{ write((const char*) &value, sizeof(bool)); return *this; }
virtual int write(const char *zbuf, int n) override
Write byte array.

◆ operator<<() [3/16]

JWriter & JIO::JWriter::operator<< ( const char value)
inline

Definition at line 151 of file JSerialisable.hh.

151{ write((const char*) &value, sizeof(char)); return *this; }

◆ operator<<() [4/16]

JWriter & JIO::JWriter::operator<< ( const unsigned char value)
inline

Definition at line 152 of file JSerialisable.hh.

152{ write((const char*) &value, sizeof(unsigned char)); return *this; }

◆ operator<<() [5/16]

JWriter & JIO::JWriter::operator<< ( const short value)
inline

Definition at line 153 of file JSerialisable.hh.

153{ write((const char*) &value, sizeof(short)); return *this; }

◆ operator<<() [6/16]

JWriter & JIO::JWriter::operator<< ( const unsigned short value)
inline

Definition at line 154 of file JSerialisable.hh.

154{ write((const char*) &value, sizeof(unsigned short)); return *this; }

◆ operator<<() [7/16]

JWriter & JIO::JWriter::operator<< ( const int value)
inline

Definition at line 155 of file JSerialisable.hh.

155{ write((const char*) &value, sizeof(int)); return *this; }

◆ operator<<() [8/16]

JWriter & JIO::JWriter::operator<< ( const unsigned int value)
inline

Definition at line 156 of file JSerialisable.hh.

156{ write((const char*) &value, sizeof(unsigned int)); return *this; }

◆ operator<<() [9/16]

JWriter & JIO::JWriter::operator<< ( const long int value)
inline

Definition at line 157 of file JSerialisable.hh.

157{ write((const char*) &value, sizeof(long int)); return *this; }

◆ operator<<() [10/16]

JWriter & JIO::JWriter::operator<< ( const unsigned long int value)
inline

Definition at line 158 of file JSerialisable.hh.

158{ write((const char*) &value, sizeof(unsigned long int)); return *this; }

◆ operator<<() [11/16]

JWriter & JIO::JWriter::operator<< ( const long long int value)
inline

Definition at line 159 of file JSerialisable.hh.

159{ write((const char*) &value, sizeof(long long int)); return *this; }

◆ operator<<() [12/16]

JWriter & JIO::JWriter::operator<< ( const unsigned long long int value)
inline

Definition at line 160 of file JSerialisable.hh.

160{ write((const char*) &value, sizeof(unsigned long long int)); return *this; }

◆ operator<<() [13/16]

JWriter & JIO::JWriter::operator<< ( const float value)
inline

Definition at line 161 of file JSerialisable.hh.

161{ write((const char*) &value, sizeof(float)); return *this; }

◆ operator<<() [14/16]

JWriter & JIO::JWriter::operator<< ( const double value)
inline

Definition at line 162 of file JSerialisable.hh.

162{ write((const char*) &value, sizeof(double)); return *this; }

◆ operator<<() [15/16]

JWriter & JIO::JWriter::operator<< ( const long double value)
inline

Definition at line 163 of file JSerialisable.hh.

163{ write((const char*) &value, sizeof(long double)); return *this; }

◆ operator<<() [16/16]

JWriter & JIO::JWriter::operator<< ( const JLANG::JObjectID & value)
inline

Definition at line 164 of file JSerialisable.hh.

164{ return (*this) << value.getID(); }
int getID() const
Get identifier.
Definition JObjectID.hh:50

◆ getStatus()

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

Status of writer.

Returns
status of this writer

Implements JLANG::JAbstractObjectStatus.

Definition at line 188 of file JBufferedIO.hh.

189 {
190 return (bool) *out;
191 }
JLANG::JSinglePointer< JWriter > out

◆ write()

virtual int JIO::JBufferedWriter::write ( const char * zbuf,
int n )
inlineoverridevirtualinherited

Write byte array.

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

Implements JLANG::JBinaryOutput.

Definition at line 201 of file JBufferedIO.hh.

202 {
203 for (int i = 0; i != n; ) {
204
205 int m = n - i;
206
207 if (m > size - pos) {
208
209 flush();
210
211 if (m > size - pos) {
212 m = size - pos;
213 }
214 }
215
216 memcpy(buffer + pos, zbuf + i, m);
217
218 i += m;
219 pos += m;
220 }
221
222 return n;
223 }
char * buffer
internal buffer
int pos
pointer to end of buffered data
const int n
Definition JPolint.hh:791

◆ flush()

void JIO::JBufferedWriter::flush ( )
inlineinherited

Write internal data to output.

Definition at line 229 of file JBufferedIO.hh.

230 {
231 pos -= out->write(buffer, pos);
232 }

◆ store() [1/2]

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 }

◆ store() [2/2]

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 }

◆ operator bool()

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.

Member Data Documentation

◆ out

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

Definition at line 236 of file JBufferedIO.hh.

◆ buffer

char* JIO::JBufferedWriter::buffer
protectedinherited

internal buffer

Definition at line 238 of file JBufferedIO.hh.

◆ size

int JIO::JBufferedWriter::size
protectedinherited

size of internal buffer

Definition at line 239 of file JBufferedIO.hh.

◆ pos

int JIO::JBufferedWriter::pos
protectedinherited

pointer to end of buffered data

Definition at line 240 of file JBufferedIO.hh.


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