Jpp
JObject.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JOBJECT__
2 #define __JLANG__JOBJECT__
3 
4 /**
5  * \author mdejong
6  */
7 
8 namespace JLANG {}
9 namespace JPP { using namespace JLANG; }
10 
11 namespace 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  return (data_type&) (*buffer);
34  }
35 
36 
37  /**
38  * Get clone from temporary object.
39  *
40  * \return pointer to newly created object
41  */
42  data_type* clone() const
43  {
44  return new T(static_cast<const T&>(*this));
45  }
46 
47  protected:
48  /**
49  * Default constructor.
50  */
52  {}
53 
54 
55  /**
56  * Copy constructor.
57  */
58  JObject(const JObject&)
59  {}
60 
61  private:
62  JObject& operator=(const JObject&);
63  };
64 
65 
66  /**
67  * Get static instance from temporary object.
68  *
69  * \param object object
70  * \return reference to static object
71  */
72  template<class T>
73  inline T& getInstance(const T& object)
74  {
75  static char buffer[sizeof(T)];
76 
77  new (buffer) T(object);
78 
79  return (T&) (*buffer);
80  }
81 }
82 
83 #endif
JLANG::getInstance
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:73
JLANG::JObject
Auxiliary base class for inline creation of a static value or clone from a temporary object.
Definition: JObject.hh:18
JLANG::JObject::data_type
T data_type
Definition: JObject.hh:20
JLANG::JObject::clone
data_type * clone() const
Get clone from temporary object.
Definition: JObject.hh:42
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JSTDObjectOutput
Implementation of object output for STD compatible output iterator.
Definition: JSTDObjectOutput.hh:26
JLANG::JObject::getInstance
data_type & getInstance()
Get static instance from temporary object.
Definition: JObject.hh:27
JLANG::JObject::operator=
JObject & operator=(const JObject &)
JLANG::JObject::JObject
JObject(const JObject &)
Copy constructor.
Definition: JObject.hh:58
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JObject::JObject
JObject()
Default constructor.
Definition: JObject.hh:51