Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JAutoMap.cc
Go to the documentation of this file.
1
2#include <iostream>
3#include <iomanip>
4#include <string>
5
6#include "JTools/JAutoMap.hh"
7
8#include "Jeep/JParser.hh"
9#include "Jeep/JMessage.hh"
10
11
12namespace {
13
14 using namespace JPP;
15
16 // type definition of map
17
18 typedef JAutoMap<int, std::string> JAutoMap_t;
19 typedef JAutoMap_t::value_type value_type;
20
21
22 using JLANG::JType;
23
24 struct JElement_t : public value_type
25 {
26 template<class T>
27 JElement_t(JType<T>);
28 };
29
30 // specialiation of constructor of auxiliary class
31
32 template<> JElement_t::JElement_t(JType<char>) : value_type(1, "char") {}
33 template<> JElement_t::JElement_t(JType<int>) : value_type(2, "int") {}
34 template<> JElement_t::JElement_t(JType<float>) : value_type(3, "float") {}
35 template<> JElement_t::JElement_t(JType<double>) : value_type(4, "double") {}
36}
37
38namespace JTOOLS {
39
40 // specialiation of member method JAutoMap_t::getAutoElement
41
42 template<> template<> value_type JAutoMap_t::getAutoElement(JType<char> ) { return value_type(1, "char"); }
43 template<> template<> value_type JAutoMap_t::getAutoElement(JType<int> ) { return value_type(2, "int"); }
44 template<> template<> value_type JAutoMap_t::getAutoElement(JType<float> ) { return value_type(3, "float"); }
45 template<> template<> value_type JAutoMap_t::getAutoElement(JType<double>) { return value_type(4, "double"); }
46}
47
48
49/**
50 * \file
51 *
52 * Example program to test JTOOLS::JAutoMap class.
53 * \author mdejong
54 */
55int main(int argc, char **argv)
56{
57 using namespace std;
58
59 int debug;
60
61 try {
62
63 JParser<> zap("Example program to test automatic generation of map based on data types.");
64
65 zap['d'] = make_field(debug) = 0;
66
67 zap(argc, argv);
68 }
69 catch(const exception &error) {
70 FATAL(error.what() << endl);
71 }
72
73
74 using namespace JPP;
75
76 typedef
77 JTypeList<int,
78 JTypeList<char,
79 JTypeList<double,
80 JTypeList<float> > > > JDataTypes_t;
81
82 {
83 JAutoMap_t zmap;
84
85 zmap.insert<JDataTypes_t>();
86
87 cout << "First method" << endl;
88
89 for (JAutoMap_t::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
90 cout << setw(2) << i->first << ' ' << i->second << endl;
91 }
92 }
93
94 {
95 JAutoMap_t zmap;
96
97 zmap.insert<JDataTypes_t>(JAutomate<JElement_t>());
98
99 cout << "Second method" << endl;
100
101 for (JAutoMap_t::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
102 cout << setw(2) << i->first << ' ' << i->second << endl;
103 }
104 }
105}
int main(int argc, char **argv)
Definition JAutoMap.cc:55
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
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
Wrapper class around std::map for automatic insertion of elements based on data types.
Definition JAutoMap.hh:93
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19
Auxiliary class for automatic element creation.
Definition JAutoMap.hh:46