Jpp  debug
the software that should make you happy
JDriver.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JDRIVER__
2 #define __JTOOLS__JDRIVER__
3 
4 #include <istream>
5 #include <ostream>
6 
8 #include "JLang/JBool.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JTOOLS {}
16 namespace JPP { using namespace JTOOLS; }
17 
18 namespace JTOOLS {
19 
20  using JLANG::JBool;
21 
22 
23  /**
24  * Auxiliary class to load and store objects.
25  */
26  template<class JClass_t>
27  class JDriver {
28  private:
29  /**
30  * Load object without input.
31  *
32  * \param option I/O option
33  * \return pointer to newly loaded object
34  */
35  static inline JClass_t* load(JLANG::JBool<false> option)
36  {
37  return new JClass_t();
38  }
39 
40 
41  /**
42  * Load object without input.
43  *
44  * \param in input stream
45  * \param option I/O option
46  * \return pointer to newly loaded object
47  */
48  static inline JClass_t* load(std::istream& in, JLANG::JBool<false> option)
49  {
50  return load(option);
51  }
52 
53 
54  /**
55  * Load object with input.
56  *
57  * \param in input stream
58  * \param option I/O option
59  * \return pointer to newly loaded object
60  */
61  static inline JClass_t* load(std::istream& in, JLANG::JBool<true> option)
62  {
63  JClass_t* p = load(JLANG::JBool<false>());
64 
65  in >> *p;
66 
67  if (in.fail()) {
68 
69  delete p;
70 
71  p = NULL;
72  }
73 
74  return p;
75  }
76 
77 
78  /**
79  * Store object without output.
80  * This implementation doesn't do anything.
81  *
82  * \param out output stream
83  * \param option I/O option
84  * \param p pointer to object
85  */
86  static inline void store(std::ostream& out, const JClass_t* p, JBool<false> option)
87  {}
88 
89 
90  /**
91  * Store object with output.
92  *
93  * \param out output stream
94  * \param option I/O option
95  * \param p pointer object
96  */
97  static inline void store(std::ostream& out, const JClass_t* p, JBool<true> option)
98  {
99  if (p != NULL) {
100  out << *p;
101  }
102  }
103 
104 
105  public:
106  /**
107  * Load object.
108  *
109  * \return pointer to newly loaded object
110  */
111  static inline JClass_t* load()
112  {
114  }
115 
116 
117  /**
118  * Load object.
119  *
120  * \param in input stream
121  * \return pointer to newly loaded object
122  */
123  static inline JClass_t* load(std::istream& in)
124  {
126  }
127 
128 
129  /**
130  * Store object.
131  *
132  * \param out output stream
133  * \param p pointer to object
134  */
135  template<class T>
136  static inline void store(std::ostream& out, const T* p)
137  {
138  store(out, dynamic_cast<const JClass_t*>(p), JLANG::JBool<JStreamAvailable<JClass_t>::has_ostream>());
139  }
140  };
141 }
142 
143 #endif
Test availability of stream operators.
Auxiliary class to load and store objects.
Definition: JDriver.hh:27
static JClass_t * load(std::istream &in, JLANG::JBool< false > option)
Load object without input.
Definition: JDriver.hh:48
static JClass_t * load(std::istream &in, JLANG::JBool< true > option)
Load object with input.
Definition: JDriver.hh:61
static JClass_t * load()
Load object.
Definition: JDriver.hh:111
static JClass_t * load(std::istream &in)
Load object.
Definition: JDriver.hh:123
static JClass_t * load(JLANG::JBool< false > option)
Load object without input.
Definition: JDriver.hh:35
static void store(std::ostream &out, const T *p)
Store object.
Definition: JDriver.hh:136
static void store(std::ostream &out, const JClass_t *p, JBool< false > option)
Store object without output.
Definition: JDriver.hh:86
static void store(std::ostream &out, const JClass_t *p, JBool< true > option)
Store object with output.
Definition: JDriver.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Auxiliary template class for type bool.
Definition: JBool.hh:21