fs_mem.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/fs_mem.h
  3. // Purpose: in-memory file system
  4. // Author: Vaclav Slavik
  5. // Copyright: (c) 2000 Vaclav Slavik
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_FS_MEM_H_
  9. #define _WX_FS_MEM_H_
  10. #include "wx/defs.h"
  11. #if wxUSE_FILESYSTEM
  12. #include "wx/filesys.h"
  13. #include "wx/hashmap.h"
  14. class wxMemoryFSFile;
  15. WX_DECLARE_STRING_HASH_MAP(wxMemoryFSFile *, wxMemoryFSHash);
  16. #if wxUSE_GUI
  17. #include "wx/bitmap.h"
  18. #endif // wxUSE_GUI
  19. // ----------------------------------------------------------------------------
  20. // wxMemoryFSHandlerBase
  21. // ----------------------------------------------------------------------------
  22. class WXDLLIMPEXP_BASE wxMemoryFSHandlerBase : public wxFileSystemHandler
  23. {
  24. public:
  25. wxMemoryFSHandlerBase();
  26. virtual ~wxMemoryFSHandlerBase();
  27. // Add file to list of files stored in memory. Stored data (bitmap, text or
  28. // raw data) will be copied into private memory stream and available under
  29. // name "memory:" + filename
  30. static void AddFile(const wxString& filename, const wxString& textdata);
  31. static void AddFile(const wxString& filename, const void *binarydata, size_t size);
  32. static void AddFileWithMimeType(const wxString& filename,
  33. const wxString& textdata,
  34. const wxString& mimetype);
  35. static void AddFileWithMimeType(const wxString& filename,
  36. const void *binarydata, size_t size,
  37. const wxString& mimetype);
  38. // Remove file from memory FS and free occupied memory
  39. static void RemoveFile(const wxString& filename);
  40. virtual bool CanOpen(const wxString& location);
  41. virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
  42. virtual wxString FindFirst(const wxString& spec, int flags = 0);
  43. virtual wxString FindNext();
  44. protected:
  45. // check that the given file is not already present in m_Hash; logs an
  46. // error and returns false if it does exist
  47. static bool CheckDoesntExist(const wxString& filename);
  48. // the hash map indexed by the names of the files stored in the memory FS
  49. static wxMemoryFSHash m_Hash;
  50. // the file name currently being searched for, i.e. the argument of the
  51. // last FindFirst() call or empty string if FindFirst() hasn't been called
  52. // yet or FindNext() didn't find anything
  53. wxString m_findArgument;
  54. // iterator into m_Hash used by FindFirst/Next(), possibly m_Hash.end() or
  55. // even invalid (can only be used when m_findArgument is not empty)
  56. wxMemoryFSHash::const_iterator m_findIter;
  57. };
  58. // ----------------------------------------------------------------------------
  59. // wxMemoryFSHandler
  60. // ----------------------------------------------------------------------------
  61. #if wxUSE_GUI
  62. // add GUI-only operations to the base class
  63. class WXDLLIMPEXP_CORE wxMemoryFSHandler : public wxMemoryFSHandlerBase
  64. {
  65. public:
  66. // bring the base class versions into the scope, otherwise they would be
  67. // inaccessible in wxMemoryFSHandler
  68. // (unfortunately "using" can't be used as gcc 2.95 doesn't have it...)
  69. static void AddFile(const wxString& filename, const wxString& textdata)
  70. {
  71. wxMemoryFSHandlerBase::AddFile(filename, textdata);
  72. }
  73. static void AddFile(const wxString& filename,
  74. const void *binarydata,
  75. size_t size)
  76. {
  77. wxMemoryFSHandlerBase::AddFile(filename, binarydata, size);
  78. }
  79. static void AddFileWithMimeType(const wxString& filename,
  80. const wxString& textdata,
  81. const wxString& mimetype)
  82. {
  83. wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
  84. textdata,
  85. mimetype);
  86. }
  87. static void AddFileWithMimeType(const wxString& filename,
  88. const void *binarydata, size_t size,
  89. const wxString& mimetype)
  90. {
  91. wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
  92. binarydata, size,
  93. mimetype);
  94. }
  95. #if wxUSE_IMAGE
  96. static void AddFile(const wxString& filename,
  97. const wxImage& image,
  98. wxBitmapType type);
  99. static void AddFile(const wxString& filename,
  100. const wxBitmap& bitmap,
  101. wxBitmapType type);
  102. #endif // wxUSE_IMAGE
  103. };
  104. #else // !wxUSE_GUI
  105. // just the same thing as the base class in wxBase
  106. class WXDLLIMPEXP_BASE wxMemoryFSHandler : public wxMemoryFSHandlerBase
  107. {
  108. };
  109. #endif // wxUSE_GUI/!wxUSE_GUI
  110. #endif // wxUSE_FILESYSTEM
  111. #endif // _WX_FS_MEM_H_