Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
11 namespace {
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  */
54 int 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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Template class for object cloning.
Definition: JClonable.hh:20
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.