Mako 8.2.0 API
MakoCore SDK API Documentation
Loading...
Searching...
No Matches
smartptr.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2007-2025 Global Graphics Software Ltd. All rights reserved.
3 */
4
12
13#ifndef __cplusplus
14#error This file is intended for use with C++ only
15#endif
16
17#ifndef __CSMARTPTR_H
18#define __CSMARTPTR_H
19
20#include <stddef.h>
21
22#include <edl/edlnamespaces.h>
23
25
26#ifdef SWIG
27
28#define DECL_SMART_PTR(cls) \
29 typedef EDL::shared_ptr<cls> cls##Ptr; \
30 typedef EDL::shared_ptr<const cls> cls##ConstPtr;
31
32#else
33
34template <class T>
36{
37public:
38
39 shared_ptr (T *src = NULL, bool bAddref = true) : m_ptr(src)
40 {
41 if (bAddref && m_ptr)
42 m_ptr->addRef();
43 }
44
45 template <class T1>
46 shared_ptr (const shared_ptr<T1> &src): m_ptr(src.operator T1 *())
47 {
48 if (m_ptr)
49 m_ptr->addRef();
50 }
51
52 shared_ptr (const shared_ptr<T> &src): m_ptr(src.operator T *())
53 {
54 if (m_ptr)
55 m_ptr->addRef();
56 }
57
59 {
60 if (m_ptr)
61 m_ptr->decRef();
62 }
63
64 template <class T1>
65 shared_ptr<T1> getPtr(T1 *fake) const
66 {
67 return shared_ptr<T1>((T1*)m_ptr, true);
68 }
69
70 template <class T1>
72 {
73 if (m_ptr)
74 m_ptr->decRef();
75 if ((m_ptr = src.operator T1 *()))
76 m_ptr->addRef();
77 return *this;
78 }
79
81 {
82 T * ptr = m_ptr;
83 if ((m_ptr = src.m_ptr))
84 m_ptr->addRef();
85 if (ptr)
86 ptr->decRef();
87 return *this;
88 }
89
91 {
92 if (m_ptr)
93 m_ptr->decRef();
94 m_ptr = src;
95 return *this;
96 }
97
98 operator T*() const
99 {
100 return m_ptr;
101 }
102
103 T* operator->() const
104 {
105 return m_ptr;
106 }
107
108 T* get ()
109 {
110 return m_ptr;
111 }
112
113protected:
115};
116
117template <class T>
119{
120public:
122 {
123 }
124 explicit shared_constptr (const T *src): m_ptr((T*)src)
125 {
126 if (m_ptr)
127 m_ptr->addRef();
128 }
129 explicit shared_constptr (const T *src , bool bAddref): m_ptr((T *)src)
130 {
131 if (bAddref && m_ptr)
132 m_ptr->addRef();
133 }
134 template <class T1>
136 {
137 return shared_constptr<T1>((T1*)m_ptr, true);
138 }
139 template <class T1>
141 {
142 return shared_ptr<T1>((T1*)m_ptr, true);
143 }
145 {
146 return shared_ptr<T>((T*)m_ptr, true);
147 }
148
149 template <class T1>
150 shared_constptr(const shared_constptr<T1> &src): m_ptr((T1 *)(src.operator const T1*()))
151 {
152 if (m_ptr)
153 m_ptr->addRef();
154 }
155 template <class T1>
156 shared_constptr(const shared_ptr<T1> &src): m_ptr(src.operator T1 *())
157 {
158 if (m_ptr)
159 m_ptr->addRef();
160 }
161 shared_constptr(const shared_constptr<T> &src): m_ptr((T *)(src.operator const T*()))
162 {
163 if (m_ptr)
164 m_ptr->addRef();
165 }
167 {
168 if (m_ptr)
169 m_ptr->decRef();
170 }
171
173 {
174 T * ptr = m_ptr;
175 if ((m_ptr = src.operator T *()))
176 m_ptr->addRef();
177 if (ptr)
178 ptr->decRef();
179 return *this;
180 }
181
183 {
184 T * ptr = m_ptr;
185 if ((m_ptr = src.m_ptr))
186 m_ptr->addRef();
187 if (ptr)
188 ptr->decRef();
189 return *this;
190 }
192 {
193 if (m_ptr)
194 m_ptr->decRef();
195 m_ptr = (T *)src;
196 return *this;
197 }
198 operator const T*() const
199 {
200 return m_ptr;
201 }
202 const T* operator->() const
203 {
204 return m_ptr;
205 }
206
207protected:
209};
210
211#define DECL_SMART_PTR(cls) typedef EDL::shared_ptr<cls> cls##Ptr; typedef EDL::shared_constptr<cls> cls##ConstPtr;
212
213#endif
214
215#define CSmartPtr EDL::shared_ptr
216
218
219#endif // !__CSMARTPTR_H
shared_constptr()
Definition smartptr.h:121
shared_constptr(const shared_constptr< T > &src)
Definition smartptr.h:161
shared_constptr(const T *src, bool bAddref)
Definition smartptr.h:129
shared_constptr & operator=(const T *src)
Definition smartptr.h:191
shared_constptr(const shared_ptr< T1 > &src)
Definition smartptr.h:156
shared_constptr(const shared_constptr< T1 > &src)
Definition smartptr.h:150
const T * operator->() const
Definition smartptr.h:202
shared_ptr< T1 > getPtr(T1 *fake)
Definition smartptr.h:140
T * m_ptr
Definition smartptr.h:208
shared_constptr< T1 > getConstPtr(T1 *fake)
Definition smartptr.h:135
shared_constptr & operator=(const shared_ptr< T > &src)
Definition smartptr.h:172
shared_ptr< T > unConst()
Definition smartptr.h:144
shared_constptr(const T *src)
Definition smartptr.h:124
shared_constptr & operator=(const shared_constptr< T > &src)
Definition smartptr.h:182
~shared_constptr()
Definition smartptr.h:166
Definition smartptr.h:36
T * operator->() const
Definition smartptr.h:103
shared_ptr & operator=(T *src)
Definition smartptr.h:90
~shared_ptr()
Definition smartptr.h:58
shared_ptr(T *src=NULL, bool bAddref=true)
Definition smartptr.h:39
T * m_ptr
Definition smartptr.h:114
shared_ptr< T > & operator=(const shared_ptr< T > &src)
Definition smartptr.h:80
shared_ptr< T > & operator=(const shared_ptr< T1 > &src)
Definition smartptr.h:71
shared_ptr(const shared_ptr< T > &src)
Definition smartptr.h:52
shared_ptr< T1 > getPtr(T1 *fake) const
Definition smartptr.h:65
T * get()
Definition smartptr.h:108
shared_ptr(const shared_ptr< T1 > &src)
Definition smartptr.h:46
EDL C++ namespace(s)
#define _BEGIN_EDL_NAMESPACE
Definition edlnamespaces.h:75
#define _END_EDL_NAMESPACE
Definition edlnamespaces.h:76