Jpp  17.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCollection.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JTools/JCollection.hh"
6 #include "JTools/JElement.hh"
7 
8 #include "Jeep/JParser.hh"
9 #include "Jeep/JMessage.hh"
10 
11 
12 namespace {
13 
14  /**
15  * Function.
16  *
17  * \param i abscissa value
18  * \return function value
19  */
20  inline int f1(const int i)
21  {
22  return i*1000;
23  }
24 }
25 
26 
27 /**
28  * \file
29  *
30  * Example program to test JTOOLS::JCollection class.
31  * \author mdejong
32  */
33 int main(int argc, char **argv)
34 {
35  using namespace std;
36  using namespace JPP;
37 
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Example program to test collection class.");
43 
44  zap['d'] = make_field(debug) = 3;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52  {
53  typedef JElement2D<int, int> JElement_t;
54  typedef JCollection<JElement_t> JCollection_t;
55 
56  JCollection_t a;
57  JCollection_t b;
58  JCollection_t c;
59 
60  for (int i = 0; i != 5; ++i) {
61  a.put(i, 10 + i);
62  b.put(i, 100 + i);
63  }
64 
65  //b.put(10,10); // throws error at 'a + b' as should be
66 
67  try {
68  c = a + b;
69  c += 1000;
70  c *= 2;
71  c += f1;
72  }
73  catch(const JException& error) {
74  FATAL(error.what() << endl);
75  }
76 
77  for (JCollection_t::const_iterator i = a.begin(), j = b.begin(), k = c.begin(); i != a.end() && j != b.end() && k != c.end(); ++i, ++j, ++k) {
78  DEBUG(setw(4) << k->getY() << " == " << setw(4) << (i->getY() + j->getY() + 1000) * 2 + f1(i->getX()) << endl);
79  ASSERT(k->getY() == (i->getY() + j->getY() + 1000) * 2 + f1(i->getX()));
80  }
81  }
82 
83  {
84  JDistance<double>::precision = 1.0e-10;
85 
86  typedef JElement2D<int, int> JElement_t;
87  typedef JCollection<JElement_t> JCollection_t;
88 
89  JCollection_t a;
90  JCollection_t b;
91  JCollection_t c;
92 
93  a.put(0.0, 0.0);
94  a.put(1.0, 1.0);
95  a.put(2.0, 2.0);
96 
97  b.put(1.0, 1.0);
98  b.put(2.0, 2.0);
99  b.put(3.0, 3.0);
100 
101  c = a + b;
102 
103  ASSERT(c.getY(0) == 0.0);
104  ASSERT(c.getY(1) == 2.0);
105  ASSERT(c.getY(2) == 4.0);
106  ASSERT(c.getY(3) == 3.0);
107  }
108 
109  return 0;
110 }
Utility class to parse command line options.
Definition: JParser.hh:1517
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
int main(int argc, char *argv[])
Definition: Main.cc:15
The elements in a collection are sorted according to their abscissa values and a given distance opera...
const JPolynome f1(1.0, 2.0, 3.0)
Function.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
General purpose class for a collection of sorted elements.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then JCalibrateToT a
Definition: JTuneHV.sh:116
Utility class to parse command line options.
int j
Definition: JPolint.hh:703
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62