Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
JClonable.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JCLONABLE__
2 #define __JLANG__JCLONABLE__
3 
4 #include "JLang/JNullType.hh"
5 
6 /**
7  * \author mdejong
8  */
9 
10 namespace JLANG {}
11 namespace JPP { using namespace JLANG; }
12 
13 namespace JLANG {
14 
15 
16  /**
17  * Template class for object cloning.
18  */
19  template<class JClonable_t, class JDerived_t = JNullType>
20  struct JClonable;
21 
22 
23  /**
24  * Template specialisation to define base class for interface of object cloning.
25  */
26  template<class JClonable_t>
27  struct JClonable<JClonable_t, JNullType>
28  {
29  /**
30  * Type definition of return value of method clone().
31  */
32  typedef JClonable_t* clone_type;
33 
34 
35  /**
36  * Virtual destructor.
37  */
38  virtual ~JClonable()
39  {}
40 
41 
42  /**
43  * Get clone of this object.
44  *
45  * \return pointer to newly created object
46  */
47  virtual clone_type clone() const = 0;
48  };
49 
50 
51  /**
52  * Template specialisation to define base class for implementation of object cloning.
53  *
54  * This class derives from the specified clonable class and implements the method clone.
55  */
56  template<class JClonable_t, class JDerived_t>
57  struct JClonable :
58  public JClonable_t
59  {
60 
62 
63 
64  /**
65  * Get clone of this object.
66  *
67  * \return pointer to newly created object
68  */
69  virtual clone_type clone() const override
70  {
71  return new JDerived_t(static_cast<const JDerived_t&>(*this));
72  }
73  };
74 }
75 
76 
77 #endif
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
virtual clone_type clone() const =0
Get clone of this object.
JClonable_t * clone_type
Type definition of return value of method clone().
Definition: JClonable.hh:32
virtual ~JClonable()
Virtual destructor.
Definition: JClonable.hh:38
Template class for object cloning.
Definition: JClonable.hh:59
JClonable< JClonable_t >::clone_type clone_type
Definition: JClonable.hh:61
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
Auxiliary class for no type definition.
Definition: JNullType.hh:19