Jpp  17.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JClass.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 
5 #include "JLang/JClass.hh"
6 
7 #include "Jeep/JParser.hh"
8 #include "Jeep/JMessage.hh"
9 
10 
11 namespace {
12 
13  struct __A__ {};
14 
15  /**
16  * Print class parameters.
17  *
18  * \param out output stream
19  * \param name name of class
20  */
21  template<class T>
22  inline void print(std::ostream& out, const char* name)
23  {
24  using namespace std;
25  using namespace JPP;
26 
27  out << setw(36) << left << name;
28  out << setw(4) << '.' << setw(8) << left << JClass<T>::is_primitive;
29  out << setw(4) << '.' << setw(8) << left << JClass<T>::is_pointer;
30  out << setw(4) << '.' << setw(8) << left << JClass<T>::is_reference;
31  out << setw(4) << '.' << setw(8) << left << JClass<T>::is_constant;
32  out << endl;
33  }
34 }
35 
36 
37 /**
38  * Print class parameters.
39  *
40  * \param OUT output stream
41  * \param T class
42  */
43 #define PRINT(OUT, T) print<T>(OUT, #T)
44 
45 
46 /**
47  * \file
48  *
49  * Example program to test JLANG::JClass class.
50  * \author mdejong
51  */
52 int main(int argc, char **argv)
53 {
54  using namespace std;
55  using namespace JPP;
56 
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Example program to test class inspection.");
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  if (debug >= debug_t) {
72 
73  cout << setw(36) << left << "name";
74  cout << setw(12) << "primitive";
75  cout << setw(12) << " pointer";
76  cout << setw(12) << "reference";
77  cout << setw(12) << "constant";
78  cout << endl;
79 
80  cout << setfill('.');
81 
82  PRINT(cout, int);
83  PRINT(cout, int&);
84  PRINT(cout, const int*);
85  PRINT(cout, __A__);
86 
89  }
90 
91  ASSERT( JClass<int>::is_primitive);
92  ASSERT(!JClass<int>::is_pointer);
93  ASSERT(!JClass<int>::is_reference);
94  ASSERT(!JClass<int>::is_constant);
95 
96  ASSERT( JClass<int&>::is_primitive);
97  ASSERT(!JClass<int&>::is_pointer);
98  ASSERT( JClass<int&>::is_reference);
99  ASSERT(!JClass<int&>::is_constant);
100 
101  ASSERT( JClass<const int*>::is_primitive);
102  ASSERT( JClass<const int*>::is_pointer);
103  ASSERT(!JClass<const int*>::is_reference);
104  ASSERT( JClass<const int*>::is_constant);
105 
106  ASSERT(!JClass<__A__>::is_primitive);
107  ASSERT(!JClass<__A__>::is_pointer);
108  ASSERT(!JClass<__A__>::is_reference);
109  ASSERT(!JClass<__A__>::is_constant);
110 
111  ASSERT(!JClass<JClass<int> ::argument_type>::is_reference);
112  ASSERT( JClass<JClass<__A__>::argument_type>::is_reference);
113 
114  ASSERT(is_iterator<__A__> ::value == false);
115  ASSERT(is_iterator<__A__&>::value == false);
116  ASSERT(is_iterator<__A__*>::value == true);
117 
118  ASSERT(is_iterator<vector<__A__>::iterator>::value == true);
119  ASSERT(is_iterator<vector<__A__>::const_iterator>::value == true);
120  ASSERT(is_iterator<vector<__A__>::reverse_iterator>::value == true);
121  ASSERT(is_iterator<vector<__A__>::const_reverse_iterator>::value == true);
122 
123  return 0;
124 }
Utility class to parse command line options.
Definition: JParser.hh:1517
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
int debug
debug level
#define PRINT(OUT, T)
Print class parameters.
Definition: JClass.cc:43