#pragma once #ifndef __PL_SCOPEDARRAY_H__ #define __PL_SCOPEDARRAY_H__ #include "CoreDefs.h" namespace PortabilityLayer { template class ScopedArray { public: ScopedArray(); ScopedArray(T *ref); ~ScopedArray(); void Swap(ScopedArray &other); operator T*(); operator const T*() const; void Set(T *ref); private: ScopedArray(const ScopedArray &other) GP_DELETED; void operator=(const ScopedArray &other) GP_DELETED; T *m_ref; }; } namespace PortabilityLayer { template inline ScopedArray::ScopedArray() : m_ref(nullptr) { } template inline ScopedArray::ScopedArray(T *ref) : m_ref(ref) { } template inline ScopedArray::~ScopedArray() { if (m_ref) delete[] m_ref; } template inline void ScopedArray::Swap(ScopedArray &other) { T *temp = m_ref; m_ref = other.m_ref; other.m_ref = temp; } template inline ScopedArray::operator T*() { return m_ref; } template inline ScopedArray::operator const T*() const { return m_ref; } template inline void ScopedArray::Set(T *ref) { if (m_ref && m_ref != ref) delete m_ref; m_ref = ref; } } #endif