Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMultiMap.cc File Reference

Example program to test JTOOLS::JMultiMap. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JTools/JMultiMap.hh"
#include "JTools/JMap.hh"
#include "JLang/JManip.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JTOOLS::JMultiMap.

Author
mdejong

Definition in file JMultiMap.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file JMultiMap.cc.

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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for format specifications.
Definition: JManip.hh:522