Jpp  15.0.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  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  */
60  JObject(const JObject&)
61  {}
62 
63  private:
64  JObject& operator=(const JObject&);
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
data_type * clone() const
Get clone from temporary object.
Definition: JObject.hh:44
JObject()
Default constructor.
Definition: JObject.hh:53
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
JObject(const JObject &)
Copy constructor.
Definition: JObject.hh:60
do set_variable OUTPUT_DIRECTORY $WORKDIR T
data_type & getInstance()
Get static instance from temporary object.
Definition: JObject.hh:27
Auxiliary base class for inline creation of a static value or clone from a temporary object...
Definition: JObject.hh:18
Implementation of object output for STD compatible output iterator.
JObject & operator=(const JObject &)