Jpp
pmt_effective_area_update
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
JTemplate.cc
Go to the documentation of this file.
1
#include <iostream>
2
#include <string>
3
4
#include <istream>
5
#include <ostream>
6
7
#include "
JLang/JTemplate.hh
"
8
#include "
JLang/JTypeList.hh
"
9
#include "
Jeep/JParser.hh
"
10
#include "
Jeep/JMessage.hh
"
11
12
13
namespace
{
14
15
struct
__A__ :
16
public
std::string
17
{
18
__A__() {}
19
__A__(
const
char
* buffer) : std::string(buffer) {}
20
};
21
22
struct
__B__ :
23
public
__A__
24
{
25
__B__() {}
26
__B__(
const
char
* buffer) : __A__(buffer) {}
27
};
28
29
struct
__C__ :
30
public
__B__
31
{
32
__C__() {}
33
__C__(
const
char
* buffer) : __B__(buffer) {}
34
};
35
}
36
37
38
/**
39
* \file
40
*
41
* Example program to test JLANG::JTemplate class.
42
* \author mdejong
43
*/
44
int
main
(
int
argc,
char
**argv)
45
{
46
using namespace
std;
47
48
int
debug
;
49
50
try
{
51
52
JParser<>
zap(
"Example program to test object referencing."
);
53
54
zap[
'd'
] =
make_field
(
debug
) = 3;
55
56
zap(argc, argv);
57
}
58
catch
(
const
exception &error) {
59
FATAL
(error.what() << endl);
60
}
61
62
using namespace
JPP;
63
64
65
{
66
JTemplate<string> object;
67
68
object
= string(
"aap"
);
69
70
object
.set(
string
(
"noot"
));
// exact match
71
object
.set(
"mies"
);
// implicit cast through std::string
72
73
object
.get<
string
>() +=
" says "
;
// exact match
74
//object.get<int>(); // gives compiler error
75
76
object
->append(
"\"hello world\""
);
// smart pointer
77
78
cout <<
object
<< endl;
79
}
80
81
{
82
class
JTemplate_t :
83
public
JTemplate<JTYPELIST<std::string, float, int>::typelist>
84
{};
85
86
JTemplate_t object;
87
88
object
.get<
string
>() =
"abc"
;
// exact match
89
object
.get<
int
>() = -1;
// exact match
90
object
.get<
float
>() = -0.99;
// exact match
91
92
//object.set("hello world"); // gives compiler error
93
object
.set(
string
(
"aap noot mies"
));
// exact match
94
object
.set<
true
>(
"hello world"
);
// allow cast
95
object
.set(777);
// exact match
96
object
.set(123.456
f
);
// exact match
97
//object.set(123.456); // gives compiler error (argument is double)
98
99
cout <<
object
<< endl;
100
}
101
102
{
103
JTemplate<JTYPELIST<__C__, __B__, __A__>::typelist> object;
104
105
object
.get<__A__>() =
"a"
;
// exact match
106
object
.get<__B__>() =
"b"
;
// exact match
107
object
.get<__C__>() =
"c"
;
// exact match
108
109
cout <<
object
.get<__C__>()
// exact match
110
<<
" == "
111
<<
object
.get<__A__, true>()
// first match
112
<< endl;
113
}
114
}
115
116
117
118
119
120
121
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1500
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
f
then JPizza f
Definition:
JPizza.sh:46
JTypeList.hh
JTemplate.hh
Auxiliary class to alleviate the so-called diamond problem due to multiple inheritance.
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1961
debug
int debug
debug level
Definition:
JSirene.cc:63
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
Generated by
1.8.5