Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
13namespace {
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 */
44int 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.456f); // exact match
97 //object.set(123.456); // gives compiler error (argument is double)
98
99 cout << object << endl;
100 }
101
102 {
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
General purpose messaging.
#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 JTemplate.cc:44
Auxiliary class to alleviate the diamond problem due to multiple inheritance.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for managing multiple objects.
Definition JTemplate.hh:40
const T & get() const
Get reference to object.
Definition JTemplate.hh:113