Jpp
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 
12 namespace {
13 
14  using namespace JPP;
15 
16  typedef JAutoMap<int, std::string> JAutoMap_t;
17  typedef JAutoMap_t::value_type value_type;
18 
19 
20  using namespace JPP;
21 
22  struct JElement_t : public value_type
23  {
24  template<class T>
25  JElement_t(JType<T>);
26  };
27 
28 
29  template<> JElement_t::JElement_t(JType<char>) : value_type(1, "char") {}
30  template<> JElement_t::JElement_t(JType<int>) : value_type(2, "int") {}
31  template<> JElement_t::JElement_t(JType<float>) : value_type(3, "float") {}
32  template<> JElement_t::JElement_t(JType<double>) : value_type(4, "double") {}
33 }
34 
35 namespace JTOOLS {
36 
37  template<> template<> value_type JAutoMap_t::getAutoElement(JType<char> ) { return value_type(1, "char"); }
38  template<> template<> value_type JAutoMap_t::getAutoElement(JType<int> ) { return value_type(2, "int"); }
39  template<> template<> value_type JAutoMap_t::getAutoElement(JType<float> ) { return value_type(3, "float"); }
40  template<> template<> value_type JAutoMap_t::getAutoElement(JType<double>) { return value_type(4, "double"); }
41 }
42 
43 
44 
45 /**
46  * \file
47  *
48  * Example program to test JTOOLS::JAutoMap class.
49  * \author mdejong
50  */
51 int main(int argc, char **argv)
52 {
53  using namespace std;
54 
55  int debug;
56 
57  try {
58 
59  JParser<> zap("Example program to test automatic generation of map based on data types.");
60 
61  zap['d'] = make_field(debug) = 0;
62 
63  zap(argc, argv);
64  }
65  catch(const exception &error) {
66  FATAL(error.what() << endl);
67  }
68 
69 
70  using namespace JPP;
71 
72  typedef
73  JTypeList<int,
74  JTypeList<char,
75  JTypeList<double,
76  JTypeList<float> > > > JDataTypes_t;
77 
78  {
79  JAutoMap_t zmap;
80 
81  zmap.insert<JDataTypes_t>();
82 
83  for (JAutoMap_t::const_iterator i = zmap.begin(); i != zmap.end(); ++i)
84  cout << setw(2) << i->first << ' ' << i->second << endl;
85  }
86 
87  {
88  JAutoMap_t zmap;
89 
90  zmap.insert<JDataTypes_t>(JAutomate<JElement_t>());
91 
92  for (JAutoMap_t::const_iterator i = zmap.begin(); i != zmap.end(); ++i)
93  cout << setw(2) << i->first << ' ' << i->second << endl;
94  }
95 }
JLANG::JType
Auxiliary class for a type holder.
Definition: JType.hh:19
JMessage.hh
JTOOLS::JAutoMap
Forward declaration of class JAutoMap for specialisation of class JAutomate.
Definition: JAutoMap.hh:29
main
int main(int argc, char **argv)
Definition: JAutoMap.cc:51
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JLANG::JTypeList
Type list.
Definition: JTypeList.hh:22
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
JTOOLS::JAutomate
Auxiliary class for automatic element creation.
Definition: JAutoMap.hh:40
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JAutoMap.hh