Jpp  19.1.0-rc.1
the software that should make you happy
JObjectStreamIO.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JOBJECTSTREAMIO__
2 #define __JLANG__JOBJECTSTREAMIO__
3 
4 #include <fstream>
5 
6 #include "JLang/JObjectIO.hh"
7 
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JLANG {}
14 namespace JPP { using namespace JLANG; }
15 
16 namespace JLANG {
17 
18  /**
19  * Auxiliary base class for storing and loading a single object to and from an ASCII file, respectively.
20  * The implementation of this functionality is based on a static cast of
21  * the given template parameter (known as "curiously recurring template pattern").
22  */
23  template<class T>
24  struct JObjectStreamIO {
25  /**
26  * Load from input file.
27  *
28  * \param file_name file name
29  */
30  void load(const char* file_name)
31  {
32  JLANG::load<std::ifstream>(file_name, static_cast<T&>(*this));
33  }
34 
35 
36  /**
37  * Store to output file.
38  *
39  * \param file_name file name
40  */
41  void store(const char* file_name) const
42  {
43  JLANG::store<std::ofstream>(file_name, static_cast<const T&>(*this));
44  }
45  };
46 }
47 
48 #endif
General methods for loading and storing a single object from and to a file, respectively.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary base class for storing and loading a single object to and from an ASCII file,...
void store(const char *file_name) const
Store to output file.
void load(const char *file_name)
Load from input file.