Jpp  19.1.0
the software that should make you happy
JObjectOutput.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JOBJECTOUTPUT__
2 #define __JLANG__JOBJECTOUTPUT__
3 
4 #include "JLang/JTypeList.hh"
5 #include "JLang/JNullType.hh"
7 #include "JLang/JAccessible.hh"
8 #include "JLang/JSingleton.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JLANG {}
16 namespace JPP { using namespace JLANG; }
17 
18 namespace JLANG {
19 
20  /**
21  * Template interface of object output for single data type.
22  */
23  template<class T>
24  class JObjectOutput {
25  protected:
26  /**
27  * Default constructor.
28  */
30  {}
31 
32 
33  public:
34  /**
35  * Virtual destructor.
36  */
37  virtual ~JObjectOutput()
38  {}
39 
40 
41  /**
42  * Object output.
43  *
44  * \param object object
45  * \return true if OK; else false
46  */
47  virtual bool put(const T& object) = 0;
48 
49 
50  /**
51  * Copy from object iterator.
52  *
53  * \param out object output
54  * \param in object iterator
55  * \return object output
56  */
59  {
60  while (in.hasNext()) {
61 
62  const T* p = in.next();
63 
64  if (p != NULL)
65  out.put(*p);
66  else
67  break;
68  }
69 
70  return out;
71  }
72  };
73 
74 
75  /**
76  * Implementation of object output for multiple data types.
77  *
78  * This class recursively defines the JObjectOutput interface
79  * for all data types by deriving from:
80  * - JObjectOutput<JHead_t>; and
81  * - JObjectOutput<JTail_t>.
82  */
83  template<class JHead_t, class JTail_t>
84  class JObjectOutput< JTypeList<JHead_t, JTail_t> > :
85  public virtual JObjectOutput<JHead_t>,
86  public virtual JObjectOutput<JTail_t>
87  {
88  public:
89 
91 
94 
95 
96  /**
97  * Copy from object iterator.
98  *
99  * Note that all data types of the output are copied from the input.
100  *
101  * \param out object output
102  * \param in object iterator
103  * \return object output
104  */
105  template<class JInputIterator_t>
106  friend inline JObjectOutput& operator<<(JObjectOutput<typelist>& out, JInputIterator_t& in)
107  {
108  static_cast<JObjectOutput<JHead_t>&>(out) << static_cast<JObjectIterator<JHead_t>&>(in);
109  static_cast<JObjectOutput<JTail_t>&>(out) << in;
110 
111  return out;
112  }
113  };
114 
115 
116  /**
117  * Terminator class of recursive JObjectOutput class.
118  */
119  template<class JHead_t>
120  class JObjectOutput< JTypeList<JHead_t, JNullType> > :
121  public virtual JObjectOutput<JHead_t>
122  {
123  public:
124 
126  };
127 
128 
129  /**
130  * Interface for object output with named access.
131  */
132  template<class T>
134  public virtual JObjectOutput<T>,
135  public virtual JAccessible
136  {};
137 
138 
139  /**
140  * Implementation of null output for single data type.
141  */
142  template<class T>
143  struct JNullOutput :
144  public JSingleton< JNullOutput<T> >,
145  public virtual JObjectOutput<T>
146  {
147  /**
148  * Object output.
149  *
150  * \param object object
151  * \return false
152  */
153  virtual bool put(const T& object) override
154  {
155  return false;
156  }
157  };
158 
159 
160  /**
161  * Implemenatation of null output for multiple data types.
162  *
163  * This class recursively implements the JLANG::JObjectOutput interface
164  * for all data types by deriving from:
165  * - JNullOutput<JHead_t>; and
166  * - JNullOutput<JTail_t>.
167  */
168  template<class JHead_t, class JTail_t>
169  struct JNullOutput< JTypeList<JHead_t, JTail_t> > :
170  public JSingleton< JTypeList<JHead_t, JTail_t> >,
171  public virtual JNullOutput<JHead_t>,
172  public virtual JNullOutput<JTail_t>
173  {};
174 
175 
176  /**
177  * Terminator class of recursive JNullOutput class.
178  */
179  template<class JHead_t>
180  struct JNullOutput< JTypeList<JHead_t, JNullType> > :
181  public virtual JNullOutput<JHead_t>
182  {};
183 
184 
185  /**
186  * Implementation for null output with null access.
187  */
188  template<class T>
190  public virtual JAccessibleObjectOutput<T>,
191  public virtual JNullOutput<T>,
192  public virtual JNullAccess
193  {};
194 }
195 
196 #endif
Interface for object output with named access.
Interface for named access of a device.
Definition: JAccessible.hh:22
Interface for null access.
Definition: JAccessible.hh:67
Interface of object iteration for a single data type.
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.
friend JObjectOutput & operator<<(JObjectOutput< typelist > &out, JInputIterator_t &in)
Copy from object iterator.
Template interface of object output for single data type.
friend JObjectOutput< T > & operator<<(JObjectOutput< T > &out, JObjectIterator< T > &in)
Copy from object iterator.
virtual bool put(const T &object)=0
Object output.
virtual ~JObjectOutput()
Virtual destructor.
JObjectOutput()
Default constructor.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Implementation for null output with null access.
Implementation of null output for single data type.
virtual bool put(const T &object) override
Object output.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
Simple singleton class.
Definition: JSingleton.hh:18
Type list.
Definition: JTypeList.hh:23