made m_Hash object, not a pointer and moved hash declaration into the header as it...
[wxWidgets.git] / include / wx / fs_mem.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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
9 #ifndef _WX_FS_MEM_H_
10 #define _WX_FS_MEM_H_
11
12 #include "wx/defs.h"
13
14 #if wxUSE_FILESYSTEM
15
16 #include "wx/filesys.h"
17
18 #include "wx/hashmap.h"
19
20 class wxMemoryFSFile;
21 WX_DECLARE_STRING_HASH_MAP(wxMemoryFSFile *, wxMemoryFSHash);
22
23 #if wxUSE_GUI
24 #include "wx/bitmap.h"
25 #endif // wxUSE_GUI
26
27 // ----------------------------------------------------------------------------
28 // wxMemoryFSHandlerBase
29 // ----------------------------------------------------------------------------
30
31 class WXDLLIMPEXP_BASE wxMemoryFSHandlerBase : public wxFileSystemHandler
32 {
33 public:
34 wxMemoryFSHandlerBase();
35 virtual ~wxMemoryFSHandlerBase();
36
37 // Add file to list of files stored in memory. Stored data (bitmap, text or
38 // raw data) will be copied into private memory stream and available under
39 // name "memory:" + filename
40 static void AddFile(const wxString& filename, const wxString& textdata);
41 static void AddFile(const wxString& filename, const void *binarydata, size_t size);
42 static void AddFileWithMimeType(const wxString& filename,
43 const wxString& textdata,
44 const wxString& mimetype);
45 static void AddFileWithMimeType(const wxString& filename,
46 const void *binarydata, size_t size,
47 const wxString& mimetype);
48
49 // Remove file from memory FS and free occupied memory
50 static void RemoveFile(const wxString& filename);
51
52 virtual bool CanOpen(const wxString& location);
53 virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
54 virtual wxString FindFirst(const wxString& spec, int flags = 0);
55 virtual wxString FindNext();
56
57 protected:
58 // check that the given file is not already present in m_Hash; logs an
59 // error and returns false if it does exist
60 static bool CheckDoesntExist(const wxString& filename);
61
62 // the hash map indexed by the names of the files stored in the memory FS
63 static wxMemoryFSHash m_Hash;
64 };
65
66 // ----------------------------------------------------------------------------
67 // wxMemoryFSHandler
68 // ----------------------------------------------------------------------------
69
70 #if wxUSE_GUI
71
72 // add GUI-only operations to the base class
73 class WXDLLIMPEXP_CORE wxMemoryFSHandler : public wxMemoryFSHandlerBase
74 {
75 public:
76 // bring the base class versions into the scope, otherwise they would be
77 // inaccessible in wxMemoryFSHandler
78 // (unfortunately "using" can't be used as gcc 2.95 doesn't have it...)
79 static void AddFile(const wxString& filename, const wxString& textdata)
80 {
81 wxMemoryFSHandlerBase::AddFile(filename, textdata);
82 }
83
84 static void AddFile(const wxString& filename,
85 const void *binarydata,
86 size_t size)
87 {
88 wxMemoryFSHandlerBase::AddFile(filename, binarydata, size);
89 }
90 static void AddFileWithMimeType(const wxString& filename,
91 const wxString& textdata,
92 const wxString& mimetype)
93 {
94 wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
95 textdata,
96 mimetype);
97 }
98 static void AddFileWithMimeType(const wxString& filename,
99 const void *binarydata, size_t size,
100 const wxString& mimetype)
101 {
102 wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
103 binarydata, size,
104 mimetype);
105 }
106
107 #if wxUSE_IMAGE
108 static void AddFile(const wxString& filename,
109 const wxImage& image,
110 wxBitmapType type);
111
112 static void AddFile(const wxString& filename,
113 const wxBitmap& bitmap,
114 wxBitmapType type);
115 #endif // wxUSE_IMAGE
116
117 };
118
119 #else // !wxUSE_GUI
120
121 // just the same thing as the base class in wxBase
122 class WXDLLIMPEXP_BASE wxMemoryFSHandler : public wxMemoryFSHandlerBase
123 {
124 };
125
126 #endif // wxUSE_GUI/!wxUSE_GUI
127
128 #endif // wxUSE_FILESYSTEM
129
130 #endif // _WX_FS_MEM_H_
131