3DiVi Face SDK  3.24.2
 Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Свойства Группы
object_with_ref_counter.h
1 #ifndef __FACE_SDK__PBIO__OBJECT_WITH_REF_COUNTER_H__2a81343862d047159b41d58bfe5e730b
2 #define __FACE_SDK__PBIO__OBJECT_WITH_REF_COUNTER_H__2a81343862d047159b41d58bfe5e730b
3 
4 #include "atomic_exchange_add.h"
5 
7 
8 namespace pbio
9 {
10 
11 template<typename T>
12 class object_with_ref_counter
13 {
14 public:
15 
16  T object;
17 
18 #ifdef __FACE_SDK_PBIO_LIGHT_SHARED_PTR_NEED_REFCOUNTER__d213e87df35b4d47af0999a1192bce7d
19 
20  int32_t refcounter_field;
21 
22  inline
23  int32_t& refcounter()
24  {
25  return refcounter_field;
26  }
27 #else
28 
29  inline
30  int32_t& refcounter()
31  {
32  return object.refcounter4light_shared_ptr;
33  }
34 #endif
35 
36 
37 
38  void increment_refcounter()
39  {
40  atomic_exchange_add(refcounter(), 1);
41  }
42 
43  void decrement_refcounter()
44  {
45  if(atomic_exchange_add(refcounter(), -1) == 1)
46  {
47  delete this;
48  }
49  }
50 
51 
52  object_with_ref_counter():
53  object() { refcounter() = 0; }
54 
55  template<typename t1>
56  object_with_ref_counter(t1 a1):
57  object(a1) { refcounter() = 0; }
58 
59 
60  template<typename t2, typename t1>
61  object_with_ref_counter(t2 a2, t1 a1):
62  object(a2, a1) { refcounter() = 0; }
63 
64 
65  template<typename t3, typename t2, typename t1>
66  object_with_ref_counter(t3 a3, t2 a2, t1 a1):
67  object(a3, a2, a1) { refcounter() = 0; }
68 
69  template<typename t4, typename t3, typename t2, typename t1>
70  object_with_ref_counter(t4 a4, t3 a3, t2 a2, t1 a1):
71  object(a4, a3, a2, a1) { refcounter() = 0; }
72 
73 
74  template<typename t5, typename t4, typename t3, typename t2, typename t1>
75  object_with_ref_counter(t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
76  object(a5, a4, a3, a2, a1) { refcounter() = 0; }
77 
78  template<typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
79  object_with_ref_counter(t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
80  object(a6, a5, a4, a3, a2, a1) { refcounter() = 0; }
81 
82 
83  template<typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
84  object_with_ref_counter(t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
85  object(a7, a6, a5, a4, a3, a2, a1) { refcounter() = 0; }
86 
87  template<typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
88  object_with_ref_counter(t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
89  object(a8, a7, a6, a5, a4, a3, a2, a1) { refcounter() = 0; }
90 
91 
92  template<typename t9, typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
93  object_with_ref_counter(t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
94  object(a9, a8, a7, a6, a5, a4, a3, a2, a1) { refcounter() = 0; }
95 
96 
97  template<typename t10, typename t9, typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
98  object_with_ref_counter(t10 a10, t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
99  object(a10, a9, a8, a7, a6, a5, a4, a3, a2, a1) { refcounter() = 0; }
100 
101 
102  template<typename t11, typename t10, typename t9, typename t8, typename t7, typename t6, typename t5, typename t4, typename t3, typename t2, typename t1>
103  object_with_ref_counter(t11 a11, t10 a10, t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
104  object(a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1) { refcounter() = 0; }
105 
106  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>
107  object_with_ref_counter(t12 a12, t11 a11, t10 a10, t9 a9, t8 a8, t7 a7, t6 a6, t5 a5, t4 a4, t3 a3, t2 a2, t1 a1):
108  object(a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1) { refcounter() = 0; }
109 
110 };
111 
112 } // pbio namespace
113 
115 
116 #endif // __FACE_SDK__PBIO__OBJECT_WITH_REF_COUNTER_H__2a81343862d047159b41d58bfe5e730b