Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JHashMap.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JTools/JHashMap.hh"
7 
8 #include "Jeep/JParser.hh"
9 #include "Jeep/JMessage.hh"
10 
11 
12 
13 /**
14  * \file
15  *
16  * Example program to test JTOOLS::JHashMap class.
17  * \author mdejong
18  */
19 int main(int argc, char **argv)
20 {
21  using namespace std;
22 
23  int debug;
24 
25  try {
26 
27  JParser<> zap("Example program to test hash map.");
28 
29  zap['d'] = make_field(debug) = 0;
30 
31  zap(argc, argv);
32  }
33  catch(const exception &error) {
34  FATAL(error.what() << endl);
35  }
36 
37 
38  using namespace JPP;
39 
40  typedef JTYPELIST<int, int, int>::typelist typelist;
41 
42  typedef JTuple <typelist> key_type;
43  typedef JHashMap<typelist, string> hash_map;
44 
45  hash_map buffer;
46 
47  buffer[1][1][3] = "mies";
48  buffer[2][1][2] = "noot";
49  buffer[3][1][1] = "aap";
50 
51  key_type key(2, 4, 6);
52 
53  buffer.put(key, "hello world");
54 
55  cout << "Has " << key << " ? " << buffer.has(key) << endl;
56 
57 
58  for (hash_map::super_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
59  i.getValue() += '!';
60  }
61 
62  for (hash_map::const_iterator i0 = buffer.begin(); i0 != buffer.end(); ++i0) {
63  for (hash_map::mapped_type::const_iterator i1 = i0->second.begin(); i1 != i0->second.end(); ++i1) {
64  for (hash_map::mapped_type::mapped_type::const_iterator i2 = i1->second.begin(); i2 != i1->second.end(); ++i2) {
65  cout << i0->first << ' ' << i1->first << ' ' << i2->first << ' ' << i2->second << endl;
66  }
67  }
68  }
69 
70  for (hash_map::super_const_iterator i = buffer.super_begin(); i != buffer.super_end(); ++i) {
71  cout << i.getKey() << ' ' << i.getValue() << endl;
72  }
73 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General purpose class for multidimensional hash maps.
int main(int argc, char *argv[])
Definition: Main.cc:15
General purpose class for hash map of unique elements.
Type list.
Definition: JTypeList.hh:22
#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.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.