2013-11-22 10:46:25 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef MISC_OYSTER_RESOURCE_H
|
|
|
|
#define MISC_OYSTER_RESOURCE_H
|
|
|
|
|
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Resource
|
|
|
|
{
|
2013-11-26 10:55:51 +01:00
|
|
|
struct CustomData;
|
2013-11-22 10:46:25 +01:00
|
|
|
/** A Resource handle representing various resources */
|
|
|
|
typedef unsigned long OHRESOURCE;
|
2013-11-26 21:51:40 +01:00
|
|
|
/** Typedef on a fuction required for custom unloading */
|
2013-11-26 12:09:38 +01:00
|
|
|
typedef void(*CustomUnloadFunction)(void* loadedData);
|
2013-11-26 21:51:40 +01:00
|
|
|
/** Typedef on a fuction required for custom loading */
|
2013-11-26 12:09:38 +01:00
|
|
|
typedef const CustomData&(*CustomLoadFunction)(const wchar_t filename[]);
|
2013-11-22 10:46:25 +01:00
|
|
|
|
|
|
|
/** 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* */
|
|
|
|
|
2013-11-26 21:51:40 +01:00
|
|
|
ResourceType_COUNT, /**< Not used. */
|
2013-11-26 10:55:51 +01:00
|
|
|
|
|
|
|
ResourceType_UNKNOWN = -1, /**< Handle can be interpeted as void* */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A struct to return when doing a custom resource Load
|
|
|
|
* By loading this way you are handing over the ownership to the resource loaded.
|
|
|
|
*/
|
|
|
|
struct CustomData
|
|
|
|
{
|
|
|
|
void* loadedData; ///<! The loaded resource interpeted as a void*.
|
|
|
|
CustomUnloadFunction resourceUnloadFnc; ///<! The function that will be used to free the resource when needed.
|
2013-11-22 10:46:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A resource handler interface to interact with when loading resources.
|
|
|
|
* The resource handler uses the filename to make resources unuiqe.
|
|
|
|
*/
|
2013-11-26 10:55:51 +01:00
|
|
|
class OysterResource
|
2013-11-22 10:46:25 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-11-26 10:55:51 +01:00
|
|
|
/**
|
|
|
|
* Load a resource given a type.
|
|
|
|
* @param filename The path to the resource.
|
|
|
|
* @param type The resource type to load.
|
|
|
|
* @param force If set to true, the resource will be reloaded if it already exists. If it does not, nothing happens.
|
|
|
|
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
|
|
|
|
*/
|
|
|
|
static OHRESOURCE LoadResource(const wchar_t filename[], ResourceType type);
|
2013-11-22 10:46:25 +01:00
|
|
|
|
|
|
|
/**
|
2013-11-26 10:55:51 +01:00
|
|
|
* Load a resource with a custom loading function
|
|
|
|
* @param filename The path to the resource.
|
|
|
|
* @param force If set to true, the resource will be reloaded even if exists.
|
|
|
|
* @param loadFnc If set, this gives you the right to do custom resource loading if your recource type is not supported.
|
|
|
|
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
|
2013-11-22 10:46:25 +01:00
|
|
|
*/
|
2013-11-26 10:55:51 +01:00
|
|
|
static OHRESOURCE LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc = 0, unsigned int CustomId = 0);
|
2013-11-22 10:46:25 +01:00
|
|
|
|
|
|
|
/**
|
2013-11-26 10:55:51 +01:00
|
|
|
* Reload a resource
|
|
|
|
* @param filename The path to the resource.
|
|
|
|
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
|
|
|
|
*/
|
|
|
|
static OHRESOURCE ReloadResource(const wchar_t filename[]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reload a resource
|
2013-11-22 10:46:25 +01:00
|
|
|
* @param filename The path to the resource.
|
|
|
|
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
|
|
|
|
*/
|
2013-11-26 10:55:51 +01:00
|
|
|
static OHRESOURCE ReloadResource(OHRESOURCE resource);
|
2013-11-22 10:46:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases all resources loaded by the resource handler.
|
|
|
|
* @return Nothing
|
|
|
|
*/
|
|
|
|
static void Clean();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release a reference to the resource handle
|
|
|
|
* @param resource The handle to release.
|
|
|
|
* @return Nothing
|
|
|
|
*/
|
|
|
|
static void ReleaseResource(const OHRESOURCE& resource);
|
|
|
|
|
|
|
|
/** Set a user defined ID
|
|
|
|
* @param resource A handle to accociate the id with.
|
|
|
|
* @param id A user defined identifier that the resource handler does not touch.
|
|
|
|
*/
|
|
|
|
static void SetResourceId(const OHRESOURCE& resource, unsigned int id);
|
|
|
|
|
|
|
|
/** Get a resource type given a OHRESOURCE handle
|
|
|
|
* @param resource The handle to check
|
|
|
|
* @return Returns the resource type of the handle
|
|
|
|
*/
|
|
|
|
static ResourceType GetResourceType(const OHRESOURCE& resource);
|
|
|
|
|
|
|
|
/** Get a resource filename given a OHRESOURCE handle
|
|
|
|
* @param resource The handle to check
|
|
|
|
* @return Returns the accociated filename
|
|
|
|
*/
|
|
|
|
static const wchar_t* GetResourceFilename(const OHRESOURCE& resource);
|
|
|
|
|
|
|
|
/** Get a user defined ID accociated with a handle
|
|
|
|
* @param resource The handle to check
|
|
|
|
* @return Returns the accociated ID
|
|
|
|
*/
|
|
|
|
static unsigned int GetResourceId(const OHRESOURCE& resource);
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|