///////////////////////////////////////////////////////////////////////////////
/// @file deResource.hpp
///
/// @brief Global resource handler
///
/// @author Assassin
///
/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
/// contents of this file is subject to the Destiny3D Member License which
/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
///
/// This file is distributed "AS IS" without warranty of any kind.  Novus
/// Delta, LLC. does not guarantee the fitness of the contents of this file
/// for any particular purpose.
///
/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
///
/// <hr>
///                                 Change History
/// <hr>
///
/// @date Aug 2001
/// @author Assassin
/// @remarks Creation
///
/// @date Feb 2002
/// @author Hootie
/// @remarks Level 2 Singleton DLL Wrap
///
///////////////////////////////////////////////////////////////////////////////

#ifndef DERESOURCE_HPP
#define DERESOURCE_HPP



//=================================================================================
// Includes
//=================================================================================
#include "deGlobalTypes.hpp"


//=================================================================================
// DLL Import/Export Defines
//=================================================================================

#if defined(DERESOURCE_DLL_EXPORTS) || defined(DESTINY3D_EXPORT_ALL)
#	define DERESOURCE_API extern "C" DEDLL_EXPORT
#elif defined(DESTINY3D_STATIC_LINK)
#	define DERESOURCE_API extern "C"
#else
#	define DERESOURCE_API extern "C" DEDLL_IMPORT
#endif

#ifdef USING_DESTINY3D
#ifdef _DEBUG
#	ifdef DESTINY3D_STATIC_LINK
#		pragma comment(lib, "deResource_sd")
#	else
#		pragma comment(lib, "deResourced")
#	endif //DESTINY3D_STATIC_LINK
#else
#	ifdef DESTINY3D_STATIC_LINK
#		pragma comment(lib, "deResource_s")
#	else
#		pragma comment(lib, "deResource")
#	endif //DESTINY3D_STATIC_LINK
#endif //_DEBUG
#endif //USING_DESTINY3D

// get rid of the annoying diamond-inheritance warning
#pragma warning (disable : 4250)

//=================================================================================
// Forward declarations
//=================================================================================

class IdeResourceBase;
class IdeResourceManager;
class IdeFileSystem;
class IdeFile;


//=================================================================================
// Destiny Resource Manager Interface Factories
//=================================================================================

/// Retrieve the Resource Manager singleton
DERESOURCE_API IdeResourceManager *IdeResourceManager_GetManager();
DERESOURCE_API void IdeResourceManager_ShutDown();
/// a type to use to retrieve the function pointer
typedef IdeResourceManager* (*fIdeResourceManager_GetManager)();



//=================================================================================
// Typedefs
//=================================================================================

/// used to register file types
typedef IdeResourceBase *(*deResourceMakerCB)(const char *filename, IdeFile *file, deBoolean isThreaded);



//=================================================================================
// IdeResourceBase Class
//
// Interface class which all resource handling must be done through
//=================================================================================

/// Used for handling objects that can be created from files.
/// Related classes: IdeResourceManager.
//class IdeResourceBase : virtual public IdeRefCountBase
DE3D_INTERFACE(IdeResourceBase, IdeRefCountBase)
{
protected:
	virtual ~IdeResourceBase()  {};
public:
	/// Used to retrieve a pointer to an interface registered through IdeResourceManager.
	/// @return NULL or a valid pointer to an interface supported by this object
	/// @param interface_id A value previously retrieved through IdeResourceManager::GetUniqueInterfaceID
	virtual void * GetRscInterface(long interface_id) = 0;

	/// tells whether or not the object has been modified since it was loaded from file
	virtual deBoolean IsDirty(void) = 0;
	/// @return pointer to the object's internal name entry
	virtual const char *GetFilename(void) = 0;
	/// fills buffer with the filename of the object, until the entire name is stored
	///  or 'buffersize' characters are written
	virtual void GetFilenameBuffer(char *buffer, long buffersize) = 0;
	/// create a copy of the object in memory
	virtual IdeResourceBase *MakeCopy(void) = 0;

	//only for use by deResourceManager, otherwise BAD things happen
	virtual void SetHash(void *HashTable) = 0;
	virtual void *GetHash(void) = 0;
	virtual void SetManager(IdeResourceManager *Manager) = 0;
	virtual IdeResourceManager *GetManager(void) = 0;
};


//=================================================================================
// IdeResourceManager Class
//
// Resource Manager interface
//=================================================================================

/// the head honcho as far as resources are concerned.
/// Related functions: IdeResourceManager_GetManager.
/// Related classes: IdeResourceBase.
//class IdeResourceManager
DE3D_INTERFACE_(IdeResourceManager)
{
protected:
	virtual ~IdeResourceManager()  {};
public:
	/// Used by classes derived from IdeResourceBase to resolve interfaces
	/// @return a value that is unique relative to all other values returned by this method
	virtual long GetUniqueInterfaceID() = 0;
	/// Register a file extension so that files can be created from it
	/// @return deFalse on failure, deTrue on success
	/// @param extension a file extension in the form "bmp". The extension cannot contain dots
	/// @param maker a pointer to a function that will return an instance of the class associated with the extension
	virtual deBoolean RegisterResourceType(const char* extension, deResourceMakerCB maker) = 0;
	/// Retrieves a "clean" instance of the specified file
	/// @return Pointer to a "clean" object that has the filename specified. It may be created from a file
	///                 specified, or it may retrieve a pointer to an instance already in the internal database.
	/// @param filename A standard filename of the format "path/file.ext"
	/// @param filesystem Either NULL or a valid pointer to a filesystem to be searched for the filename.
	///                   If NULL is used, the behavior of the maker function may be undefined
	/// @param DoLoad If set to deFalse, the file will not be loaded if it does not already exist in memory
	virtual IdeResourceBase* GetResource(const char* filename, IdeFileSystem* filesystem, deBoolean doLoad = deTRUE) = 0;
	virtual IdeResourceBase* GetResourceThreaded(const char* filename, IdeFileSystem* filesystem, deBoolean doLoad = deTRUE) = 0;
	virtual IdeResourceBase* GetResourceFromFile(IdeFile* file, const char* filename, deBoolean record = deTRUE) = 0;
	virtual IdeResourceBase* GetResourceFromFileThreaded(IdeFile* file, const char* filename, deBoolean record = deTRUE) = 0;
	/// Removes a resource from the internal database
	/// @param resource a valid pointer to an object to remove
	virtual deBoolean RemoveResource(IdeResourceBase* resource) = 0;
	/// Will remove all the objects from the internal database
	virtual deBoolean RemoveAllResources(void) = 0;
};







#endif  //End: DERESOURCE_HPP

