Home | History | Annotate | Download | only in Tools
      1 /*!****************************************************************************
      2 
      3  @file         PVRTResourceFile.h
      4  @copyright    Copyright (c) Imagination Technologies Limited.
      5  @brief        Simple resource file wrapper
      6 
      7 ******************************************************************************/
      8 #ifndef _PVRTRESOURCEFILE_H_
      9 #define _PVRTRESOURCEFILE_H_
     10 
     11 #include <stdlib.h>
     12 #include "PVRTString.h"
     13 
     14 typedef void* (*PFNLoadFileFunc)(const char*, char** pData, size_t &size);
     15 typedef bool  (*PFNReleaseFileFunc)(void* handle);
     16 
     17 /*!***************************************************************************
     18  @class CPVRTResourceFile
     19  @brief Simple resource file wrapper
     20 *****************************************************************************/
     21 class CPVRTResourceFile
     22 {
     23 public:
     24 	/*!***************************************************************************
     25 	@fn       			SetReadPath
     26 	@param[in]			pszReadPath The path where you would like to read from
     27 	@brief      		Sets the read path
     28 	*****************************************************************************/
     29 	static void SetReadPath(const char* pszReadPath);
     30 
     31 	/*!***************************************************************************
     32 	@fn       			GetReadPath
     33 	@return 			The currently set read path
     34 	@brief      		Returns the currently set read path
     35 	*****************************************************************************/
     36 	static CPVRTString GetReadPath();
     37 
     38 	/*!***************************************************************************
     39 	@fn       			SetLoadReleaseFunctions
     40 	@param[in]			pLoadFileFunc Function to use for opening a file
     41 	@param[in]			pReleaseFileFunc Function to release any data allocated by the load function
     42 	@brief      		This function is used to override the CPVRTResource file loading functions. If
     43 	                    you pass NULL in as the load function CPVRTResource will use the default functions.
     44 	*****************************************************************************/
     45 	static void SetLoadReleaseFunctions(void* pLoadFileFunc, void* pReleaseFileFunc);
     46 
     47 	/*!***************************************************************************
     48 	@brief     			CPVRTResourceFile constructor
     49 	@param[in]			pszFilename Name of the file you would like to open
     50 	*****************************************************************************/
     51 	CPVRTResourceFile(const char* pszFilename);
     52 
     53 	/*!***************************************************************************
     54 	@brief     			CPVRTResourceFile constructor
     55 	@param[in]			pData A pointer to the data you would like to use
     56 	@param[in]			i32Size The size of the data
     57 	*****************************************************************************/
     58 	CPVRTResourceFile(const char* pData, size_t i32Size);
     59 
     60 	/*!***************************************************************************
     61 	@fn       			~CPVRTResourceFile
     62 	@brief      		Destructor
     63 	*****************************************************************************/
     64 	virtual ~CPVRTResourceFile();
     65 
     66 	/*!***************************************************************************
     67 	@fn       			IsOpen
     68 	@return 			true if the file is open
     69 	@brief      		Is the file open
     70 	*****************************************************************************/
     71 	bool IsOpen() const;
     72 
     73 	/*!***************************************************************************
     74 	@fn       			IsMemoryFile
     75 	@return 			true if the file was opened from memory
     76 	@brief      		Was the file opened from memory
     77 	*****************************************************************************/
     78 	bool IsMemoryFile() const;
     79 
     80 	/*!***************************************************************************
     81 	@fn       			Size
     82 	@return 			The size of the opened file
     83 	@brief      		Returns the size of the opened file
     84 	*****************************************************************************/
     85 	size_t Size() const;
     86 
     87 	/*!***************************************************************************
     88 	@fn       			DataPtr
     89 	@return 			A pointer to the file data
     90 	@brief      		Returns a pointer to the file data. If the data is expected
     91 						to be a string don't assume that it is null-terminated.
     92 	*****************************************************************************/
     93 	const void* DataPtr() const;
     94 
     95 	/*!***************************************************************************
     96 	@fn       			Close
     97 	@brief      		Closes the file
     98 	*****************************************************************************/
     99 	void Close();
    100 
    101 protected:
    102 	bool m_bOpen;
    103 	bool m_bMemoryFile;
    104 	size_t m_Size;
    105 	const char* m_pData;
    106 	void *m_Handle;
    107 
    108 	static CPVRTString s_ReadPath;
    109 	static PFNLoadFileFunc s_pLoadFileFunc;
    110 	static PFNReleaseFileFunc s_pReleaseFileFunc;
    111 };
    112 
    113 #endif // _PVRTRESOURCEFILE_H_
    114 
    115 /*****************************************************************************
    116  End of file (PVRTResourceFile.h)
    117 *****************************************************************************/
    118 
    119