rewrite using type safe wxHashMap instead of wxObject-based wxHashTable
[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 class wxMemoryFSHash;
19
20 #if wxUSE_GUI
21 #include "wx/bitmap.h"
22 #endif // wxUSE_GUI
23
24 // ----------------------------------------------------------------------------
25 // wxMemoryFSHandlerBase
26 // ----------------------------------------------------------------------------
27
28 class WXDLLIMPEXP_BASE wxMemoryFSHandlerBase : public wxFileSystemHandler
29 {
30 public:
31 wxMemoryFSHandlerBase();
32 virtual ~wxMemoryFSHandlerBase();
33
34 // Add file to list of files stored in memory. Stored data (bitmap, text or
35 // raw data) will be copied into private memory stream and available under
36 // name "memory:" + filename
37 static void AddFile(const wxString& filename, const wxString& textdata);
38 static void AddFile(const wxString& filename, const void *binarydata, size_t size);
39 static void AddFileWithMimeType(const wxString& filename,
40 const wxString& textdata,
41 const wxString& mimetype);
42 static void AddFileWithMimeType(const wxString& filename,
43 const void *binarydata, size_t size,
44 const wxString& mimetype);
45
46 // Remove file from memory FS and free occupied memory
47 static void RemoveFile(const wxString& filename);
48
49 virtual bool CanOpen(const wxString& location);
50 virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
51 virtual wxString FindFirst(const wxString& spec, int flags = 0);
52 virtual wxString FindNext();
53
54 protected:
55 static bool CheckHash(const wxString& filename);
56 static wxMemoryFSHash *m_Hash;
57 };
58
59 // ----------------------------------------------------------------------------
60 // wxMemoryFSHandler
61 // ----------------------------------------------------------------------------
62
63 #if wxUSE_GUI
64
65 // add GUI-only operations to the base class
66 class WXDLLIMPEXP_CORE wxMemoryFSHandler : public wxMemoryFSHandlerBase
67 {
68 public:
69 // bring the base class versions into the scope, otherwise they would be
70 // inaccessible in wxMemoryFSHandler
71 // (unfortunately "using" can't be used as gcc 2.95 doesn't have it...)
72 static void AddFile(const wxString& filename, const wxString& textdata)
73 {
74 wxMemoryFSHandlerBase::AddFile(filename, textdata);
75 }
76
77 static void AddFile(const wxString& filename,
78 const void *binarydata,
79 size_t size)
80 {
81 wxMemoryFSHandlerBase::AddFile(filename, binarydata, size);
82 }
83 static void AddFileWithMimeType(const wxString& filename,
84 const wxString& textdata,
85 const wxString& mimetype)
86 {
87 wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
88 textdata,
89 mimetype);
90 }
91 static void AddFileWithMimeType(const wxString& filename,
92 const void *binarydata, size_t size,
93 const wxString& mimetype)
94 {
95 wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
96 binarydata, size,
97 mimetype);
98 }
99
100 #if wxUSE_IMAGE
101 static void AddFile(const wxString& filename,
102 const wxImage& image,
103 wxBitmapType type);
104
105 static void AddFile(const wxString& filename,
106 const wxBitmap& bitmap,
107 wxBitmapType type);
108 #endif // wxUSE_IMAGE
109
110 };
111
112 #else // !wxUSE_GUI
113
114 // just the same thing as the base class in wxBase
115 class WXDLLIMPEXP_BASE wxMemoryFSHandler : public wxMemoryFSHandlerBase
116 {
117 };
118
119 #endif // wxUSE_GUI/!wxUSE_GUI
120
121 #endif // wxUSE_FILESYSTEM
122
123 #endif // _WX_FS_MEM_H_
124