Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTypeList.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 #include <typeinfo>
5 
6 #include "JLang/JType.hh"
7 #include "JLang/JTypeList.hh"
8 #include "JLang/JConversion.hh"
9 
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 
14 namespace {
15 
16  using namespace JPP;
17 
18 
19  /**
20  * Print empty type list.
21  *
22  * \param out output stream
23  * \param typelist empty typelist
24  * \return output stream
25  */
26  std::ostream& operator<<(std::ostream& out, JType<JNullType> typelist)
27  {
28  return out;
29  }
30 
31 
32  /**
33  * Print type list.
34  *
35  * \param out output stream
36  * \param typelist typelist
37  * \return output stream
38  */
39  template<class JHead_t, class JTail_t>
40  std::ostream& operator<<(std::ostream& out, JType< JTypeList<JHead_t, JTail_t> > typelist)
41  {
42  return out << typeid(JHead_t).name() << ' ' << JType<JTail_t>();
43  }
44 }
45 
46 
47 /**
48  * \file
49  *
50  * Example program to test JLANG::JTypeList class.
51  * \author mdejong
52  */
53 int main(int argc, char **argv)
54 {
55  using namespace std;
56 
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Example program to test type lists.");
62 
63  zap['d'] = make_field(debug) = 3;
64 
65  zap(argc, argv);
66  }
67  catch(const exception &error) {
68  FATAL(error.what() << endl);
69  }
70 
71  using namespace JPP;
72 
73  typedef JTYPELIST<char,
74  short>::typelist removal;
75 
76  typedef JTYPELIST<char,
77  short,
78  int,
79  float,
80  double>::typelist typelist;
81 
82  const int N = 30;
83 
84  cout << setw(N) << left << "typelist" << JType<typelist>() << endl;
85  cout << setw(N) << left << "removal list" << JType<removal> () << endl;
86  cout << setw(N) << left << "index of char" << JIndexOf<typelist,char> ::value << endl;
87  cout << setw(N) << left << "index of float" << JIndexOf<typelist,float>::value << endl;
88 
89  cout << setw(N) << left << "typelist w/o char" << JType<JRemove<typelist, char> ::typelist>() << endl;
90  cout << setw(N) << left << "typelist w/o int" << JType<JRemove<typelist, int> ::typelist>() << endl;
91  cout << setw(N) << left << "typelist w/o removal list" << JType<JRemove<typelist, removal>::typelist>() << endl;
92  cout << setw(N) << left << "removal list w int" << JType<JAppend<removal, int> ::typelist>() << endl;
93  cout << setw(N) << left << "removal list w typelist" << JType<JAppend<removal, typelist>::typelist>() << endl;
94 
95  cout << "Length of typelist " << JLength<typelist>::value << endl;
96  cout << "Type at 0 is char " << JConversion<char, JTypeAt<typelist, 0, false>::value_type>::is_same << endl;
97  cout << "Type at 4 is double " << JConversion<double, JTypeAt<typelist, 4, false>::value_type>::is_same << endl;
98  cout << "Type at 5 is null " << JConversion<JNullType, JTypeAt<typelist, 5, false>::value_type>::is_same << endl;
99  //cout << "Type at 5 is null " << JConversion<JNullType, JTypeAt<typelist, 5, true> ::value_type>::is_same << endl;
100 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Template class test for polymorphism.
Definition: JConversion.hh:21
Auxiliary class for a type holder.
Definition: JType.hh:19
Length of type list.
Definition: JTypeList.hh:176
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:377
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
Indexing of data type in type list.
Definition: JTypeList.hh:310
int main(int argc, char *argv[])
Definition: Main.cpp:15