3DiVi Face SDK  3.24.0
 Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Свойства Группы
light_shared_ptr.h
1 #ifndef __FACE_SDK__PBIO__LIGHT_SHARED_PTR_H__56133c8ad934432e86a8b16f11bb18d7
2 #define __FACE_SDK__PBIO__LIGHT_SHARED_PTR_H__56133c8ad934432e86a8b16f11bb18d7
3 
4 #include "object_with_ref_counter.h"
5 
6 #ifdef __FACE_SDK_PBIO_LIGHT_SHARED_PTR_CHECK_NULL_USE__e8dbe74d9bf04bfa9d97e90c29e858f5
7 #include "../Error.h"
8 #endif
9 
11 
12 namespace pbio
13 {
14 
15 template<typename T>
16 class light_shared_ptr
17 {
18 public:
19 
20 
21  light_shared_ptr() : ptr(NULL) {}
22 
23 
24  light_shared_ptr(const light_shared_ptr &a) : ptr(a.ptr)
25  {
26  if(ptr)
27  {
28  ptr->increment_refcounter();
29  }
30  }
31 
32 
33  ~light_shared_ptr()
34  {
35  if(ptr)
36  {
37  ptr->decrement_refcounter();
38  }
39  }
40 
41 
42  light_shared_ptr& operator=(const light_shared_ptr &a)
43  {
44  if(ptr == a.ptr)
45  {
46  return *this;
47  }
48 
49  if(ptr)
50  {
51  ptr->decrement_refcounter();
52  }
53 
54  ptr = a.ptr;
55 
56  if(ptr)
57  {
58  ptr->increment_refcounter();
59  }
60 
61  return *this;
62  }
63 
64 
65  T* get () const
66  {
67  if(ptr)
68  {
69  return &ptr->object;
70  }
71 
72  return NULL;
73  }
74 
75 
76  operator T* () const
77  {
78  return get();
79  }
80 
81  bool empty () const
82  {
83  return !ptr;
84  }
85 
86  void release ()
87  {
88  if(ptr)
89  {
90  ptr->decrement_refcounter();
91  ptr = NULL;
92  }
93  }
94 
95  T* operator -> () const
96  {
97 #ifdef __FACE_SDK_PBIO_LIGHT_SHARED_PTR_CHECK_NULL_USE__e8dbe74d9bf04bfa9d97e90c29e858f5
98  if(!ptr)
99  {
100  throw pbio::Error(0xef621abe, "Error: Ptr::operator-> called with NULL pointer stored, error code: 0xef621abe.");
101  }
102 #endif
103  return &ptr->object;
104  }
105 
106 
107  T& operator * () const
108  {
109 #ifdef __FACE_SDK_PBIO_LIGHT_SHARED_PTR_CHECK_NULL_USE__e8dbe74d9bf04bfa9d97e90c29e858f5
110  if(!ptr)
111  {
112  throw pbio::Error(0xb3fe4d07, "Error: Ptr::operator* called with NULL pointer stored, error code: 0xb3fe4d07.");
113  }
114 #endif
115  return ptr->object;
116  }
117 
118 
119  static inline light_shared_ptr make()
120  { return light_shared_ptr(new object_with_ref_counter<T>()); }
121 
122  template<typename t1>
123  static inline light_shared_ptr make(t1 a1)
124  { return light_shared_ptr(new object_with_ref_counter<T>(a1)); }
125 
126  template<typename t2, typename t1>
127  static inline light_shared_ptr make(t2 a2, t1 a1)
128  { return light_shared_ptr(new object_with_ref_counter<T>(a2, a1)); }
129 
130  template<typename t3, typename t2, typename t1>
131  static inline light_shared_ptr make(t3 a3, t2 a2, t1 a1)
132  { return light_shared_ptr(new object_with_ref_counter<T>(a3, a2, a1)); }
133 
134  template<typename t4, typename t3, typename t2, typename t1>
135  static inline light_shared_ptr make(t4 a4, t3 a3, t2 a2, t1 a1)
136  { return light_shared_ptr(new object_with_ref_counter<T>(a4, a3, a2, a1)); }
137 
138  template<typename t5, typename t4, typename t3, typename t2, typename t1>
139  static inline light_shared_ptr make(t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
140  { return light_shared_ptr(new object_with_ref_counter<T>(a5, a4, a3, a2, a1)); }
141 
142  template<typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
143  static inline light_shared_ptr make(t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
144  { return light_shared_ptr(new object_with_ref_counter<T>(a6, a5, a4, a3, a2, a1)); }
145 
146  template<typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
147  static inline light_shared_ptr make(t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
148  { return light_shared_ptr(new object_with_ref_counter<T>(a7, a6, a5, a4, a3, a2, a1)); }
149 
150  template<typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
151  static inline light_shared_ptr make(t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
152  { return light_shared_ptr(new object_with_ref_counter<T>(a8, a7, a6, a5, a4, a3, a2, a1)); }
153 
154  template<typename t9, typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
155  static inline light_shared_ptr make(t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
156  { return light_shared_ptr(new object_with_ref_counter<T>(a9, a8, a7, a6, a5, a4, a3, a2, a1)); }
157 
158  template<typename t10, typename t9, typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
159  static inline light_shared_ptr make(t10 a10, t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
160  { return light_shared_ptr(new object_with_ref_counter<T>(a10, a9, a8, a7, a6, a5, a4, a3, a2, a1)); }
161 
162  template<typename t11, typename t10, typename t9, typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
163  static inline light_shared_ptr make(t11 a11, t10 a10, t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
164  { return light_shared_ptr(new object_with_ref_counter<T>(a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1)); }
165 
166  template<typename t12, typename t11, typename t10, typename t9, typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
167  static inline light_shared_ptr make(t12 a12, t11 a11, t10 a10, t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1)
168  { return light_shared_ptr(new object_with_ref_counter<T>(a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1)); }
169 
170 private:
171 
172  light_shared_ptr(object_with_ref_counter<T>* ptr) :
173  ptr(ptr)
174  {
175  if(ptr)
176  {
177  ptr->increment_refcounter();
178  }
179  }
180 
181  object_with_ref_counter<T> *ptr;
182 
183 };
184 
185 
186 template<typename T>
187 inline
188 bool operator == (const light_shared_ptr<T> &a, const light_shared_ptr<T> &b)
189 {
190  return a.get() == b.get();
191 }
192 
193 template<typename T>
194 inline
195 bool operator != (const light_shared_ptr<T> &a, const light_shared_ptr<T> &b)
196 {
197  return a.get() != b.get();
198 }
199 
200 } // pbio namespace
201 
203 
204 #endif // __FACE_SDK__PBIO__LIGHT_SHARED_PTR_H__56133c8ad934432e86a8b16f11bb18d7
Класс исключений, выбрасываемых при возникновении ошибок.
Definition: Error.h:26