Jpp  18.2.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JObjectDemultiplexer.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 
11 
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 
15 namespace {
16 
17  struct __A__ {
18  /**
19  * Virtual destructor.
20  */
21  virtual ~__A__()
22  {}
23 
24 
25  /**
26  * Constructor.
27  *
28  * \param i value
29  */
30  __A__(const int i) :
31  i(i)
32  {}
33 
34 
35  /**
36  * Get name.
37  *
38  * \return name
39  */
40  virtual const char* getName() const
41  {
42  return "a";
43  }
44 
45 
46  /**
47  * Equal operator.
48  *
49  * \param first first object
50  * \param second second object
51  * \return true if first and second object are equal; else false
52  */
53  friend inline bool operator==(const __A__& first, const __A__& second)
54  {
55  return first.i == second.i;
56  }
57 
58 
59  /**
60  * Write object to output stream.
61  *
62  * \param out output stream
63  * \param object object
64  * \return output stream
65  */
66  friend inline std::ostream& operator<<(std::ostream& out, const __A__& object)
67  {
68  return out << object.getName() << object.i;
69  }
70 
71  int i;
72  };
73 
74 
75  struct __B__ :
76  public __A__
77  {
78  /**
79  * Constructor.
80  *
81  * \param i value
82  */
83  __B__(const int i) :
84  __A__(i)
85  {}
86 
87 
88  /**
89  * Get name.
90  *
91  * \return name
92  */
93  virtual const char* getName() const
94  {
95  return "b";
96  }
97  };
98 }
99 
100 
101 /**
102  * \file
103  *
104  * Example program to test JLANG::JObjectMultiplexer and JLANG::JObjectDemultiplexer classes.
105  * \author mdejong
106  */
107 int main(int argc, char **argv)
108 {
109  using namespace std;
110 
111  int debug;
112 
113  try {
114 
115  JParser<> zap("Example program to test object multiplexing and demultiplexing.");
116 
117  zap['d'] = make_field(debug) = 3;
118 
119  zap(argc, argv);
120  }
121  catch(const exception &error) {
122  FATAL(error.what() << endl);
123  }
124 
125 
126  using namespace JPP;
127 
128  vector<__A__> a_in;
129  vector<__B__> b_in;
130 
131  for (int i = 1; i != 4; ++i) {
132  a_in.push_back(i);
133  b_in.push_back(i);
134  }
135 
136  if (debug >= debug_t) {
137  cout << "a_in "; copy(a_in.begin(), a_in.end(), ostream_iterator<__A__>(cout, " ")); cout << endl;
138  cout << "b_in "; copy(b_in.begin(), b_in.end(), ostream_iterator<__B__>(cout, " ")); cout << endl;
139  }
140 
141 
142  typedef JTYPELIST<__B__, __A__>::typelist typelist; // make sure base class is at end
143 
144  JSTDObjectReader<typelist> in;
145 
146  in.set(a_in);
147  in.set(b_in);
148 
149 
150  JSTDObjectWriter<typelist> out;
151 
152  vector<__A__> a_out;
153  vector<__B__> b_out;
154 
155  out.set(a_out);
156  out.set(b_out);
157 
158 
159  JObjectMultiplexer<typelist> multiplexer (in);
160 
161  JObjectDemultiplexer<__A__, typelist> demultiplexer(out);
162 
163 
164  multiplexer >> demultiplexer;
165 
166  if (debug >= debug_t) {
167  cout << "a_out "; copy(a_out.begin(), a_out.end(), ostream_iterator<__A__>(cout, " ")); cout << endl;
168  cout << "b_out "; copy(b_out.begin(), b_out.end(), ostream_iterator<__B__>(cout, " ")); cout << endl;
169  }
170 
171  ASSERT(a_in == a_out);
172  ASSERT(b_in == b_out);
173 
174  return 0;
175 }
Utility class to parse command line options.
Definition: JParser.hh:1514
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Type list.
Definition: JTypeList.hh:22
bool operator==(Packet const &p, ID const &id)
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:60
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level