diff --git a/Code/Misc/Resource/Loaders/CustomLoader.cpp.orig b/Code/Misc/Resource/Loaders/CustomLoader.cpp.orig deleted file mode 100644 index a37c0a76..00000000 --- a/Code/Misc/Resource/Loaders/CustomLoader.cpp.orig +++ /dev/null @@ -1,73 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// - -#include "..\OResource.h" -#include "..\..\Utilities.h" - -#include - -using namespace Oyster::Resource; - - -OResource* OResource::CustomLoader(const wchar_t filename[], CustomLoadFunction fnc) -{ -<<<<<<< HEAD - CustomData &data = fnc(filename); - - if(!data.loadedData) return 0; - if(!data.resourceUnloadFnc) return 0; - OHRESOURCE n = (OHRESOURCE)data.loadedData; - OResource *resource = new OResource(n, ResourceType_UNKNOWN, 0, 0, filename); - - resource->customData = new CustomResourceData(); - resource->customData->unloadingFunction = data.resourceUnloadFnc; - //resource->resourceData = (OHRESOURCE)data.loadedData; -======= - CustomData data; - memset(&data, 0, sizeof(CustomData)); - - fnc(filename, data); - - if(!data.loadedData) - { - return 0; - } - if(!data.resourceUnloadFnc) - { - return 0; - } - /** For some wierd reason that i don't understand when trying to send data.loadedData directly as a - * parameter to OResource constructor, the value is changed when it arrives in the constructor. - * Doing it like this, storing in a temporary variable, the value stays correct. (What the fuck! I must be overloking something...)*/ - //OHRESOURCE temp = data.loadedData; - OResource *resource = new OResource(data.loadedData, ResourceType_UNKNOWN, 0, 0, filename); - - resource->customData = new CustomResourceData(); - resource->customData->unloadingFunction = data.resourceUnloadFnc; ->>>>>>> d08644e8e1ecc56f4d9dfa6a9aa33df94d9e655a - resource->customData->loadingFunction = fnc; - - return resource; -} -void OResource::CustomUnloader() -{ - this->customData->unloadingFunction(this->resourceData); -} -OResource* OResource::CustomReloader() -{ - CustomUnloader(); - - CustomData data; - memset(&data, 0, sizeof(CustomData)); - - this->customData->loadingFunction(this->resourceFilename.c_str(), data); - this->resourceData = (OHRESOURCE)data.loadedData; - - if(data.resourceUnloadFnc) - { - this->customData->unloadingFunction = data.resourceUnloadFnc; - } - return this; -} - diff --git a/Code/Misc/Utilities-Impl.h b/Code/Misc/Utilities-Impl.h index cc82c959..6567d9eb 100644 --- a/Code/Misc/Utilities-Impl.h +++ b/Code/Misc/Utilities-Impl.h @@ -208,6 +208,12 @@ namespace Utility template SmartPointer::SmartPointer() :_rc(0), _ptr(0) { } + template SmartPointer::SmartPointer(UniquePointer& p) + :_ptr(p.Release()) + { + this->_rc = new ReferenceCount(); + this->_rc->Incref(); + } template SmartPointer::SmartPointer(T* p) :_ptr(p) { @@ -222,10 +228,7 @@ namespace Utility } template SmartPointer::~SmartPointer() { - if (this->_rc && this->_rc->Decref() == 0) - { - Destroy(); - } + this->Release(); } template SmartPointer& SmartPointer::operator= (const SmartPointer& p) { @@ -244,6 +247,30 @@ namespace Utility } return *this; } + template SmartPointer& SmartPointer::operator= (UniquePointer& p) + { + //Last to go? + if(this->_rc) + { + if(this->_rc->Decref() == 0) + { + //Call child specific + Destroy(); + this->_rc = new ReferenceCount(); + } + } + else + { + if(p) this->_rc = new ReferenceCount(); + } + + if(this->_rc) + this->_rc->Incref(); + + this->_ptr = p.Release(); + + return *this; + } template SmartPointer& SmartPointer::operator= (T* p) { if (this->_ptr != p) @@ -266,27 +293,51 @@ namespace Utility } return *this; } - template inline bool SmartPointer::operator== (const SmartPointer& d) + template inline bool SmartPointer::operator== (const SmartPointer& d) const { return d._ptr == this->_ptr; } - template inline bool SmartPointer::operator== (const T& p) + template inline bool SmartPointer::operator== (const T& p) const { return &p == this->_ptr; } + template inline bool SmartPointer::operator!= (const SmartPointer& d) const + { + return d._ptr != this->_ptr; + } + template inline bool SmartPointer::operator!= (const T& p) const + { + return &p != this->_ptr; + } template inline T& SmartPointer::operator* () { return *this->_ptr; } + template inline const T& SmartPointer::operator* () const + { + return *this->_ptr; + } template inline T* SmartPointer::operator-> () { return this->_ptr; } - template inline SmartPointer::operator T* () + template inline const T* SmartPointer::operator-> () const { return this->_ptr; } - template inline SmartPointer::operator bool() + template inline SmartPointer::operator T* () const + { + return this->_ptr; + } + template inline SmartPointer::operator const T* () const + { + return this->_ptr; + } + template inline SmartPointer::operator T& () const + { + return *this->_ptr; + } + template inline SmartPointer::operator bool() const { return (this->_ptr != 0); } @@ -294,7 +345,21 @@ namespace Utility { return this->_ptr; } - template inline bool SmartPointer::IsValid() + template inline T* SmartPointer::Get() const + { + return this->_ptr; + } + template int SmartPointer::Release() + { + int returnVal = 0; + + if(this->_rc && ((returnVal = this->_rc->Decref()) == 0)) + { + Destroy(); + } + return returnVal; + } + template inline bool SmartPointer::IsValid() const { return (this->_ptr != NULL) ? true : false; } diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index 6112bea1..e427d0b3 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -205,27 +205,41 @@ namespace Utility public: SmartPointer(); + SmartPointer(UniquePointer& up); SmartPointer(T* p); SmartPointer(const SmartPointer& d); virtual~SmartPointer(); SmartPointer& operator= (const SmartPointer& p); + SmartPointer& operator= (UniquePointer& p); SmartPointer& operator= (T* p); - bool operator== (const SmartPointer& d); - bool operator== (const T& p); + bool operator== (const SmartPointer& d) const; + bool operator== (const T& p) const; + bool operator!= (const SmartPointer& d) const; + bool operator!= (const T& p) const; T& operator* (); + const T& operator* () const; T* operator-> (); - operator T* (); - operator bool(); + const T* operator-> () const; + operator T* () const; + operator const T* () const; + operator T& () const; + operator bool() const; /** * Returns the connected pointer */ T* Get(); + T* Get() const; + + /** + * Releases one reference of the pointer and set value to null, making the current SmartPointer invalid. + */ + int Release(); /** Checks if the pointer is valid (not NULL) * Returns true for valid, else false. */ - bool IsValid(); + bool IsValid() const; }; }