Jpp
18.0.0-rc.3
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JLang
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
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
129
typedef
JTYPELIST<char, int, float>::typelist
typelistA;
130
typedef
JTYPELIST<char, int, float>::typelist
typelistB;
131
typedef
JTYPELIST<typelistB, int, float>::typelist
typelistC;
132
typedef
JTYPELIST<int, typelistC>::typelist
typelistD;
133
typedef
JTYPELIST<typelistA, typelistD>::typelist
typelistE;
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
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1514
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
JLANG::JConversion
Template class test for polymorphism.
Definition:
JConversion.hh:21
name
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition:
JCookie.sh:42
JLANG::JRemove
Removal of data type from type list.
Definition:
JTypeList.hh:114
JLANG::JType
Auxiliary class for a type holder.
Definition:
JType.hh:19
JLANG::JLength
Length of type list.
Definition:
JTypeList.hh:176
JTypeList.hh
JLANG::JTypeList
Type list.
Definition:
JTypeList.hh:22
JConversion.hh
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
JLANG::JTYPELIST
Auxiliary class for recursive type list generation.
Definition:
JTypeList.hh:351
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1989
JLANG::JNullType
Auxiliary class for no type definition.
Definition:
JNullType.hh:19
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JType.hh
N
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition:
JMuonPostfit.sh:36
JParser.hh
Utility class to parse command line options.
JLANG::JIndexOf
Indexing of data type in type list.
Definition:
JTypeList.hh:310
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
JLANG::JTypeAt
Extraction of data type from type list.
Definition:
JTypeList.hh:273
Generated by
1.8.5