STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Platform::Agile< T, TIsNotAgile > Class Template Reference

#include <agile.h>

Public Member Functions

 Agile () throw ()
 
 Agile (nullptr_t) throw ()
 
 Agile (TypeT object) throw ()
 
 Agile (const Agile &object) throw ()
 
 Agile (Agile &&object) throw ()
 
 ~Agile () throw ()
 
TypeT Get () const
 
TypeTGetAddressOf () throw ()
 
TypeTGetAddressOfForInOut () throw ()
 
TypeT operator-> () const throw ()
 
Agileoperator= (nullptr_t) throw ()
 
Agileoperator= (TypeT object) throw ()
 
Agileoperator= (Agile object) throw ()
 
void Swap (Agile &object)
 
void Release () throw ()
 
bool operator== (nullptr_t) const throw ()
 
bool operator== (const Agile &other) const throw ()
 
bool operator< (const Agile &other) const throw ()
 

Private Types

enum  AgileState { AgileState::NonAgilePointer = 0, AgileState::AgilePointer = 1, AgileState::Unknown = 2 }
 
typedef Details::AgileTypeHelper< T >::agileMemberType TypeT
 

Private Member Functions

void CaptureContext ()
 
void SetObject (TypeT object)
 

Private Attributes

TypeT _object
 
::Microsoft::WRL::ComPtr< IUnknown > _contextCallback
 
ULONG_PTR _contextToken
 
AgileState _agileState
 

Member Typedef Documentation

template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
typedef Details::AgileTypeHelper<T>::agileMemberType Platform::Agile< T, TIsNotAgile >::TypeT
private

Member Enumeration Documentation

template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
enum Platform::Agile::AgileState
strongprivate
Enumerator
NonAgilePointer 
AgilePointer 
Unknown 
123  {
124  NonAgilePointer = 0,
125  AgilePointer = 1,
126  Unknown = 2
127  };

Constructor & Destructor Documentation

template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Platform::Agile< T, TIsNotAgile >::Agile ( )
throw (
)
inline
161  {
162  }
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
AgileState _agileState
Definition: agile.h:128
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Platform::Agile< T, TIsNotAgile >::Agile ( nullptr_t  )
throw (
)
inline
165  {
166  }
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
AgileState _agileState
Definition: agile.h:128
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Platform::Agile< T, TIsNotAgile >::Agile ( TypeT  object)
throw (
)
inlineexplicit
169  {
170  // Assumes that the source object is from the current context
171  SetObject(object);
172  }
void SetObject(TypeT object)
Definition: agile.h:136
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
AgileState _agileState
Definition: agile.h:128
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Platform::Agile< T, TIsNotAgile >::Agile ( const Agile< T, TIsNotAgile > &  object)
throw (
)
inline
175  {
176  // Get returns pointer valid for current context
177  SetObject(object.Get());
178  }
void SetObject(TypeT object)
Definition: agile.h:136
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
TypeT Get() const
Definition: agile.h:191
AgileState _agileState
Definition: agile.h:128
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Platform::Agile< T, TIsNotAgile >::Agile ( Agile< T, TIsNotAgile > &&  object)
throw (
)
inline
181  {
182  // Assumes that the source object is from the current context
183  Swap(object);
184  }
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
AgileState _agileState
Definition: agile.h:128
void Swap(Agile &object)
Definition: agile.h:273
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Platform::Agile< T, TIsNotAgile >::~Agile ( )
throw (
)
inline
187  {
188  Release();
189  }
void Release()
Definition: agile.h:282

Member Function Documentation

template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
void Platform::Agile< T, TIsNotAgile >::CaptureContext ( )
inlineprivate
131  {
132  _contextCallback = Details::GetObjectContext();
133  __abi_ThrowIfFailed(CoGetContextToken(&_contextToken));
134  }
void __abi_ThrowIfFailed(long __hrArg)
Definition: vccorlib.h:91
ULONG_PTR _contextToken
Definition: agile.h:120
::Microsoft::WRL::ComPtr< IUnknown > _contextCallback
Definition: agile.h:119
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
TypeT Platform::Agile< T, TIsNotAgile >::Get ( ) const
inline
192  {
193  // Agile object, no proxy required
194  if (_agileState == AgileState::AgilePointer || _object == nullptr)
195  {
196  return _object;
197  }
198 
199  // Do the check for same context
200  ULONG_PTR currentContextToken;
201  __abi_ThrowIfFailed(CoGetContextToken(&currentContextToken));
202  if (currentContextToken == _contextToken)
203  {
204  return _object;
205  }
206 
207  // Different context and holding on to a non agile object
208  // Do the costly work of getting a proxy
209  TypeT localObject;
210  __abi_ThrowIfFailed(Details::GetProxy(_object, _contextCallback.Get(), &localObject));
211 
213  {
214  // Object is agile if it implements IAgileObject
215  // GetAddressOf captures the context with out knowing the type of object that it will hold
216  ::Microsoft::WRL::ComPtr<IAgileObject> checkIfAgile;
217  HRESULT hr = reinterpret_cast<IUnknown*>(localObject)->QueryInterface(__uuidof(IAgileObject), &checkIfAgile);
218  if (hr == S_OK)
219  {
220  auto pThis = const_cast<Agile*>(this);
221  pThis->_agileState = AgileState::AgilePointer;
222  pThis->_contextToken = 0;
223  pThis->_contextCallback = nullptr;
224  return _object;
225  }
226  else
227  {
228  auto pThis = const_cast<Agile*>(this);
229  pThis->_agileState = AgileState::NonAgilePointer;
230  }
231  }
232 
233  return localObject;
234  }
#define S_OK
Definition: comutil.h:62
TypeT _object
Definition: agile.h:118
Details::AgileTypeHelper< T >::agileMemberType TypeT
Definition: agile.h:116
void __abi_ThrowIfFailed(long __hrArg)
Definition: vccorlib.h:91
Agile()
Definition: agile.h:160
ULONG_PTR _contextToken
Definition: agile.h:120
AgileState _agileState
Definition: agile.h:128
::Microsoft::WRL::ComPtr< IUnknown > _contextCallback
Definition: agile.h:119
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
TypeT* Platform::Agile< T, TIsNotAgile >::GetAddressOf ( )
throw (
)
inline
237  {
238  Release();
239  CaptureContext();
240  return &_object;
241  }
TypeT _object
Definition: agile.h:118
void Release()
Definition: agile.h:282
void CaptureContext()
Definition: agile.h:130
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
TypeT* Platform::Agile< T, TIsNotAgile >::GetAddressOfForInOut ( )
throw (
)
inline
244  {
245  CaptureContext();
246  return &_object;
247  }
TypeT _object
Definition: agile.h:118
void CaptureContext()
Definition: agile.h:130
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
TypeT Platform::Agile< T, TIsNotAgile >::operator-> ( ) const
throw (
)
inline
250  {
251  return Get();
252  }
TypeT Get() const
Definition: agile.h:191
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
bool Platform::Agile< T, TIsNotAgile >::operator< ( const Agile< T, TIsNotAgile > &  other) const
throw (
)
inline
318  {
319  if (reinterpret_cast<void*>(_object) < reinterpret_cast<void*>(other._object))
320  {
321  return true;
322  }
323 
324  return _object == other._object && _contextToken < other._contextToken;
325  }
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Agile& Platform::Agile< T, TIsNotAgile >::operator= ( nullptr_t  )
throw (
)
inline
255  {
256  Release();
257  return *this;
258  }
void Release()
Definition: agile.h:282
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Agile& Platform::Agile< T, TIsNotAgile >::operator= ( TypeT  object)
throw (
)
inline
261  {
262  Agile(object).Swap(*this);
263  return *this;
264  }
Agile()
Definition: agile.h:160
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
Agile& Platform::Agile< T, TIsNotAgile >::operator= ( Agile< T, TIsNotAgile >  object)
throw (
)
inline
267  {
268  // parameter is by copy which gets pointer valid for current context
269  object.Swap(*this);
270  return *this;
271  }
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
bool Platform::Agile< T, TIsNotAgile >::operator== ( nullptr_t  ) const
throw (
)
inline
308  {
309  return _object == nullptr;
310  }
TypeT _object
Definition: agile.h:118
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
bool Platform::Agile< T, TIsNotAgile >::operator== ( const Agile< T, TIsNotAgile > &  other) const
throw (
)
inline
313  {
314  return _object == other._object && _contextToken == other._contextToken;
315  }
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
void Platform::Agile< T, TIsNotAgile >::Release ( )
throw (
)
inline
283  {
284  if (_object)
285  {
286  // Cast to IInspectable (no QI)
287  IUnknown* pObject = *(IUnknown**) (&_object);
288  // Set ^ to null without release
289  *(IUnknown**) (&_object) = nullptr;
290 
291  ULONG_PTR currentContextToken;
292  __abi_ThrowIfFailed(CoGetContextToken(&currentContextToken));
293  if (_contextToken == 0 || _contextCallback == nullptr || _contextToken == currentContextToken)
294  {
295  pObject->Release();
296  }
297  else
298  {
300  }
301  _contextCallback = nullptr;
302  _contextToken = 0;
304  }
305  }
HRESULT ReleaseInContext(T *ObjectIn, IUnknown *ContextCallBack)
Definition: agile.h:37
TypeT _object
Definition: agile.h:118
void __abi_ThrowIfFailed(long __hrArg)
Definition: vccorlib.h:91
ULONG_PTR _contextToken
Definition: agile.h:120
AgileState _agileState
Definition: agile.h:128
::Microsoft::WRL::ComPtr< IUnknown > _contextCallback
Definition: agile.h:119
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
void Platform::Agile< T, TIsNotAgile >::SetObject ( TypeT  object)
inlineprivate
137  {
138  // Capture context before setting the pointer
139  // If context capture fails then nothing to cleanup
140  Release();
141  if (object != nullptr)
142  {
143  ::Microsoft::WRL::ComPtr<IAgileObject> checkIfAgile;
144  HRESULT hr = reinterpret_cast<IUnknown*>(object)->QueryInterface(__uuidof(IAgileObject), &checkIfAgile);
145  // Don't Capture context if object is agile
146  if (hr != S_OK)
147  {
149  CaptureContext();
150  }
151  else
152  {
154  }
155  }
156  _object = object;
157  }
#define S_OK
Definition: comutil.h:62
TypeT _object
Definition: agile.h:118
void Release()
Definition: agile.h:282
void CaptureContext()
Definition: agile.h:130
AgileState _agileState
Definition: agile.h:128
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
void Platform::Agile< T, TIsNotAgile >::Swap ( Agile< T, TIsNotAgile > &  object)
inline
274  {
275  std::swap(_object, object._object);
279  }
TypeT _object
Definition: agile.h:118
ULONG_PTR _contextToken
Definition: agile.h:120
void swap(array< _Ty, _Size > &_Left, array< _Ty, _Size > &_Right) _NOEXCEPT_OP(_NOEXCEPT_OP(_Left.swap(_Right)))
Definition: array:429
AgileState _agileState
Definition: agile.h:128
::Microsoft::WRL::ComPtr< IUnknown > _contextCallback
Definition: agile.h:119

Member Data Documentation

template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
AgileState Platform::Agile< T, TIsNotAgile >::_agileState
private
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
::Microsoft::WRL::ComPtr<IUnknown> Platform::Agile< T, TIsNotAgile >::_contextCallback
private
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
ULONG_PTR Platform::Agile< T, TIsNotAgile >::_contextToken
private
template<typename T, bool TIsNotAgile = (__is_win_class(typename Details::AgileTypeHelper<T>::type) && !__is_winrt_agile(typename Details::AgileTypeHelper<T>::type)) || __is_win_interface(typename Details::AgileTypeHelper<T>::type)>
TypeT Platform::Agile< T, TIsNotAgile >::_object
private

The documentation for this class was generated from the following file: