Version

menu_open
Wwise SDK 2021.1.14
AkSmartPtr.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: v2021.1.14 Build: 6590
25  Copyright (c) 2006-2023 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 // AkSmartPtr.h
29 
30 /// \file
31 /// Helper file.
32 
33 #ifndef _AK_SMARTPTR_H
34 #define _AK_SMARTPTR_H
35 
37 
38 template <class T> class CAkSmartPtr
39 {
40 public:
41  /// Smart pointer constructor
43  : m_pT( NULL )
44  {
45  }
46 
47  /// Smart pointer constructor
49  {
50  m_pT = in_pT;
51  if (m_pT)
52  m_pT->AddRef();
53  }
54 
55  /// Smart pointer copy constructor
57  {
58  m_pT = in_rPtr.m_pT;
59  if (m_pT)
60  m_pT->AddRef();
61  }
62 
63  /// Smart pointer move constructor
65  {
66  m_pT = in_rPtr.m_pT;
67  in_rPtr.m_pT = NULL;
68  }
69 
70  /// Smart pointer destructor
72  {
73  Release();
74  }
75 
76  /// Release
78  {
79  if( m_pT )
80  {
81  m_pT->Release();
82  m_pT = NULL;
83  }
84  }
85 
86  /// Assign with no Addref.
87  AkForceInline void Attach( T* in_pObj )
88  {
89  _Assign( in_pObj, false );
90  }
91 
92  /// Give the pointer without releasing it.
94  {
95  T* pObj = m_pT;
96  m_pT = NULL;
97 
98  return pObj;
99  }
100 
101  /// Copy Assignation operator</span>
102  const CAkSmartPtr<T>& operator=( const CAkSmartPtr<T>& in_pObj )
103  {
104  _Assign( in_pObj.m_pT );
105  return *this;
106  }
107 
108  /// Move Assignation operator</span>
110  {
111  _Assign( in_pObj.m_pT, false );
112  in_pObj.m_pT = NULL;
113  return *this;
114  }
115 
116  /// Assignation operator</span>
117  const CAkSmartPtr<T>& operator=( T* in_pObj )
118  {
119  _Assign( in_pObj );
120  return *this;
121  }
122 
123  /// Operator *
124  T& operator*() { return *m_pT; }
125 
126  /// Operator ->
127  T* operator->() const { return m_pT; }
128 
129  /// Operator
130  operator</span> T*() const { return m_pT; }
131 
132  /// Operators to pass to functions like QueryInterface and other functions returning an addref'd pointer.
133  T** operator &() { return &m_pT; }
134 
135  /// Operator *
136  const T& operator*() const { return *m_pT; }
137 
138  /// Cast
139  T* Cast() { return m_pT; }
140 
141  /// Cast
142  const T* Cast() const { return m_pT; }
143 
144 protected:
145 
146  /// internal use only
147  void _Assign( T* in_pObj, bool in_bAddRef = true )
148  {
149  if (in_pObj != NULL && in_bAddRef)
150  in_pObj->AddRef();
151 
152  // Must use a local pointer since we cannot call Release(); without having set the m_pT to its final value.
153  T* l_Ptr = m_pT;
154  m_pT = in_pObj;
155  if (l_Ptr)
156  l_Ptr->Release();
157  }
158 
159  /// internal use only
160  bool _Compare( const T* in_pObj ) const
161  {
162  return m_pT == in_pObj;
163  }
164 
165  /// internal use only
166  T* m_pT;
167 };
168 
169 #endif // _AK_SMARTPTR_H
170 
bool _Compare(const T *in_pObj) const
internal use only
Definition: AkSmartPtr.h:160
const T * Cast() const
Cast.
Definition: AkSmartPtr.h:142
const CAkSmartPtr< T > & operator=(T *in_pObj)
Assignation operator.
Definition: AkSmartPtr.h:117
#define NULL
Definition: AkTypes.h:47
CAkSmartPtr< T > & operator=(CAkSmartPtr< T > &&in_pObj)
Move Assignation operator.
Definition: AkSmartPtr.h:109
AkForceInline CAkSmartPtr()
Smart pointer constructor.
Definition: AkSmartPtr.h:42
void _Assign(T *in_pObj, bool in_bAddRef=true)
internal use only
Definition: AkSmartPtr.h:147
AkForceInline T * Detach()
Give the pointer without releasing it.
Definition: AkSmartPtr.h:93
~CAkSmartPtr()
Smart pointer destructor.
Definition: AkSmartPtr.h:71
AkForceInline CAkSmartPtr(const CAkSmartPtr< T > &in_rPtr)
Smart pointer copy constructor.
Definition: AkSmartPtr.h:56
AkForceInline CAkSmartPtr(CAkSmartPtr< T > &&in_rPtr)
Smart pointer move constructor.
Definition: AkSmartPtr.h:64
T * operator->() const
Operator ->
Definition: AkSmartPtr.h:127
AkForceInline CAkSmartPtr(T *in_pT)
Smart pointer constructor.
Definition: AkSmartPtr.h:48
AkForceInline void Attach(T *in_pObj)
Assign with no Addref.
Definition: AkSmartPtr.h:87
T ** operator&()
Operators to pass to functions like QueryInterface and other functions returning an addref'd pointer.
Definition: AkSmartPtr.h:133
T * Cast()
Cast.
Definition: AkSmartPtr.h:139
AkForceInline void Release()
Release.
Definition: AkSmartPtr.h:77
T * m_pT
internal use only
Definition: AkSmartPtr.h:166
const T & operator*() const
Operator *.
Definition: AkSmartPtr.h:136
T & operator*()
Operator *.
Definition: AkSmartPtr.h:124
const CAkSmartPtr< T > & operator=(const CAkSmartPtr< T > &in_pObj)
Copy Assignation operator.
Definition: AkSmartPtr.h:102
#define AkForceInline
Definition: AkTypes.h:60

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise