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