Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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"
9
10#include "Jeep/JParser.hh"
11#include "Jeep/JMessage.hh"
12
13
14namespace {
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 */
53int main(int argc, char **argv)
54{
55 using namespace std;
56 using namespace JPP;
57
58 int debug;
59
60 try {
61
62 JParser<> zap("Example program to test type lists.");
63
64 zap['d'] = make_field(debug) = 3;
65
66 zap(argc, argv);
67 }
68 catch(const exception &error) {
69 FATAL(error.what() << endl);
70 }
71
72 typedef JTYPELIST<char,
73 short,
74 int,
75 float,
76 double>::typelist typelist;
77
78 typedef JTYPELIST<char,
79 short>::typelist removal;
80
81
82 const int N = 30;
83
84 DEBUG(setw(N) << left << "typelist" << (JType<typelist>()) << endl);
85 DEBUG(setw(N) << left << "removal list" << (JType<removal> ()) << endl);
86
87 DEBUG("Length of typelist " << JLength<typelist>::value << endl);
88
89 ASSERT((JLength<typelist>::value) == 5, "Test of length of type list");
90
91 DEBUG(setw(N) << left << "index of char" << (JIndexOf<typelist,char> ::value) << endl);
92 DEBUG(setw(N) << left << "index of float" << (JIndexOf<typelist,float>::value) << endl);
93 DEBUG(setw(N) << left << "index of string" << (JIndexOf<typelist,string>::value) << endl);
94
95 ASSERT((JIndexOf<typelist,char> ::value) == 0, "Test of index of char.");
96 ASSERT((JIndexOf<typelist,float> ::value) == 3, "Test of index of float.");
97 ASSERT((JIndexOf<typelist,string>::value) == -1, "Test of index of string.");
98
99 DEBUG(setw(N) << left << "typelist w/o char" << (JType<JRemove<typelist, char> ::typelist>()) << endl);
100 DEBUG(setw(N) << left << "typelist w/o int" << (JType<JRemove<typelist, int> ::typelist>()) << endl);
101
102 ASSERT((JIndexOf<JRemove<typelist, char> ::typelist,char> ::value) == -1, "Test of index of char after removal.");
103 ASSERT((JIndexOf<JRemove<typelist, float> ::typelist,float> ::value) == -1, "Test of index of float after removal.");
104
105 DEBUG(setw(N) << left << "typelist w/o removal list" << (JType<JRemove<typelist, removal>::typelist>()) << endl);
106
107 ASSERT((JLength<JRemove<typelist, removal>::typelist>::value) == 3, "Test of length of type list after removal of other type list.");
108
109 DEBUG(setw(N) << left << "removal list with int" << (JType<JAppend<removal, int> ::typelist>()) << endl);
110 DEBUG(setw(N) << left << "removal list with type list" << (JType<JAppend<removal, typelist>::typelist>()) << endl);
111
112 ASSERT((JLength<JAppend<removal, int> ::typelist>::value) == 3, "Test of length of type list after adding data type.");
113 ASSERT((JLength<JAppend<removal, typelist>::typelist>::value) == 7, "Test of length of type list after adding type list.");
114
115 DEBUG(setw(N) << left << "removal list with int" << (JType<JTYPELIST<removal, int> ::typelist>()) << endl);
116 DEBUG(setw(N) << left << "removal list with type list" << (JType<JTYPELIST<removal, typelist>::typelist>()) << endl);
117
118 ASSERT((JLength<JTYPELIST<removal, int> ::typelist>::value) == 3, "Test of length of type list after adding data type.");
119 ASSERT((JLength<JTYPELIST<removal, typelist>::typelist>::value) == 7, "Test of length of type list after adding type list.");
120
121 DEBUG("Type at 0 is char " << (JConversion<char, JTypeAt<typelist, 0, false>::value_type>::is_same ? "Y" : "N") << endl);
122 DEBUG("Type at 4 is double " << (JConversion<double, JTypeAt<typelist, 4, false>::value_type>::is_same ? "Y" : "N") << endl);
123 DEBUG("Type at 5 is null " << (JConversion<JNullType, JTypeAt<typelist, 5, false>::value_type>::is_same ? "Y" : "N") << endl);
124
125 ASSERT((JConversion<char, JTypeAt<typelist, 0, false>::value_type>::is_same), "Test of type extraction by index.");
126 ASSERT((JConversion<double, JTypeAt<typelist, 4, false>::value_type>::is_same), "Test of type extraction by index.");
127 ASSERT((JConversion<JNullType, JTypeAt<typelist, 5, false>::value_type>::is_same), "Test of type extraction by index.");
128
132 typedef JTYPELIST<int, typelistC>::typelist typelistD;
134
135 DEBUG("Type list A " << JType<typelistA>() << endl);
136 DEBUG("Type list B " << JType<typelistB>() << endl);
137 DEBUG("Type list C " << JType<typelistC>() << endl);
138 DEBUG("Type list D " << JType<typelistD>() << endl);
139 DEBUG("Type list E " << JType<typelistE>() << endl);
140
141 ASSERT((JLength<typelistA>::value) == 3, "Test of length of type list A");
142 ASSERT((JLength<typelistB>::value) == 3, "Test of length of type list B");
143 ASSERT((JLength<typelistC>::value) == 5, "Test of length of type list C");
144 ASSERT((JLength<typelistD>::value) == 6, "Test of length of type list D");
145 ASSERT((JLength<typelistE>::value) == 9, "Test of length of type list E");
146
147 return 0;
148}
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#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
int main(int argc, char **argv)
Definition JTypeList.cc:53
Utility class to parse command line options.
Definition JParser.hh:1698
std::ostream & operator<<(std::ostream &out, const JAHRSCalibration &calibration)
Write AHRS calibration to output stream.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Append to type list.
Definition JTypeList.hh:62
Template class test for polymorphism.
Indexing of data type in type list.
Definition JTypeList.hh:310
Length of type list.
Definition JTypeList.hh:176
Auxiliary class for no type definition.
Definition JNullType.hh:19
Removal of data type from type list.
Definition JTypeList.hh:114
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
Extraction of data type from type list.
Definition JTypeList.hh:273
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19