Jpp
JIOToolkit.hh
Go to the documentation of this file.
1 #ifndef __JIO__JIOTOOLKIT__
2 #define __JIO__JIOTOOLKIT__
3 
4 #include "JLang/JException.hh"
5 #include "JIO/JFileStreamIO.hh"
6 #include "JIO/JSTDIO.hh"
7 
8 
9 /**
10  * \file
11  * Auxiliary methods for binary I/O.
12  * \author mdejong
13  */
14 namespace JIO {}
15 namespace JPP { using namespace JIO; }
16 
17 namespace 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(std::string("Error opening file ") + file_name);
36  }
37 
38  in.load(object);
39 
40  if (!in) {
41  throw JFileReadException(std::string("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(std::string("Error opening file ") + file_name);
61  }
62 
63  out.store(object);
64  out.close();
65  }
66 }
67 
68 #endif
JException.hh
JIO::JFileStreamWriter
Binary buffered file output.
Definition: JFileStreamIO.hh:72
JIO::JFileStreamReader
Binary buffered file input.
Definition: JFileStreamIO.hh:22
JLANG::JFileReadException
Exception for reading of file.
Definition: JException.hh:360
JFileStreamIO.hh
JLANG::JFileOpenException
Exception for opening of file.
Definition: JException.hh:342
JIO::JWriter::store
JWriter & store(const JSerialisable &object)
Write object.
Definition: JSerialisable.hh:168
JIO::JReader::load
JReader & load(JSerialisable &object)
Read object.
Definition: JSerialisable.hh:107
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JSTDIO.hh
JIO::JFileStreamWriter::close
void close()
Close file.
Definition: JFileStreamIO.hh:121
JIO
Auxiliary classes and methods for binary I/O.
Definition: JBinaryFileReader.hh:17
JIO::load
void load(const char *file_name, T &object)
Load object from input file.
Definition: JIOToolkit.hh:30
JIO::store
void store(const char *file_name, const T &object)
Store object to output file.
Definition: JIOToolkit.hh:55