• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!****************************************************************************
2 
3  @file         PVRTMemoryFileSystem.h
4  @copyright    Copyright (c) Imagination Technologies Limited.
5  @brief        Memory file system for resource files.
6 
7 ******************************************************************************/
8 #ifndef _PVRTMEMORYFILE_H_
9 #define _PVRTMEMORYFILE_H_
10 
11 #include "PVRTGlobal.h"
12 #include <stddef.h>
13 
14 /*!****************************************************************************
15  @class        CPVRTMemoryFileSystem
16  @brief        Memory file system for resource files.
17 ******************************************************************************/
18 class CPVRTMemoryFileSystem
19 {
20 public:
21 	/*!***************************************************************************
22      @brief      	Constructor. Creates a CPVRTMemoryFileSystem object based on the parameters supplied.
23 	 @param[in]		pszFilename		Name of file to register
24 	 @param[in]		pBuffer			Pointer to file data
25 	 @param[in]		Size			File size
26 	 @param[in]		bCopy			Name and data should be copied?
27 	*****************************************************************************/
28     CPVRTMemoryFileSystem(const char* pszFilename, const void* pBuffer, size_t Size, bool bCopy = false);
29 
30 	/*!***************************************************************************
31 	 @fn           	RegisterMemoryFile
32 	 @param[in]		pszFilename		Name of file to register
33 	 @param[in]		pBuffer			Pointer to file data
34 	 @param[in]		Size			File size
35 	 @param[in]		bCopy			Name and data should be copied?
36 	 @brief      	Registers a block of memory as a file that can be looked up
37 	                by name.
38 	*****************************************************************************/
39 	static void RegisterMemoryFile(const char* pszFilename, const void* pBuffer, size_t Size, bool bCopy = false);
40 
41 	/*!***************************************************************************
42 	 @fn           	GetFile
43 	 @param[in]		pszFilename		Name of file to open
44 	 @param[out]	ppBuffer		Pointer to file data
45 	 @param[out]	pSize			File size
46 	 @return		true if the file was found in memory, false otherwise
47 	 @brief      	Looks up a file in the memory file system by name. Returns a
48 	                pointer to the file data as well as its size on success.
49 	*****************************************************************************/
50 	static bool GetFile(const char* pszFilename, const void** ppBuffer, size_t* pSize);
51 
52 	/*!***************************************************************************
53 	 @fn           	GetNumFiles
54 	 @return		The number of registered files
55 	 @brief      	Getter for the number of registered files
56 	*****************************************************************************/
57 	static int GetNumFiles();
58 
59 	/*!***************************************************************************
60 	 @fn           	GetFilename
61 	 @param[in]		i32Index		Index of file
62 	 @return		A pointer to the filename of the requested file
63 	 @brief      	Looks up a file in the memory file system by name. Returns a
64 	                pointer to the file data as well as its size on success.
65 	*****************************************************************************/
66 	static const char* GetFilename(int i32Index);
67 
68 protected:
69     /*!***************************************************************************
70 	 @class         CAtExit
71 	 @brief      	Provides a deconstructor for platforms that don't support the atexit() function.
72 	*****************************************************************************/
73 	class CAtExit
74 	{
75 	public:
76 		/*!***************************************************************************
77 		@brief      Destructor of CAtExit class. Workaround for platforms that
78 		            don't support the atexit() function. This deletes any memory
79 					file system data.
80 		*****************************************************************************/
81 		~CAtExit();
82 	};
83 	static CAtExit s_AtExit;
84 
85 	friend class CAtExit;
86 
87     /*!***************************************************************************
88 	 @struct        SFileInfo
89 	 @brief      	Struct which contains information on a single file.
90 	*****************************************************************************/
91 	struct SFileInfo
92 	{
93 		const char* pszFilename;        ///< File name.
94 		const void* pBuffer;            ///< Pointer to file data.
95 		size_t Size;                    ///< File size.
96 		bool bAllocated;                ///< File was allocated. If true, this file will be deleted on exit.
97 	};
98 	static SFileInfo* s_pFileInfo;
99 	static int s_i32NumFiles;
100 	static int s_i32Capacity;
101 };
102 
103 #endif // _PVRTMEMORYFILE_H_
104 
105 /*****************************************************************************
106  End of file (PVRTMemoryFileSystem.h)
107 *****************************************************************************/
108 
109