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
;
65 // the file name currently being searched for, i.e. the argument of the
66 // last FindFirst() call or empty string if FindFirst() hasn't been called
67 // yet or FindNext() didn't find anything
68 wxString m_findArgument
;
70 // iterator into m_Hash used by FindFirst/Next(), possibly m_Hash.end() or
71 // even invalid (can only be used when m_findArgument is not empty)
72 wxMemoryFSHash::const_iterator m_findIter
;
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
81 // add GUI-only operations to the base class
82 class WXDLLIMPEXP_CORE wxMemoryFSHandler
: public wxMemoryFSHandlerBase
85 // bring the base class versions into the scope, otherwise they would be
86 // inaccessible in wxMemoryFSHandler
87 // (unfortunately "using" can't be used as gcc 2.95 doesn't have it...)
88 static void AddFile(const wxString
& filename
, const wxString
& textdata
)
90 wxMemoryFSHandlerBase::AddFile(filename
, textdata
);
93 static void AddFile(const wxString
& filename
,
94 const void *binarydata
,
97 wxMemoryFSHandlerBase::AddFile(filename
, binarydata
, size
);
99 static void AddFileWithMimeType(const wxString
& filename
,
100 const wxString
& textdata
,
101 const wxString
& mimetype
)
103 wxMemoryFSHandlerBase::AddFileWithMimeType(filename
,
107 static void AddFileWithMimeType(const wxString
& filename
,
108 const void *binarydata
, size_t size
,
109 const wxString
& mimetype
)
111 wxMemoryFSHandlerBase::AddFileWithMimeType(filename
,
117 static void AddFile(const wxString
& filename
,
118 const wxImage
& image
,
121 static void AddFile(const wxString
& filename
,
122 const wxBitmap
& bitmap
,
124 #endif // wxUSE_IMAGE
130 // just the same thing as the base class in wxBase
131 class WXDLLIMPEXP_BASE wxMemoryFSHandler
: public wxMemoryFSHandlerBase
135 #endif // wxUSE_GUI/!wxUSE_GUI
137 #endif // wxUSE_FILESYSTEM
139 #endif // _WX_FS_MEM_H_