1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: in-memory file system
4 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/filesys.h"
18 #include "wx/hashmap.h"
21 WX_DECLARE_STRING_HASH_MAP(wxMemoryFSFile
*, wxMemoryFSHash
);
24 #include "wx/bitmap.h"
27 // ----------------------------------------------------------------------------
28 // wxMemoryFSHandlerBase
29 // ----------------------------------------------------------------------------
31 class WXDLLIMPEXP_BASE wxMemoryFSHandlerBase
: public wxFileSystemHandler
34 wxMemoryFSHandlerBase();
35 virtual ~wxMemoryFSHandlerBase();
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
);
49 // Remove file from memory FS and free occupied memory
50 static void RemoveFile(const wxString
& filename
);
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();
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
);
62 // the hash map indexed by the names of the files stored in the memory FS
63 static wxMemoryFSHash m_Hash
;
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
72 // add GUI-only operations to the base class
73 class WXDLLIMPEXP_CORE wxMemoryFSHandler
: public wxMemoryFSHandlerBase
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
)
81 wxMemoryFSHandlerBase
::AddFile(filename
, textdata
);
84 static void AddFile(const wxString
& filename
,
85 const void *binarydata
,
88 wxMemoryFSHandlerBase
::AddFile(filename
, binarydata
, size
);
90 static void AddFileWithMimeType(const wxString
& filename
,
91 const wxString
& textdata
,
92 const wxString
& mimetype
)
94 wxMemoryFSHandlerBase
::AddFileWithMimeType(filename
,
98 static void AddFileWithMimeType(const wxString
& filename
,
99 const void *binarydata
, size_t size
,
100 const wxString
& mimetype
)
102 wxMemoryFSHandlerBase
::AddFileWithMimeType(filename
,
108 static void AddFile(const wxString
& filename
,
109 const wxImage
& image
,
112 static void AddFile(const wxString
& filename
,
113 const wxBitmap
& bitmap
,
115 #endif // wxUSE_IMAGE
121 // just the same thing as the base class in wxBase
122 class WXDLLIMPEXP_BASE wxMemoryFSHandler
: public wxMemoryFSHandlerBase
126 #endif // wxUSE_GUI/!wxUSE_GUI
128 #endif // wxUSE_FILESYSTEM
130 #endif // _WX_FS_MEM_H_