버전

menu_open
Wwise SDK 2022.1.18
AkSmartPtr.h
이 파일의 문서화 페이지로 가기
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  Copyright (c) 2024 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 // AkSmartPtr.h
28 
29 /// \file
30 /// Helper file.
31 
32 #ifndef _AK_SMARTPTR_H
33 #define _AK_SMARTPTR_H
34 
36 
37 template <class T> class CAkSmartPtr
38 {
39 public:
40  /// Smart pointer constructor
42  : m_pT( NULL )
43  {
44  }
45 
46  /// Smart pointer constructor
48  {
49  m_pT = in_pT;
50  if (m_pT)
51  m_pT->AddRef();
52  }
53 
54  /// Smart pointer copy constructor
56  {
57  m_pT = in_rPtr.m_pT;
58  if (m_pT)
59  m_pT->AddRef();
60  }
61 
62  /// Smart pointer move constructor
64  {
65  m_pT = in_rPtr.m_pT;
66  in_rPtr.m_pT = NULL;
67  }
68 
69  /// Smart pointer destructor
71  {
72  Release();
73  }
74 
75  /// Release
77  {
78  if( m_pT )
79  {
80  m_pT->Release();
81  m_pT = NULL;
82  }
83  }
84 
85  /// Assign with no Addref.
86  AkForceInline void Attach( T* in_pObj )
87  {
88  _Assign( in_pObj, false );
89  }
90 
91  /// Give the pointer without releasing it.
93  {
94  T* pObj = m_pT;
95  m_pT = NULL;
96 
97  return pObj;
98  }
99 
100  /// Copy Assignation operator</span>
101  const CAkSmartPtr<T>& operator=( const CAkSmartPtr<T>& in_pObj )
102  {
103  _Assign( in_pObj.m_pT );
104  return *this;
105  }
106 
107  /// Move Assignation operator</span>
109  {
110  _Assign( in_pObj.m_pT, false );
111  in_pObj.m_pT = NULL;
112  return *this;
113  }
114 
115  /// Assignation operator</span>
116  const CAkSmartPtr<T>& operator=( T* in_pObj )
117  {
118  _Assign( in_pObj );
119  return *this;
120  }
121 
122  /// Operator *
123  T& operator*() { return *m_pT; }
124 
125  /// Operator ->
126  T* operator->() const { return m_pT; }
127 
128  /// Operator
129  operator</span> T*() const { return m_pT; }
130 
131  /// Operators to pass to functions like QueryInterface and other functions returning an addref'd pointer.
132  T** operator &() { return &m_pT; }
133 
134  /// Operator *
135  const T& operator*() const { return *m_pT; }
136 
137  /// Cast
138  T* Cast() { return m_pT; }
139 
140  /// Cast
141  const T* Cast() const { return m_pT; }
142 
143 protected:
144 
145  /// internal use only
146  void _Assign( T* in_pObj, bool in_bAddRef = true )
147  {
148  if (in_pObj != NULL && in_bAddRef)
149  in_pObj->AddRef();
150 
151  // Must use a local pointer since we cannot call Release(); without having set the m_pT to its final value.
152  T* l_Ptr = m_pT;
153  m_pT = in_pObj;
154  if (l_Ptr)
155  l_Ptr->Release();
156  }
157 
158  /// internal use only
159  bool _Compare( const T* in_pObj ) const
160  {
161  return m_pT == in_pObj;
162  }
163 
164  /// internal use only
165  T* m_pT;
166 };
167 
168 #endif // _AK_SMARTPTR_H
169 
bool _Compare(const T *in_pObj) const
internal use only
Definition: AkSmartPtr.h:159
const T * Cast() const
Cast
Definition: AkSmartPtr.h:141
const CAkSmartPtr< T > & operator=(T *in_pObj)
Assignation operator</div>
Definition: AkSmartPtr.h:116
#define NULL
Definition: AkTypes.h:46
CAkSmartPtr< T > & operator=(CAkSmartPtr< T > &&in_pObj)
Move Assignation operator</div>
Definition: AkSmartPtr.h:108
AkForceInline CAkSmartPtr()
Smart pointer constructor
Definition: AkSmartPtr.h:41
void _Assign(T *in_pObj, bool in_bAddRef=true)
internal use only
Definition: AkSmartPtr.h:146
AkForceInline T * Detach()
Give the pointer without releasing it.
Definition: AkSmartPtr.h:92
~CAkSmartPtr()
Smart pointer destructor
Definition: AkSmartPtr.h:70
AkForceInline CAkSmartPtr(const CAkSmartPtr< T > &in_rPtr)
Smart pointer copy constructor
Definition: AkSmartPtr.h:55
AkForceInline CAkSmartPtr(CAkSmartPtr< T > &&in_rPtr)
Smart pointer move constructor
Definition: AkSmartPtr.h:63
T * operator->() const
Operator ->
Definition: AkSmartPtr.h:126
AkForceInline CAkSmartPtr(T *in_pT)
Smart pointer constructor
Definition: AkSmartPtr.h:47
AkForceInline void Attach(T *in_pObj)
Assign with no Addref.
Definition: AkSmartPtr.h:86
T ** operator&()
Operators to pass to functions like QueryInterface and other functions returning an addref'd pointer.
Definition: AkSmartPtr.h:132
T * Cast()
Cast
Definition: AkSmartPtr.h:138
AkForceInline void Release()
Release
Definition: AkSmartPtr.h:76
T * m_pT
internal use only
Definition: AkSmartPtr.h:165
const T & operator*() const
Operator *
Definition: AkSmartPtr.h:135
T & operator*()
Operator *
Definition: AkSmartPtr.h:123
const CAkSmartPtr< T > & operator=(const CAkSmartPtr< T > &in_pObj)
Copy Assignation operator</div>
Definition: AkSmartPtr.h:101
#define AkForceInline
Definition: AkTypes.h:63

이 페이지가 도움이 되었나요?

지원이 필요하신가요?

질문이 있으신가요? 문제를 겪고 계신가요? 더 많은 정보가 필요하신가요? 저희에게 문의해주시면 도와드리겠습니다!

지원 페이지를 방문해 주세요

작업하는 프로젝트에 대해 알려주세요. 언제든지 도와드릴 준비가 되어 있습니다.

프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.

Wwise를 시작해 보세요