Jpp  15.0.3
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  * Constructor.
20  *
21  * \param i value
22  */
23  __A__(const int i) :
24  i(i)
25  {}
26 
27 
28  /**
29  * Get name.
30  *
31  * \return name
32  */
33  virtual const char* getName() const
34  {
35  return "a";
36  }
37 
38 
39  /**
40  * Equal operator.
41  *
42  * \param first first object
43  * \param second second object
44  * \return true if first and second object are equal; else false
45  */
46  friend inline bool operator==(const __A__& first, const __A__& second)
47  {
48  return first.i == second.i;
49  }
50 
51 
52  /**
53  * Write object to output stream.
54  *
55  * \param out output stream
56  * \param object object
57  * \return output stream
58  */
59  friend inline std::ostream& operator<<(std::ostream& out, const __A__& object)
60  {
61  return out << object.getName() << object.i;
62  }
63 
64  int i;
65  };
66 
67 
68  struct __B__ :
69  public __A__
70  {
71  /**
72  * Constructor.
73  *
74  * \param i value
75  */
76  __B__(const int i) :
77  __A__(i)
78  {}
79 
80 
81  /**
82  * Get name.
83  *
84  * \return name
85  */
86  virtual const char* getName() const
87  {
88  return "b";
89  }
90  };
91 }
92 
93 
94 /**
95  * \file
96  *
97  * Example program to test JLANG::JObjectMultiplexer and JLANG::JObjectDemultiplexer classes.
98  * \author mdejong
99  */
100 int main(int argc, char **argv)
101 {
102  using namespace std;
103 
104  int debug;
105 
106  try {
107 
108  JParser<> zap("Example program to test object multiplexing and demultiplexing.");
109 
110  zap['d'] = make_field(debug) = 3;
111 
112  zap(argc, argv);
113  }
114  catch(const exception &error) {
115  FATAL(error.what() << endl);
116  }
117 
118 
119  using namespace JPP;
120 
121  vector<__A__> a_in;
122  vector<__B__> b_in;
123 
124  for (int i = 1; i != 4; ++i) {
125  a_in.push_back(i);
126  b_in.push_back(i);
127  }
128 
129  if (debug >= debug_t) {
130  cout << "a_in "; copy(a_in.begin(), a_in.end(), ostream_iterator<__A__>(cout, " ")); cout << endl;
131  cout << "b_in "; copy(b_in.begin(), b_in.end(), ostream_iterator<__B__>(cout, " ")); cout << endl;
132  }
133 
134 
135  typedef JTYPELIST<__B__, __A__>::typelist typelist; // make sure base class is at end
136 
137  JSTDObjectReader<typelist> in;
138 
139  in.set(a_in);
140  in.set(b_in);
141 
142 
143  JSTDObjectWriter<typelist> out;
144 
145  vector<__A__> a_out;
146  vector<__B__> b_out;
147 
148  out.set(a_out);
149  out.set(b_out);
150 
151 
152  JObjectMultiplexer<typelist> multiplexer (in);
153 
154  JObjectDemultiplexer<__A__, typelist> demultiplexer(out);
155 
156 
157  multiplexer >> demultiplexer;
158 
159  if (debug >= debug_t) {
160  cout << "a_out "; copy(a_out.begin(), a_out.end(), ostream_iterator<__A__>(cout, " ")); cout << endl;
161  cout << "b_out "; copy(b_out.begin(), b_out.end(), ostream_iterator<__B__>(cout, " ")); cout << endl;
162  }
163 
164  ASSERT(a_in == a_out);
165  ASSERT(b_in == b_out);
166 
167  return 0;
168 }
Utility class to parse command line options.
Definition: JParser.hh:1500
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:1961
int debug
debug level
Definition: JSirene.cc:63
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:139
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:57
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:42