Jpp  16.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMultiMap.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JTools/JMultiMap.hh"
6 #include "JTools/JMap.hh"
7 
8 #include "JLang/JManip.hh"
9 
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 
14 /**
15  * \file
16  *
17  * Example program to test JTOOLS::JMultiMap.
18  * \author mdejong
19  */
20 int main(int argc, char **argv)
21 {
22  using namespace std;
23 
24  int debug;
25 
26  try {
27 
28  JParser<> zap("Example program to test multi-dimensional map.");
29 
30  zap['d'] = make_field(debug) = 3;
31 
32  zap(argc, argv);
33  }
34  catch(const exception &error) {
35  FATAL(error.what() << endl);
36  }
37 
38 
39  using namespace JPP;
40 
41  const double xmin = -1.0;
42  const double xmax = +1.0;
43  const double nx = 3;
44 
45  typedef JMAPLIST<JMap,
46  JMap,
47  JMap>::maplist JMaplist_t;
48 
49  typedef JMultiMap<double, double, JMaplist_t> JMultimap_t;
50 
51  JMultimap_t buffer;
52 
53  for (double x = xmin; x <= xmax; x += (xmax - xmin)/(nx - 1)) {
54  for (double y = xmin; y <= xmax; y += (xmax - xmin)/(nx - 1)) {
55  for (double z = xmin; z <= xmax; z += (xmax - xmin)/(nx - 1)) {
56  buffer[x][y][z] = x*100 + y*10 + z;
57  }
58  }
59  }
60 
61  const JFormat_t format(6, 1, std::ios::fixed);
62 
63  setFormat< JMultiKey<3, const double> >(format);
64  setFormat< JMultiKey<2, const double> >(format);
65  setFormat< JMultiKey<1, const double> >(format);
66 
67  cout << "i->[second]*->(first|second)" << endl;
68 
69  for (JMultimap_t::super_const_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
70  cout << format << i->first << ' '
71  << format << i->second->first << ' '
72  << format << i->second->second->first << ' '
73  << format << i->second->second->second << endl;
74  }
75 
76  cout << "i.getKey() i.getValue()" << endl;
77 
78  for (JMultimap_t::super_const_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
79  cout << i.getKey() << ' ' << format << i.getValue() << endl;
80  }
81 }
Utility class to parse command line options.
Definition: JParser.hh:1500
JMultiMap is a general purpose multidimensional map based on a type list of maps. ...
int main(int argc, char *argv[])
Definition: Main.cc:15
#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.
I/O manipulators.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
Data structure for format specifications.
Definition: JManip.hh:522