버전

menu_open
Wwise SDK 2019.1.11
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  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> 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 
36 #include <AK/SoundEngine/Common/AkTypes.h>
37 
38 template <class T> class CAkSmartPtr
39 {
40 public:
41  /// Smart pointer constructor
42  AkForceInline CAkSmartPtr()
43  : m_pT( NULL )
44  {
45  }
46 
47  /// Smart pointer constructor
48  AkForceInline CAkSmartPtr( T* in_pT )
49  {
50  m_pT = in_pT;
51  if (m_pT)
52  m_pT->AddRef();
53  }
54 
55  /// Smart pointer constructor
56  AkForceInline CAkSmartPtr( const CAkSmartPtr<T>& in_rPtr )
57  {
58  m_pT = in_rPtr.m_pT;
59  if (m_pT)
60  m_pT->AddRef();
61  }
62 
63  /// Smart pointer destructor
65  {
66  Release();
67  }
68 
69  /// Release
70  AkForceInline void Release()
71  {
72  if( m_pT )
73  {
74  m_pT->Release();
75  m_pT = NULL;
76  }
77  }
78 
79  /// Assign with no Addref.
80  AkForceInline void Attach( T* in_pObj )
81  {
82  _Assign( in_pObj, false );
83  }
84 
85  /// Give the pointer without releasing it.
86  AkForceInline T* Detach()
87  {
88  T* pObj = m_pT;
89  m_pT = NULL;
90 
91  return pObj;
92  }
93 
94  /// Assignation operator</span>
95  const CAkSmartPtr<T>& operator=( const CAkSmartPtr<T>& in_pObj )
96  {
97  _Assign( in_pObj.m_pT );
98  return *this;
99  }
100 
101  /// Assignation operator</span>
102  const CAkSmartPtr<T>& operator=( T* in_pObj )
103  {
104  _Assign( in_pObj );
105  return *this;
106  }
107 
108  /// Operator *
109  T& operator*() { return *m_pT; }
110 
111  /// Operator ->
112  T* operator->() const { return m_pT; }
113 
114  /// Operator
115  operator</span> T*() const { return m_pT; }
116 
117  /// Operators to pass to functions like QueryInterface and other functions returning an addref'd pointer.
118  T** operator &() { return &m_pT; }
119 
120  /// Operator *
121  const T& operator*() const { return *m_pT; }
122 
123  /// Cast
124  T* Cast() { return m_pT; }
125 
126  /// Cast
127  const T* Cast() const { return m_pT; }
128 
129 protected:
130 
131  /// internal use only
132  void _Assign( T* in_pObj, bool in_bAddRef = true )
133  {
134  if (in_pObj != NULL && in_bAddRef)
135  in_pObj->AddRef();
136 
137  // Must use a local pointer since we cannot call Release(); without having set the m_pT to its final value.
138  T* l_Ptr = m_pT;
139  m_pT = in_pObj;
140  if (l_Ptr)
141  l_Ptr->Release();
142  }
143 
144  /// internal use only
145  bool _Compare( const T* in_pObj ) const
146  {
147  return m_pT == in_pObj;
148  }
149 
150  /// internal use only
151  T* m_pT;
152 };
153 
154 #endif // _AK_SMARTPTR_H
155 
bool _Compare(const T *in_pObj) const
internal use only
Definition: AkSmartPtr.h:145
const T * Cast() const
Cast
Definition: AkSmartPtr.h:127
const CAkSmartPtr< T > & operator=(T *in_pObj)
Assignation operator</div>
Definition: AkSmartPtr.h:102
AkForceInline CAkSmartPtr()
Smart pointer constructor
Definition: AkSmartPtr.h:42
void _Assign(T *in_pObj, bool in_bAddRef=true)
internal use only
Definition: AkSmartPtr.h:132
AkForceInline T * Detach()
Give the pointer without releasing it.
Definition: AkSmartPtr.h:86
~CAkSmartPtr()
Smart pointer destructor
Definition: AkSmartPtr.h:64
AkForceInline CAkSmartPtr(const CAkSmartPtr< T > &in_rPtr)
Smart pointer constructor
Definition: AkSmartPtr.h:56
T * operator->() const
Operator ->
Definition: AkSmartPtr.h:112
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:80
T ** operator&()
Operators to pass to functions like QueryInterface and other functions returning an addref'd pointer.
Definition: AkSmartPtr.h:118
T * Cast()
Cast
Definition: AkSmartPtr.h:124
AkForceInline void Release()
Release
Definition: AkSmartPtr.h:70
T * m_pT
internal use only
Definition: AkSmartPtr.h:151
const T & operator*() const
Operator *
Definition: AkSmartPtr.h:121
T & operator*()
Operator *
Definition: AkSmartPtr.h:109
const CAkSmartPtr< T > & operator=(const CAkSmartPtr< T > &in_pObj)
Assignation operator</div>
Definition: AkSmartPtr.h:95

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

지원이 필요하신가요?

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

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

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

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

Wwise를 시작해 보세요