Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JMultiMap.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <cmath>
5
6#include "JTools/JMultiMap.hh"
7#include "JTools/JMap.hh"
8
9#include "JLang/JManip.hh"
10
11#include "Jeep/JParser.hh"
12#include "Jeep/JMessage.hh"
13
14namespace {
15
16 using namespace JPP;
17
18 /**
19 * Test function.
20 *
21 * \param x x
22 * \param y y
23 * \param z z
24 * \return value
25 */
26 inline double f1(const double x,
27 const double y,
28 const double z)
29 {
30 return x*100 + y*10 + z;
31 }
32
33 /**
34 * Test function.
35 *
36 * \param key key
37 * \return value
38 */
39 inline double f1(const JMultiKey<3, const double>& key)
40 {
41 return f1(key.first, key.second.first, key.second.second.first);
42 }
43}
44
45
46/**
47 * \file
48 *
49 * Example program to test JTOOLS::JMultiMap.
50 * \author mdejong
51 */
52int main(int argc, char **argv)
53{
54 using namespace std;
55 using namespace JPP;
56
57 double precision;
58 int debug;
59
60 try {
61
62 JParser<> zap("Example program to test multi-dimensional map.");
63
64 zap['e'] = make_field(precision) = 1.0e-10;
65 zap['d'] = make_field(debug) = 3;
66
67 zap(argc, argv);
68 }
69 catch(const exception &error) {
70 FATAL(error.what() << endl);
71 }
72
73
74 const double xmin = -1.0;
75 const double xmax = +1.0;
76 const double nx = 3;
77
78 typedef JMAPLIST<JMap,
79 JMap,
80 JMap>::maplist JMaplist_t;
81
82 typedef JMultiMap<double, double, JMaplist_t> JMultimap_t;
83
84 JMultimap_t buffer;
85
86 for (double x = xmin; x <= xmax; x += (xmax - xmin)/(nx - 1)) {
87 for (double y = xmin; y <= xmax; y += (xmax - xmin)/(nx - 1)) {
88 for (double z = xmin; z <= xmax; z += (xmax - xmin)/(nx - 1)) {
89 buffer[x][y][z] = f1(x, y, z);
90 }
91 }
92 }
93
94 const JFormat_t format(6, 1, std::ios::fixed);
95
99
100 DEBUG("i->[second]*->(first|second)" << endl);
101
102 for (JMultimap_t::super_const_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
103 DEBUG(""
104 << format << i->first << ' '
105 << format << i->second->first << ' '
106 << format << i->second->second->first << ' '
107 << format << i->second->second->second << endl);
108
109 ASSERT(fabs(f1(i->first,
110 i->second->first,
111 i->second->second->first) - i->second->second->second) <= precision, "Test iterator equality");
112 }
113
114 DEBUG("i->[second]*->(first|second)" << endl);
115
116 for (JMultimap_t::super_const_reverse_iterator i = buffer.super_rbegin(); i != buffer.super_rend(); ++i) {
117 DEBUG(""
118 << format << i->first << ' '
119 << format << i->second->first << ' '
120 << format << i->second->second->first << ' '
121 << format << i->second->second->second << endl);
122
123 ASSERT(fabs(f1(i->first,
124 i->second->first,
125 i->second->second->first) - i->second->second->second) <= precision, "Test iterator equality");
126 }
127
128 DEBUG("*i.[second]*.(first|second)" << endl);
129
130 for (JMultimap_t::super_const_reverse_iterator i = buffer.super_rbegin(); i != buffer.super_rend(); ++i) {
131 DEBUG(""
132 << format << (*i).first << ' '
133 << format << (*i).second.first << ' '
134 << format << (*i).second.second.first << ' '
135 << format << (*i).second.second.second << endl);
136
137 ASSERT(fabs(f1(i->first,
138 i->second->first,
139 i->second->second->first) - i->second->second->second) <= precision, "Test iterator equality");
140 }
141
142 DEBUG("i.getKey() i.getValue()" << endl);
143
144 for (JMultimap_t::super_const_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
145
146 DEBUG(i.getKey() << ' ' << format << i.getValue() << endl);
147
148 ASSERT(fabs(f1(i.getKey()) - i.getValue()) <= precision, "Test iterator equality");
149 }
150
151 return 0;
152}
I/O manipulators.
void setFormat(const JFormat_t &format)
Set format for given type.
Definition JManip.hh:714
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
int main(int argc, char **argv)
Definition JMultiMap.cc:52
General purpose multidimensional map based on a type list of maps.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
Map of pair-wise elements.
Definition JMap.hh:33
Multidimensional key.
Definition JMultiKey.hh:69
Multidimensional map.
Definition JMultiMap.hh:52
const JPolynome f1(1.0, 2.0, 3.0)
Function.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for format specifications.
Definition JManip.hh:524
double getValue(const double x) const
Function value.
Definition JMathlib.hh:1421
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109