Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JObjectDemultiplexer.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JOBJECTDEMULTIPLEXER__
2 #define __JLANG__JOBJECTDEMULTIPLEXER__
3 
5 #include "JLang/JObjectOutput.hh"
6 #include "JLang/JTypeList.hh"
7 #include "JLang/JNullType.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  * Auxiliary class for demultiplexing object outputs.
21  *
22  * The template argument <tt>JDerived_t</tt> refers to a list of
23  * multiple object outputs which are processed in parallel.\n
24  * The template argument <tt>JBase_t</tt> refers to a single object output
25  * which provides for a common interface to the multiple object outputs.
26  *
27  * This class implements the JLANG::JObjectOutput interface.
28  */
29  template<class JBase_t, class JDerived_t>
31  public virtual JObjectOutput<JBase_t>
32  {
33  /**
34  * Constructor.
35  *
36  * \param output object output
37  */
39  out(output)
40  {}
41 
42 
43  /**
44  * Object output.
45  *
46  * \param object object
47  * \return true if OK; else false
48  */
49  virtual bool put(const JBase_t& object) override
50  {
51  const JDerived_t* p = dynamic_cast<const JDerived_t*>(&object);
52 
53  if (p != NULL)
54  return out.put(*p);
55  else
56  return false;
57  }
58 
59 
60  /**
61  * Pipe operator.
62  *
63  * \param in object demultiplexer
64  * \param out object output
65  */
67  {
68  while (in.hasNext() && out.put(*in.next())) {}
69  }
70 
71  private:
73  };
74 
75 
76  /**
77  * Template specialisation of JObjectDemultiplexer for multiple object outputs.
78  * Implementation of object demultiplexing for multiple data types.
79  *
80  * This class recursively extends the JLANG::JObjectDemultiplexer class
81  * for all data types by deriving from:
82  * - JObjectDemultiplexer<JBase_t, JHead_t>; and
83  * - JObjectDemultiplexer<JBase_t, JTail_t>.
84  *
85  * This class implements the JLANG::JObjectOutput interface.
86  */
87  template<class JBase_t, class JHead_t, class JTail_t>
88  struct JObjectDemultiplexer<JBase_t, JTypeList<JHead_t, JTail_t> > :
89  public JObjectDemultiplexer<JBase_t, JHead_t>,
90  public JObjectDemultiplexer<JBase_t, JTail_t>,
91  public virtual JObjectOutput<JBase_t>
92  {
93  /**
94  * Constructor.
95  *
96  * \param output object output
97  */
98  template<class T>
100  JObjectDemultiplexer<JBase_t, JHead_t>(output),
101  JObjectDemultiplexer<JBase_t, JTail_t>(output)
102  {}
103 
104 
105  /**
106  * Object output.
107  *
108  * \param object object
109  * \return true if OK; else false
110  */
111  virtual bool put(const JBase_t& object) override
112  {
113  return (static_cast< JObjectDemultiplexer<JBase_t, JHead_t> >(*this).put(object) ||
114  static_cast< JObjectDemultiplexer<JBase_t, JTail_t> >(*this).put(object));
115  }
116 
117 
118  /**
119  * Pipe operator.
120  *
121  * \param in object demultiplexer
122  * \param out object output
123  */
125  {
126  while (in.hasNext() && out.put(*in.next())) {}
127  }
128  };
129 
130 
131  /**
132  * Terminator class of recursive JObjectDemultiplexer class.
133  */
134  template<class JBase_t, class JHead_t>
135  struct JObjectDemultiplexer<JBase_t, JTypeList<JHead_t, JNullType> > :
136  public JObjectDemultiplexer<JBase_t, JHead_t>
137  {
138  /**
139  * Constructor.
140  *
141  * \param output object output
142  */
144  JObjectDemultiplexer<JBase_t, JHead_t>(output)
145  {}
146  };
147 }
148 
149 #endif
friend void operator|(JObjectIterator< JBase_t > &in, JObjectDemultiplexer &out)
Pipe operator.
virtual bool put(const JBase_t &object) override
Object output.
Type list.
Definition: JTypeList.hh:22
virtual const pointer_type & next()=0
Get next element.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for no type definition.
Definition: JNullType.hh:19
virtual bool hasNext()=0
Check availability of next element.
virtual bool put(const JBase_t &object) override
Object output.
JObjectDemultiplexer(JObjectOutput< JDerived_t > &output)
Constructor.
Auxiliary class for demultiplexing object outputs.
JObjectOutput< JDerived_t > & out
Template interface of object output for single data type.
virtual bool put(const T &object)=0
Object output.
friend void operator|(JObjectIterator< JBase_t > &in, JObjectDemultiplexer &out)
Pipe operator.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41