#pragma once #include "Misc/Common.h" namespace Bblids { namespace Wrapping { // ----------------------------------------------------------------------------- // ***************************************************************************** // ----------------------------------------------------------------------------- template ref struct CWrappedSmartPtr : System::IDisposable { public: typedef CWrappedSmartPtr self_type; typedef T wrapped_type; typedef wrapped_type* ptr_wrapped_type; typedef boost::shared_ptr smart_ptr_wrapped_type; public: CWrappedSmartPtr() : FWrappedSmartPtr (nullptr) { } CWrappedSmartPtr(ptr_wrapped_type parPtr) : FWrappedSmartPtr (new smart_ptr_wrapped_type(parPtr)) { } CWrappedSmartPtr(const smart_ptr_wrapped_type& parSmartPtr) : FWrappedSmartPtr (new smart_ptr_wrapped_type(parSmartPtr)) { } CWrappedSmartPtr(self_type% parOther) : FWrappedSmartPtr (new smart_ptr_wrapped_type(parOther.FWrappedSmartPtr)) { } ~CWrappedSmartPtr() { Reset(nullptr); } !CWrappedSmartPtr() { Reset(nullptr); } public: bool IsNull() { BBLIDS_ASSERT(FWrappedSmartPtr == nullptr || FWrappedSmartPtr->get() != nullptr); return (FWrappedSmartPtr == nullptr); } bool IsNotNull() { BBLIDS_ASSERT(FWrappedSmartPtr == nullptr || FWrappedSmartPtr->get() != nullptr); return (FWrappedSmartPtr != nullptr); } ptr_wrapped_type operator->() { BBLIDS_ASSERT(nullptr != FWrappedSmartPtr); return (FWrappedSmartPtr->get()); } wrapped_type& Get() { return (*FWrappedSmartPtr->get()); } public: bool operator ==(self_type% parOther) { return (FWrappedSmartPtr == parOther.FWrappedSmartPtr); } bool operator !=(self_type% parOther) { return (FWrappedSmartPtr != parOther.FWrappedSmartPtr); } bool operator <(self_type% parOther) { return (FWrappedSmartPtr < parOther.FWrappedSmartPtr); } bool operator >=(self_type% parOther) { return (FWrappedSmartPtr >= parOther.FWrappedSmartPtr); } public: void Swap(self_type% parOther) { std::swap(FWrappedSmartPtr, parOther.FWrappedSmartPtr); } smart_ptr_wrapped_type* Release() { if (FWrappedSmartPtr == nullptr) return (nullptr); smart_ptr_wrapped_type* wrapped_smart_ptr = FWrappedSmartPtr; FWrappedSmartPtr = nullptr; return (wrapped_smart_ptr); } void Reset() { Reset(nullptr); } void Reset(ptr_wrapped_type parPtr) { if (FWrappedSmartPtr != nullptr) { if (parPtr == FWrappedSmartPtr->get()) return; delete (FWrappedSmartPtr); } FWrappedSmartPtr = (parPtr == nullptr) ? nullptr : new smart_ptr_wrapped_type(parPtr); } void Reset(const smart_ptr_wrapped_type& parSmartPtr) { if (FWrappedSmartPtr != nullptr) { if (parSmartPtr.get() == FWrappedSmartPtr->get()) return; delete (FWrappedSmartPtr); } FWrappedSmartPtr = new smart_ptr_wrapped_type(parSmartPtr); } private: smart_ptr_wrapped_type* FWrappedSmartPtr; }; // ----------------------------------------------------------------------------- // ***************************************************************************** // ----------------------------------------------------------------------------- }}