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