Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JClonable.cc
Go to the documentation of this file.
1
2#include <iostream>
3#include <iomanip>
4
5#include "JLang/JClonable.hh"
6
7#include "Jeep/JParser.hh"
8#include "Jeep/JMessage.hh"
9
10
11namespace {
12
13 using namespace JPP;
14
15
16 struct __A__ :
17 public JClonable<__A__>
18 {
19 virtual ~__A__()
20 {}
21
22 virtual int get() const = 0;
23 };
24
25 struct __B__ :
26 public JClonable<__A__, __B__>
27 {
28 static const int value = 1;
29
30 virtual int get() const
31 {
32 return __B__::value;
33 }
34 };
35
36 struct __C__ :
37 public JClonable<__A__, __C__>
38 {
39 static const int value = 2;
40
41 virtual int get() const
42 {
43 return __C__::value;
44 }
45 };
46}
47
48/**
49 * \file
50 *
51 * Example program to test JLANG::JClonable class.
52 * \author mdejong
53 */
54int main(int argc, char **argv)
55{
56 using namespace std;
57 using namespace JPP;
58
59 int debug;
60
61 try {
62
63 JParser<> zap("Example program to test object cloning.");
64
65 zap['d'] = make_field(debug) = 3;
66
67 zap(argc, argv);
68 }
69 catch(const exception &error) {
70 FATAL(error.what() << endl);
71 }
72
73 __B__ b;
74 __C__ c;
75
76 {
77 __A__* p = b.clone();
78
79 ASSERT(p->get() == __B__::value);
80
81 delete p;
82 }
83
84 {
85 __A__* p = c.clone();
86
87 ASSERT(p->get() == __C__::value);
88
89 delete p;
90 }
91
92 return 0;
93}
int main(int argc, char **argv)
Definition JClonable.cc:54
General purpose messaging.
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#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
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template class for object cloning.
Definition JClonable.hh:59