Jpp  17.2.0
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 <cmath>
#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 52 of file JMultiMap.cc.

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 
75  const double xmin = -1.0;
76  const double xmax = +1.0;
77  const double nx = 3;
78 
79  typedef JMAPLIST<JMap,
80  JMap,
81  JMap>::maplist JMaplist_t;
82 
83  typedef JMultiMap<double, double, JMaplist_t> JMultimap_t;
84 
85  JMultimap_t buffer;
86 
87  for (double x = xmin; x <= xmax; x += (xmax - xmin)/(nx - 1)) {
88  for (double y = xmin; y <= xmax; y += (xmax - xmin)/(nx - 1)) {
89  for (double z = xmin; z <= xmax; z += (xmax - xmin)/(nx - 1)) {
90  buffer[x][y][z] = f1(x, y, z);
91  }
92  }
93  }
94 
95  const JFormat_t format(6, 1, std::ios::fixed);
96 
97  setFormat< JMultiKey<3, const double> >(format);
98  setFormat< JMultiKey<2, const double> >(format);
99  setFormat< JMultiKey<1, const double> >(format);
100 
101  DEBUG("i->[second]*->(first|second)" << endl);
102 
103  for (JMultimap_t::super_const_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
104  DEBUG(""
105  << format << i->first << ' '
106  << format << i->second->first << ' '
107  << format << i->second->second->first << ' '
108  << format << i->second->second->second << endl);
109 
110  ASSERT(fabs(f1(i->first,
111  i->second->first,
112  i->second->second->first) - i->second->second->second) <= precision, "Test iterator equality");
113  }
114 
115  DEBUG("i->[second]*->(first|second)" << endl);
116 
117  for (JMultimap_t::super_const_reverse_iterator i = buffer.super_rbegin(); i != buffer.super_rend(); ++i) {
118  DEBUG(""
119  << format << i->first << ' '
120  << format << i->second->first << ' '
121  << format << i->second->second->first << ' '
122  << format << i->second->second->second << endl);
123 
124  ASSERT(fabs(f1(i->first,
125  i->second->first,
126  i->second->second->first) - i->second->second->second) <= precision, "Test iterator equality");
127  }
128 
129  DEBUG("*i.[second]*.(first|second)" << endl);
130 
131  for (JMultimap_t::super_const_reverse_iterator i = buffer.super_rbegin(); i != buffer.super_rend(); ++i) {
132  DEBUG(""
133  << format << (*i).first << ' '
134  << format << (*i).second.first << ' '
135  << format << (*i).second.second.first << ' '
136  << format << (*i).second.second.second << endl);
137 
138  ASSERT(fabs(f1(i->first,
139  i->second->first,
140  i->second->second->first) - i->second->second->second) <= precision, "Test iterator equality");
141  }
142 
143  DEBUG("i.getKey() i.getValue()" << endl);
144 
145  for (JMultimap_t::super_const_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
146 
147  DEBUG(i.getKey() << ' ' << format << i.getValue() << endl);
148 
149  ASSERT(fabs(f1(i.getKey()) - i.getValue()) <= precision, "Test iterator equality");
150  }
151 
152  return 0;
153 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1517
Map of pair-wise elements.
Definition: JMap.hh:30
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
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
#define FATAL(A)
Definition: JMessage.hh:67
const double xmin
Definition: JQuadrature.cc:23
Data structure for format specifications.
Definition: JManip.hh:522
Multidimensional map.
Definition: JMultiMap.hh:52
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
double getValue(const double x) const
Function value.
Definition: JPolynome.hh:233