Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JIOToolkit.hh
Go to the documentation of this file.
1#ifndef __JIO__JIOTOOLKIT__
2#define __JIO__JIOTOOLKIT__
3
4#include "JLang/JException.hh"
6#include "JIO/JSTDIO.hh"
7
8
9/**
10 * \file
11 * Auxiliary methods for binary I/O.
12 * \author mdejong
13 */
14namespace JIO {}
15namespace JPP { using namespace JIO; }
16
17namespace JIO {
18
21
22
23 /**
24 * Load object from input file.
25 *
26 * \param file_name file name
27 * \param object object to be read
28 */
29 template<class T>
30 inline void load(const char* file_name, T& object)
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 }
46
47
48 /**
49 * Store object to output file.
50 *
51 * \param file_name file name
52 * \param object object to be written
53 */
54 template<class T>
55 inline void store(const char* file_name, const T& object)
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 }
66}
67
68#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
STD extensions for binary I/O.
Binary buffered file input.
Binary buffered file output.
void close()
Close file.
JReader & load(JSerialisable &object)
Read object.
JWriter & store(const JSerialisable &object)
Write object.
Exception for opening of file.
Exception for reading of file.
Auxiliary classes and methods for binary I/O.
void load(const char *file_name, T &object)
Load object from input file.
Definition JIOToolkit.hh:30
void store(const char *file_name, const T &object)
Store object to output file.
Definition JIOToolkit.hh:55
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).