PVRTMemoryFileSystem.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /******************************************************************************
  2. @File PVRTMemoryFileSystem.h
  3. @Title PVRTMemoryFileSystem
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description Memory file system for resource files
  8. ******************************************************************************/
  9. #ifndef _PVRTMEMORYFILE_H_
  10. #define _PVRTMEMORYFILE_H_
  11. #include "PVRTGlobal.h"
  12. #include <stddef.h>
  13. class CPVRTMemoryFileSystem
  14. {
  15. public:
  16. CPVRTMemoryFileSystem(const char* pszFilename, const void* pBuffer, size_t Size, bool bCopy = false);
  17. /*!***************************************************************************
  18. @Function RegisterMemoryFile
  19. @Input pszFilename Name of file to register
  20. @Input pBuffer Pointer to file data
  21. @Input Size File size
  22. @Input bCopy Name and data should be copied?
  23. @Description Registers a block of memory as a file that can be looked up
  24. by name.
  25. *****************************************************************************/
  26. static void RegisterMemoryFile(const char* pszFilename, const void* pBuffer, size_t Size, bool bCopy = false);
  27. /*!***************************************************************************
  28. @Function GetFile
  29. @Input pszFilename Name of file to open
  30. @Output ppBuffer Pointer to file data
  31. @Output pSize File size
  32. @Return true if the file was found in memory, false otherwise
  33. @Description Looks up a file in the memory file system by name. Returns a
  34. pointer to the file data as well as its size on success.
  35. *****************************************************************************/
  36. static bool GetFile(const char* pszFilename, const void** ppBuffer, size_t* pSize);
  37. /*!***************************************************************************
  38. @Function GetNumFiles
  39. @Return The number of registered files
  40. @Description Getter for the number of registered files
  41. *****************************************************************************/
  42. static int GetNumFiles();
  43. /*!***************************************************************************
  44. @Function GetFilename
  45. @Input i32Index Index of file
  46. @Return A pointer to the filename of the requested file
  47. @Description 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 const char* GetFilename(int i32Index);
  51. protected:
  52. class CAtExit
  53. {
  54. public:
  55. /*!***************************************************************************
  56. @Function Destructor
  57. @Description Destructor of CAtExit class. Workaround for platforms that
  58. don't support the atexit() function. This deletes any memory
  59. file system data.
  60. *****************************************************************************/
  61. ~CAtExit();
  62. };
  63. static CAtExit s_AtExit;
  64. friend class CAtExit;
  65. struct SFileInfo
  66. {
  67. const char* pszFilename;
  68. const void* pBuffer;
  69. size_t Size;
  70. bool bAllocated;
  71. };
  72. static SFileInfo* s_pFileInfo;
  73. static int s_i32NumFiles;
  74. static int s_i32Capacity;
  75. };
  76. #endif // _PVRTMEMORYFILE_H_
  77. /*****************************************************************************
  78. End of file (PVRTMemoryFileSystem.h)
  79. *****************************************************************************/