mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 12:09:36 +00:00
Lots of stuff
This commit is contained in:
97
PortabilityLayer/ScopedPtr.h
Normal file
97
PortabilityLayer/ScopedPtr.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_SCOPEDPTR_H__
|
||||
#define __PL_SCOPEDPTR_H__
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class T>
|
||||
class ScopedPtr
|
||||
{
|
||||
public:
|
||||
ScopedPtr();
|
||||
ScopedPtr(T *ref);
|
||||
~ScopedPtr();
|
||||
|
||||
void Swap(ScopedPtr<T> &other);
|
||||
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
T *operator->();
|
||||
const T *operator->() const;
|
||||
|
||||
void Set(T *ref);
|
||||
|
||||
private:
|
||||
ScopedPtr(const ScopedPtr<T> &other) PL_DELETED;
|
||||
void operator=(const ScopedPtr<T> &other) PL_DELETED;
|
||||
T *m_ref;
|
||||
};
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::ScopedPtr()
|
||||
: m_ref(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::ScopedPtr(T *ref)
|
||||
: m_ref(ref)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::~ScopedPtr()
|
||||
{
|
||||
if (m_ref)
|
||||
delete m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ScopedPtr<T>::Swap(ScopedPtr<T> &other)
|
||||
{
|
||||
T *temp = m_ref;
|
||||
m_ref = other.m_ref;
|
||||
other.m_ref = temp;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::operator T*()
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::operator const T*() const
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *ScopedPtr<T>::operator->()
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline const T *ScopedPtr<T>::operator->() const
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ScopedPtr<T>::Set(T *ref)
|
||||
{
|
||||
if (m_ref && m_ref != ref)
|
||||
delete m_ref;
|
||||
|
||||
m_ref = ref;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user