Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JTypeList.cc File Reference

Example program to test JLANG::JTypeList class. More...

#include <iostream>
#include <iomanip>
#include <typeinfo>
#include "JLang/JType.hh"
#include "JLang/JTypeList.hh"
#include "JLang/JConversion.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JLANG::JTypeList class.

Author
mdejong

Definition in file JTypeList.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 53 of file JTypeList.cc.

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;
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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
Removal of data type from type list.
Definition: JTypeList.hh:114
Auxiliary class for a type holder.
Definition: JType.hh:19
Length of type list.
Definition: JTypeList.hh:176
Type list.
Definition: JTypeList.hh:22
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Template class test for polymorphism.
Definition: JConversion.hh:22
Auxiliary class for no type definition.
Definition: JNullType.hh:19
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
Indexing of data type in type list.
Definition: JTypeList.hh:310
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Extraction of data type from type list.
Definition: JTypeList.hh:273