Jpp  19.1.0
the software that should make you happy
JAbstractObjectWriter.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JABSTRACTOBJECTWRITER__
2 #define __JLANG__JABSTRACTOBJECTWRITER__
3 
4 #include "JLang/JObjectOutput.hh"
5 #include "JLang/JTypeList.hh"
6 #include "JLang/JNullType.hh"
7 #include "JLang/JException.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JLANG {}
15 namespace JPP { using namespace JLANG; }
16 
17 namespace JLANG {
18 
19  /**
20  * Abstract interface for object writing.
21  *
22  * This class implements the JObjectOutput interface by transferring
23  * the interface methods to a helper object via a single interface method getHelper().
24  */
25  template<class T>
27  public virtual JObjectOutput<T>
28  {
29  /**
30  * Get helper.
31  *
32  * \return pointer to helper
33  */
34  virtual JObjectOutput<T>* getHelper() const = 0;
35 
36 
37  /**
38  * Object output.
39  *
40  * \param object object
41  * \return true if OK; else false
42  */
43  virtual bool put(const T& object) override
44  {
45  return (this->getHelper() != NULL && this->getHelper()->put(object));
46  }
47  };
48 
49 
50  /**
51  * Abstract interface for object writing for multiple data types.
52  *
53  * This class recursively implements the JLANG::JObjectOutput interface
54  * for all data types by deriving from:
55  * - JAbstractObjectWriter<JHead_t>; and
56  * - JAbstractObjectWriter<JTail_t>.
57  */
58  template<class JHead_t, class JTail_t>
59  struct JAbstractObjectWriter< JTypeList<JHead_t, JTail_t> > :
60  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
61  public JAbstractObjectWriter<JHead_t>,
62  public JAbstractObjectWriter<JTail_t>
63  {
66  };
67 
68 
69  /**
70  * Terminator class of recursive JAbstractObjectWriter class.
71  */
72  template<class JHead_t>
74  public JAbstractObjectWriter<JHead_t>
75  {};
76 
77 
78  /**
79  * Abstract interface for object writing with named access.
80  *
81  * This class implements the JAccessibleObjectOutput interface by transferring
82  * the interface methods to a helper object via a single interface method getHelper().
83  */
84  template<class T>
86  public virtual JAccessibleObjectOutput<T>,
87  public JAbstractObjectWriter <T>
88  {
89  /**
90  * Get helper.
91  *
92  * \return pointer to helper
93  */
94  virtual JAccessibleObjectOutput<T>* getHelper() const override = 0;
95 
96 
97  /**
98  * Check is device is open.
99  *
100  * \return true if open; else false
101  */
102  virtual bool is_open() const override
103  {
104  if (this->getHelper() != NULL)
105  return this->getHelper()->is_open();
106  else
107  return false;
108  }
109 
110 
111  /**
112  * Open device.
113  *
114  * \param file_name file name
115  */
116  virtual void open(const char* file_name) override
117  {
118  if (this->getHelper() != NULL) {
119  this->getHelper()->open(file_name);
120  }
121  }
122 
123 
124  /**
125  * Close device.
126  */
127  virtual void close() override
128  {
129  if (this->getHelper() != NULL) {
130  this->getHelper()->close();
131  }
132  }
133  };
134 }
135 
136 #endif
Exceptions.
Interface for object output with named access.
Template interface of object output for single data type.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Abstract interface for object writing with named access.
virtual void open(const char *file_name) override
Open device.
virtual void close() override
Close device.
virtual JAccessibleObjectOutput< T > * getHelper() const override=0
Get helper.
virtual bool is_open() const override
Check is device is open.
Abstract interface for object writing.
virtual bool put(const T &object) override
Object output.
virtual JObjectOutput< T > * getHelper() const =0
Get helper.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
Type list.
Definition: JTypeList.hh:23