mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-09 13:37:48 +00:00
Smart pointer cleanup
This commit is contained in:
@@ -31,10 +31,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static inline CFPointer<T> adopt(T CF_RELEASES_ARGUMENT ptr);
|
||||
static inline CFPointer<T> adopt(T CF_RELEASES_ARGUMENT ptr) {
|
||||
return CFPointer<T>(ptr, CFPointer<T>::Adopt);
|
||||
}
|
||||
|
||||
T get() const {
|
||||
return fromStorageType(storage);
|
||||
}
|
||||
|
||||
CFPointer &operator=(CFPointer other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
T get() const;
|
||||
CFPointer &operator=(CFPointer);
|
||||
CFTypeRef* operator&()
|
||||
{
|
||||
if (CFTypeRef pointer = storage) {
|
||||
@@ -58,30 +67,11 @@ private:
|
||||
return (T)pointer;
|
||||
}
|
||||
|
||||
void swap(CFPointer &);
|
||||
void swap(CFPointer &other) {
|
||||
std::swap(storage, other.storage);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
CFPointer<T> CFPointer<T>::adopt(T CF_RELEASES_ARGUMENT ptr) {
|
||||
return CFPointer<T>(ptr, CFPointer<T>::Adopt);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T CFPointer<T>::get() const {
|
||||
return fromStorageType(storage);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline CFPointer<T>& CFPointer<T>::operator=(CFPointer other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void CFPointer<T>::swap(CFPointer &other) {
|
||||
std::swap(storage, other.storage);
|
||||
}
|
||||
|
||||
/// A smart pointer that can manage the lifecycle of CoreFoundation IUnknown objects.
|
||||
template<typename T>
|
||||
class IUnknownPointer {
|
||||
@@ -118,13 +108,17 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static inline IUnknownPointer<T> adopt(T** ptr);
|
||||
static inline IUnknownPointer<T> adopt(T** ptr) {
|
||||
return IUnknownPointer<T>(ptr, IUnknownPointer<T>::Adopt);
|
||||
}
|
||||
|
||||
T* get() const {
|
||||
return fromStorageType(_storage);
|
||||
}
|
||||
|
||||
T* get() const;
|
||||
T* operator->() const { return get(); }
|
||||
T** storage() const { return (T**)_storage; }
|
||||
LPVOID* operator&()
|
||||
{
|
||||
LPVOID* operator&() {
|
||||
if (IUnknownVTbl** pointer = _storage) {
|
||||
printf("%p RELEASE %d\n", pointer, (*pointer)->Release(pointer));
|
||||
}
|
||||
@@ -146,22 +140,9 @@ private:
|
||||
return *(T**)pointer;
|
||||
}
|
||||
|
||||
void swap(IUnknownPointer &);
|
||||
void swap(IUnknownPointer &other) {
|
||||
std::swap(_storage, other._storage);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
IUnknownPointer<T> IUnknownPointer<T>::adopt(T** ptr) {
|
||||
return IUnknownPointer<T>(ptr, IUnknownPointer<T>::Adopt);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* IUnknownPointer<T>::get() const {
|
||||
return fromStorageType(_storage);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void IUnknownPointer<T>::swap(IUnknownPointer &other) {
|
||||
std::swap(_storage, other._storage);
|
||||
}
|
||||
|
||||
#endif // __CFPOINTER_HPP__
|
||||
|
||||
@@ -43,9 +43,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static inline IOObjectPointer<T> adopt(T ptr);
|
||||
static inline IOObjectPointer<T> adopt(T ptr) {
|
||||
return IOObjectPointer<T>(ptr, IOObjectPointer<T>::Adopt);
|
||||
}
|
||||
|
||||
T get() const;
|
||||
T get() const {
|
||||
return fromStorageType(storage);
|
||||
}
|
||||
io_object_t* operator&()
|
||||
{
|
||||
if (io_object_t pointer = storage) {
|
||||
@@ -69,24 +73,11 @@ private:
|
||||
return (T)pointer;
|
||||
}
|
||||
|
||||
void swap(IOObjectPointer &);
|
||||
void swap(IOObjectPointer &other) {
|
||||
std::swap(storage, other.storage);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
IOObjectPointer<T> IOObjectPointer<T>::adopt(T ptr) {
|
||||
return IOObjectPointer<T>(ptr, IOObjectPointer<T>::Adopt);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T IOObjectPointer<T>::get() const {
|
||||
return fromStorageType(storage);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void IOObjectPointer<T>::swap(IOObjectPointer &other) {
|
||||
std::swap(storage, other.storage);
|
||||
}
|
||||
|
||||
/// A smart pointer that can manage the lifecycle of IOKit plugin objects.
|
||||
class IOCFPluginPointer {
|
||||
public:
|
||||
@@ -122,11 +113,9 @@ public:
|
||||
|
||||
private:
|
||||
IOCFPlugInInterface** _storage;
|
||||
void swap(IOCFPluginPointer &);
|
||||
void swap(IOCFPluginPointer &other) {
|
||||
std::swap(_storage, other._storage);
|
||||
}
|
||||
};
|
||||
|
||||
inline void IOCFPluginPointer::swap(IOCFPluginPointer &other) {
|
||||
std::swap(_storage, other._storage);
|
||||
}
|
||||
|
||||
#endif // __IOKITPOINTER_HPP__
|
||||
|
||||
Reference in New Issue
Block a user