Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JObject.hh
Go to the documentation of this file.
1#ifndef __JLANG__JOBJECT__
2#define __JLANG__JOBJECT__
3
4/**
5 * \author mdejong
6 */
7
8namespace JLANG {}
9namespace JPP { using namespace JLANG; }
10
11namespace JLANG {
12
13
14 /**
15 * Auxiliary base class for inline creation of a static value or clone from a temporary object.
16 */
17 template<class T>
18 struct JObject {
19
20 typedef T data_type;
21
22 /**
23 * Get static instance from temporary object.
24 *
25 * \return reference to static object
26 */
28 {
29 static char buffer[sizeof(T)];
30
31 new (buffer) T(static_cast<const T&>(*this));
32
33 T* p = reinterpret_cast<data_type*>(buffer);
34
35 return *p;
36 }
37
38
39 /**
40 * Get clone from temporary object.
41 *
42 * \return pointer to newly created object
43 */
44 data_type* clone() const
45 {
46 return new T(static_cast<const T&>(*this));
47 }
48
49 protected:
50 /**
51 * Default constructor.
52 */
54 {}
55
56
57 /**
58 * Copy constructor.
59 */
61 {}
62
63 private:
65 };
66
67
68 /**
69 * Get static instance from temporary object.
70 *
71 * \param object object
72 * \return reference to static object
73 */
74 template<class T>
75 inline T& getInstance(const T& object)
76 {
77 static char buffer[sizeof(T)];
78
79 new (buffer) T(object);
80
81 T* p = reinterpret_cast<T*>(buffer);
82
83 return *p;
84 }
85}
86
87#endif
Auxiliary classes and methods for language specific functionality.
T & getInstance(const T &object)
Get static instance from temporary object.
Definition JObject.hh:75
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary base class for inline creation of a static value or clone from a temporary object.
Definition JObject.hh:18
data_type & getInstance()
Get static instance from temporary object.
Definition JObject.hh:27
JObject(const JObject &)
Copy constructor.
Definition JObject.hh:60
JObject & operator=(const JObject &)
JObject()
Default constructor.
Definition JObject.hh:53
data_type * clone() const
Get clone from temporary object.
Definition JObject.hh:44