123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- // ExclusiveHolder.tli
- //
- #pragma once
- #include "ExclusiveHolder.tlh"
- template <typename T>
- ExclusiveHolder <T>::ExclusiveHolder ()
- {
- m_pObject = NULL;
- }
- template <typename T>
- ExclusiveHolder <T>::~ExclusiveHolder ()
- {
- LockHolder Lock (this);
- delete m_pObject;
- }
- template <typename T>
- ExclusiveHolder <T>::ExclusiveHolder (T * object)
- {
- m_pObject = object;
- }
- template <typename T>
- void ExclusiveHolder <T>::Attach (T * object)
- {
- LockHolder Lock (this);
- delete m_pObject;
- m_pObject = object;
- }
- template <typename T>
- T * ExclusiveHolder <T>::Detach ()
- {
- LockHolder Lock (this);
- T * old = m_pObject;
- m_pObject = NULL;
- Release ();
- return old;
- }
- template <typename T>
- void ExclusiveHolder <T>::Release ()
- {
- LockHolder Lock (this);
- delete m_pObject;
- m_pObject = NULL;
- }
- template <typename T>
- ExclusiveHolder <T> & ExclusiveHolder <T>::operator = (T * object)
- {
- Attach (object);
- return *this;
- }
- template <typename T>
- bool ExclusiveHolder <T>::IsEmpty () const
- {
- LockHolder Lock (this);
- return (m_pObject == NULL);
- }
- template <typename T>
- ExclusiveHolder <T>::LockHolder::LockHolder (const ExclusiveHolder <T> *holder)
- {
- auto lock = new std::lock_guard < std::recursive_mutex > (holder->m_Mutex);
- m_Lock.reset (lock);
- m_Holder = holder;
- }
- template <typename T>
- ExclusiveHolder <T>::LockHolder::LockHolder (LockHolder && from)
- {
- m_Lock.swap (from.m_Lock);
- m_Holder = from.m_Holder;
- }
- template <typename T>
- ExclusiveHolder <T>::LockHolder::~LockHolder ()
- {
- }
- template <typename T>
- T * ExclusiveHolder <T>::LockHolder::As ()
- {
- return m_Holder->m_pObject;
- }
- template <typename T>
- const T * ExclusiveHolder <T>::LockHolder::As () const
- {
- return m_Holder->m_pObject;
- }
- template <typename T>
- template <typename C> C * ExclusiveHolder <T>::LockHolder::AS ()
- {
- return m_Holder->m_pObject;
- }
- template <typename T>
- template <typename C> const C * ExclusiveHolder <T>::LockHolder::AS () const
- {
- return m_Holder->m_pObject;
- }
|