Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JIO Namespace Reference

Auxiliary classes and methods for binary I/O. More...

Classes

class  JBinaryFileReader
 Object reading from binary file (i.e. .jpp). More...
 
class  JBinaryFileReader< T, false >
 Template specialisation of JBinaryFileReader for unserialisable data types. More...
 
class  JBinaryFileReader< T, true >
 Template specialisation of JBinaryFileReader for serialisable data types. More...
 
class  JBinaryFileWriter
 Object(s) writing to binary file (i.e. .jpp). More...
 
class  JBinaryWriter
 Implementation of object output to binary file for single data type. More...
 
class  JBinaryWriter< JTypeList< JHead_t, JNullType > >
 Terminator class of recursive JBinaryWriter class. More...
 
class  JBinaryWriter< JTypeList< JHead_t, JTail_t > >
 Implementation of object output to binary file for multiple data types. More...
 
class  JBinaryWriterObjectOutput
 Auxiliary class for object writing to binary stream. More...
 
class  JBinaryWriterObjectOutput< T, false >
 Implementation of object output for binary stream incompatible data types. More...
 
class  JBinaryWriterObjectOutput< T, true >
 Implementation of object output for binary stream compatible data types. More...
 
class  JBufferedReader
 Buffered binary input. More...
 
class  JBufferedWriter
 Buffered binary output. More...
 
class  JByteArrayReader
 Byte array binary input. More...
 
class  JByteArrayWriter
 Byte array binary output. More...
 
class  JFileReader
 Binary input based on a file descriptor. More...
 
class  JFileStreamReader
 Binary buffered file input. More...
 
class  JFileStreamWriter
 Binary buffered file output. More...
 
class  JFileWriter
 Binary output based on a file descriptor. More...
 
struct  JObjectBinaryIO
 Auxiliary base class for storing and loading a single object to and from a binary file, respectively. More...
 
class  JReader
 Interface for binary input. More...
 
class  JReaderObjectIterator
 JReader object iterator. More...
 
class  JSerialisable
 Forward declaration of binary output. More...
 
class  JStreamReader
 Binary input based on std::istream. More...
 
class  JStreamWriter
 Binary output based on std::ostream. More...
 
class  JWriter
 Interface for binary output. More...
 
class  JWriterObjectOutput
 Implementation of object output using JIO::JWriter for single data type. More...
 
class  JWriterObjectOutput< JTypeList< JHead_t, JNullType > >
 Terminator class of recursive JWriterObjectOutput class. More...
 
class  JWriterObjectOutput< JTypeList< JHead_t, JTail_t > >
 Implementation of object output for multiple data types. More...
 

Functions

template<class T >
void load (const char *file_name, T &object)
 Load object from input file.
 
template<class T >
void store (const char *file_name, const T &object)
 Store object to output file.
 
JReaderoperator>> (JReader &in, std::string &object)
 Read template std::string from input.
 
JWriteroperator<< (JWriter &out, const std::string &object)
 Write template std::string to output.
 
template<class JElement_t , class JAllocator_t >
JReaderoperator>> (JReader &in, std::vector< JElement_t, JAllocator_t > &object)
 Read template std::vector from input.
 
template<class JElement_t , class JAllocator_t >
JWriteroperator<< (JWriter &out, const std::vector< JElement_t, JAllocator_t > &object)
 Write template std::vector to output.
 
template<class JElement_t , class JAllocator_t >
JReaderoperator>> (JReader &in, std::list< JElement_t, JAllocator_t > &object)
 Read template std::list from input.
 
template<class JElement_t , class JAllocator_t >
JWriteroperator<< (JWriter &out, const std::list< JElement_t, JAllocator_t > &object)
 Write template std::list to output.
 
template<class JElement_t , class JComparator_t , class JAllocator_t >
JReaderoperator>> (JReader &in, std::set< JElement_t, JComparator_t, JAllocator_t > &object)
 Read template std::set from input.
 
template<class JElement_t , class JComparator_t , class JAllocator_t >
JWriteroperator<< (JWriter &out, const std::set< JElement_t, JComparator_t, JAllocator_t > &object)
 Write template std::set to output.
 
template<class JElement_t , class JComparator_t , class JAllocator_t >
JReaderoperator>> (JReader &in, std::multiset< JElement_t, JComparator_t, JAllocator_t > &object)
 Read template std::multiset from input.
 
template<class JElement_t , class JComparator_t , class JAllocator_t >
JWriteroperator<< (JWriter &out, const std::multiset< JElement_t, JComparator_t, JAllocator_t > &object)
 Write template std::multiset to output.
 
template<class JKey_t , class JValue_t >
JReaderoperator>> (JReader &in, std::pair< JKey_t, JValue_t > &object)
 Read template std::pair from input.
 
template<class JKey_t , class JValue_t >
JWriteroperator<< (JWriter &out, const std::pair< JKey_t, JValue_t > &object)
 Write template std::pair to output.
 
template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JReaderoperator>> (JReader &in, std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &object)
 Read template std::map from input.
 
template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JWriteroperator<< (JWriter &out, const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &object)
 Write template std::map to output.
 
template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JReaderoperator>> (JReader &in, std::multimap< JKey_t, JValue_t, JComparator_t, JAllocator_t > &object)
 Read template std::multimap from input.
 
template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JWriteroperator<< (JWriter &out, const std::multimap< JKey_t, JValue_t, JComparator_t, JAllocator_t > &object)
 Write template std::multimap to output.
 

Detailed Description

Auxiliary classes and methods for binary I/O.

Author
mdejong

Function Documentation

◆ load()

template<class T >
void JIO::load ( const char * file_name,
T & object )
inline

Load object from input file.

Parameters
file_namefile name
objectobject to be read

Definition at line 30 of file JIOToolkit.hh.

31 {
32 JFileStreamReader in(file_name);
33
34 if (!in) {
35 THROW(JFileOpenException, "Error opening file " << file_name);
36 }
37
38 in.load(object);
39
40 if (!in) {
41 THROW(JFileReadException, "Error reading file " << file_name);
42 }
43
44 in.close();
45 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Binary buffered file input.
Exception for opening of file.

◆ store()

template<class T >
void JIO::store ( const char * file_name,
const T & object )
inline

Store object to output file.

Parameters
file_namefile name
objectobject to be written

Definition at line 55 of file JIOToolkit.hh.

56 {
57 JFileStreamWriter out(file_name);
58
59 if (!out) {
60 THROW(JFileOpenException, "Error opening file " << file_name);
61 }
62
63 out.store(object);
64 out.close();
65 }
Binary buffered file output.

◆ operator>>() [1/8]

JReader & JIO::operator>> ( JReader & in,
std::string & object )
inline

Read template std::string from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 27 of file JSTDIO.hh.

28 {
29 unsigned int n = 0;
30
31 object.clear();
32
33 in.read((char*) &n, sizeof(unsigned int));
34
35 for (char c; n != 0; --n, object += c) {
36 in.read(&c, sizeof(char));
37 }
38
39 return in;
40 }
virtual int read(char *buffer, const int length)=0
Read byte array.

◆ operator<<() [1/8]

JWriter & JIO::operator<< ( JWriter & out,
const std::string & object )
inline

Write template std::string to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 50 of file JSTDIO.hh.

51 {
52 unsigned int n = object.size();
53
54 out.write((const char*) &n, sizeof(unsigned int));
55 out.write((const char*) object.c_str(), n);
56
57 return out;
58 }
virtual int write(const char *buffer, const int length)=0
Write byte array.

◆ operator>>() [2/8]

template<class JElement_t , class JAllocator_t >
JReader & JIO::operator>> ( JReader & in,
std::vector< JElement_t, JAllocator_t > & object )
inline

Read template std::vector from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 69 of file JSTDIO.hh.

70 {
71 int n = 0;
72
73 in >> n;
74
75 object.resize(n);
76
77 for (typename std::vector<JElement_t, JAllocator_t>::iterator i = object.begin(); i != object.end(); ++i) {
78 in >> *i;
79 }
80
81 return in;
82 }

◆ operator<<() [2/8]

template<class JElement_t , class JAllocator_t >
JWriter & JIO::operator<< ( JWriter & out,
const std::vector< JElement_t, JAllocator_t > & object )
inline

Write template std::vector to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 93 of file JSTDIO.hh.

94 {
95 int n = object.size();
96
97 out << n;
98
99 for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
100 out << *i;
101 }
102
103 return out;
104 }

◆ operator>>() [3/8]

template<class JElement_t , class JAllocator_t >
JReader & JIO::operator>> ( JReader & in,
std::list< JElement_t, JAllocator_t > & object )
inline

Read template std::list from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 115 of file JSTDIO.hh.

116 {
117 int n = 0;
118
119 in >> n;
120
122
123 object.clear();
124
125 for (int i = 0; i != n; ++i) {
126
127 in >> element;
128
129 object.push_back(element);
130 }
131
132 return in;
133 }

◆ operator<<() [3/8]

template<class JElement_t , class JAllocator_t >
JWriter & JIO::operator<< ( JWriter & out,
const std::list< JElement_t, JAllocator_t > & object )
inline

Write template std::list to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 144 of file JSTDIO.hh.

145 {
146 int n = object.size();
147
148 out << n;
149
150 for (typename std::list<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
151 out << *i;
152 }
153
154 return out;
155 }

◆ operator>>() [4/8]

template<class JElement_t , class JComparator_t , class JAllocator_t >
JReader & JIO::operator>> ( JReader & in,
std::set< JElement_t, JComparator_t, JAllocator_t > & object )
inline

Read template std::set from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 166 of file JSTDIO.hh.

167 {
168 int n = 0;
169
170 in >> n;
171
173
174 object.clear();
175
176 for (int i = 0; i != n; ++i) {
177
178 in >> element;
179
180 object.insert(element);
181 }
182
183 return in;
184 }

◆ operator<<() [4/8]

template<class JElement_t , class JComparator_t , class JAllocator_t >
JWriter & JIO::operator<< ( JWriter & out,
const std::set< JElement_t, JComparator_t, JAllocator_t > & object )
inline

Write template std::set to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 195 of file JSTDIO.hh.

196 {
197 int n = object.size();
198
199 out << n;
200
201 for (typename std::set<JElement_t, JComparator_t,JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
202 out << *i;
203 }
204
205 return out;
206 }

◆ operator>>() [5/8]

template<class JElement_t , class JComparator_t , class JAllocator_t >
JReader & JIO::operator>> ( JReader & in,
std::multiset< JElement_t, JComparator_t, JAllocator_t > & object )
inline

Read template std::multiset from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 217 of file JSTDIO.hh.

218 {
219 int n = 0;
220
221 in >> n;
222
224
225 object.clear();
226
227 for (int i = 0; i != n; ++i) {
228
229 in >> element;
230
231 object.insert(element);
232 }
233
234 return in;
235 }

◆ operator<<() [5/8]

template<class JElement_t , class JComparator_t , class JAllocator_t >
JWriter & JIO::operator<< ( JWriter & out,
const std::multiset< JElement_t, JComparator_t, JAllocator_t > & object )
inline

Write template std::multiset to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 246 of file JSTDIO.hh.

247 {
248 int n = object.size();
249
250 out << n;
251
252 for (typename std::multiset<JElement_t, JComparator_t,JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
253 out << *i;
254 }
255
256 return out;
257 }

◆ operator>>() [6/8]

template<class JKey_t , class JValue_t >
JReader & JIO::operator>> ( JReader & in,
std::pair< JKey_t, JValue_t > & object )
inline

Read template std::pair from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 268 of file JSTDIO.hh.

269 {
270 in >> object.first;
271 in >> object.second;
272
273 return in;
274 }

◆ operator<<() [6/8]

template<class JKey_t , class JValue_t >
JWriter & JIO::operator<< ( JWriter & out,
const std::pair< JKey_t, JValue_t > & object )
inline

Write template std::pair to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 285 of file JSTDIO.hh.

286 {
287 out << object.first;
288 out << object.second;
289
290 return out;
291 }

◆ operator>>() [7/8]

template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JReader & JIO::operator>> ( JReader & in,
std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > & object )
inline

Read template std::map from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 302 of file JSTDIO.hh.

303 {
304 int n = 0;
305
306 in >> n;
307
310
311 object.clear();
312
313 for (int i = 0; i != n; ++i) {
314
315 in >> key >> value;
316
317 object[key]=value;
318 }
319
320 return in;
321 }

◆ operator<<() [7/8]

template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JWriter & JIO::operator<< ( JWriter & out,
const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > & object )
inline

Write template std::map to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 332 of file JSTDIO.hh.

333 {
334 int n = object.size();
335
336 out << n;
337
338 for (typename std::map<JKey_t, JValue_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
339 out << *i;
340 }
341
342 return out;
343 }

◆ operator>>() [8/8]

template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JReader & JIO::operator>> ( JReader & in,
std::multimap< JKey_t, JValue_t, JComparator_t, JAllocator_t > & object )
inline

Read template std::multimap from input.

Parameters
inreader
objectobject
Returns
reader

Definition at line 354 of file JSTDIO.hh.

355 {
356 int n = 0;
357
358 in >> n;
359
362
363 object.clear();
364
365 for (int i = 0; i != n; ++i) {
366
367 in >> key >> value;
368
369 object[key]=value;
370 }
371
372 return in;
373 }

◆ operator<<() [8/8]

template<class JKey_t , class JValue_t , class JComparator_t , class JAllocator_t >
JWriter & JIO::operator<< ( JWriter & out,
const std::multimap< JKey_t, JValue_t, JComparator_t, JAllocator_t > & object )
inline

Write template std::multimap to output.

Parameters
outwriter
objectobject
Returns
writer

Definition at line 384 of file JSTDIO.hh.

385 {
386 int n = object.size();
387
388 out << n;
389
390 for (typename std::multimap<JKey_t, JValue_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
391 out << *i;
392 }
393
394 return out;
395 }