Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTemplate.cc File Reference

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

#include <iostream>
#include <string>
#include <istream>
#include <ostream>
#include "JLang/JTemplate.hh"
#include "JLang/JTypeList.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::JTemplate class.

Author
mdejong

Definition in file JTemplate.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 44 of file JTemplate.cc.

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}
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
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