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/Resource/OysterResource.h.orig b/Code/Misc/Resource/OysterResource.h.orig deleted file mode 100644 index 2ec147e8..00000000 --- a/Code/Misc/Resource/OysterResource.h.orig +++ /dev/null @@ -1,162 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// - -#ifndef MISC_OYSTER_RESOURCE_H -#define MISC_OYSTER_RESOURCE_H - - -namespace Oyster -{ - namespace Resource - { - struct CustomData; - /** A Resource handle representing various resources */ - typedef void* OHRESOURCE; - /** Typedef on a fuction required for custom unloading */ - typedef void(*CustomUnloadFunction)(void* loadedData); - /** Typedef on a fuction required for custom loading */ -<<<<<<< HEAD - typedef CustomData&(*CustomLoadFunction)(const wchar_t filename[]); -======= - typedef void(*CustomLoadFunction)(const wchar_t filename[], CustomData& outData); ->>>>>>> d08644e8e1ecc56f4d9dfa6a9aa33df94d9e655a - - /** An enum class representing all avalible resources that is supported. */ - enum ResourceType - { - //Byte - ResourceType_Byte_Raw, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_ANSI, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_UTF8, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_UNICODE, /**< Handle can be interpeted as char[] or char* */ - ResourceType_Byte_UTF16LE, /**< Handle can be interpeted as char[] or char* */ - - ResourceType_COUNT, /**< Not used. */ - - ResourceType_UNKNOWN = -1, /**< Handle can be interpeted as void* */ - ResourceType_INVALID = -2, /**< Invalid or non existing resource */ - }; - - /** A struct to fill when doing a custom resource Load. */ - struct CustomData - { - void* loadedData; // 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) { @@ -244,6 +250,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,19 +296,19 @@ 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) + 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; } @@ -286,15 +316,31 @@ namespace Utility { 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); } @@ -302,7 +348,7 @@ namespace Utility { return this->_ptr; } - template inline bool SmartPointer::IsValid() + 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 e541e1df..aaec016a 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -205,29 +205,36 @@ 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); - 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; /** Checks if the pointer is valid (not NULL) * Returns true for valid, else false. */ - bool IsValid(); + bool IsValid() const; }; }