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