rewrite using type safe wxHashMap instead of wxObject-based wxHashTable
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56117 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#include "wx/filesys.h"
|
#include "wx/filesys.h"
|
||||||
|
|
||||||
|
class wxMemoryFSHash;
|
||||||
|
|
||||||
#if wxUSE_GUI
|
#if wxUSE_GUI
|
||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
#endif // wxUSE_GUI
|
#endif // wxUSE_GUI
|
||||||
@@ -51,7 +53,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool CheckHash(const wxString& filename);
|
static bool CheckHash(const wxString& filename);
|
||||||
static wxHashTable *m_Hash;
|
static wxMemoryFSHash *m_Hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/hash.h"
|
#include "wx/hashmap.h"
|
||||||
#include "wx/wxcrtvararg.h"
|
#include "wx/wxcrtvararg.h"
|
||||||
#if wxUSE_GUI
|
#if wxUSE_GUI
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include "wx/mstream.h"
|
#include "wx/mstream.h"
|
||||||
|
|
||||||
class MemFSHashObj : public wxObject
|
class MemFSHashObj
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MemFSHashObj(const void *data, size_t len, const wxString& mime)
|
MemFSHashObj(const void *data, size_t len, const wxString& mime)
|
||||||
@@ -73,6 +73,8 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WX_DECLARE_STRING_HASH_MAP(MemFSHashObj *, wxMemoryFSHash);
|
||||||
|
|
||||||
#if wxUSE_BASE
|
#if wxUSE_BASE
|
||||||
|
|
||||||
|
|
||||||
@@ -81,7 +83,7 @@ private:
|
|||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
wxHashTable *wxMemoryFSHandlerBase::m_Hash = NULL;
|
wxMemoryFSHash *wxMemoryFSHandlerBase::m_Hash = NULL;
|
||||||
|
|
||||||
|
|
||||||
wxMemoryFSHandlerBase::wxMemoryFSHandlerBase() : wxFileSystemHandler()
|
wxMemoryFSHandlerBase::wxMemoryFSHandlerBase() : wxFileSystemHandler()
|
||||||
@@ -96,7 +98,7 @@ wxMemoryFSHandlerBase::~wxMemoryFSHandlerBase()
|
|||||||
|
|
||||||
if (m_Hash)
|
if (m_Hash)
|
||||||
{
|
{
|
||||||
WX_CLEAR_HASH_TABLE(*m_Hash);
|
WX_CLEAR_HASH_MAP(wxMemoryFSHash, *m_Hash);
|
||||||
delete m_Hash;
|
delete m_Hash;
|
||||||
m_Hash = NULL;
|
m_Hash = NULL;
|
||||||
}
|
}
|
||||||
@@ -113,18 +115,22 @@ wxFSFile * wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs),
|
|||||||
if ( !m_Hash )
|
if ( !m_Hash )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MemFSHashObj *obj = (MemFSHashObj*) m_Hash->Get(GetRightLocation(location));
|
wxMemoryFSHash::const_iterator i = m_Hash->find(GetRightLocation(location));
|
||||||
if ( !obj )
|
if ( i == m_Hash->end() )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
else return new wxFSFile(new wxMemoryInputStream(obj->m_Data, obj->m_Len),
|
const MemFSHashObj * const obj = i->second;
|
||||||
location,
|
|
||||||
obj->m_MimeType,
|
return new wxFSFile
|
||||||
GetAnchor(location)
|
(
|
||||||
|
new wxMemoryInputStream(obj->m_Data, obj->m_Len),
|
||||||
|
location,
|
||||||
|
obj->m_MimeType,
|
||||||
|
GetAnchor(location)
|
||||||
#if wxUSE_DATETIME
|
#if wxUSE_DATETIME
|
||||||
, obj->m_Time
|
, obj->m_Time
|
||||||
#endif // wxUSE_DATETIME
|
#endif // wxUSE_DATETIME
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxMemoryFSHandlerBase::FindFirst(const wxString& WXUNUSED(spec),
|
wxString wxMemoryFSHandlerBase::FindFirst(const wxString& WXUNUSED(spec),
|
||||||
@@ -145,11 +151,9 @@ wxString wxMemoryFSHandlerBase::FindNext()
|
|||||||
bool wxMemoryFSHandlerBase::CheckHash(const wxString& filename)
|
bool wxMemoryFSHandlerBase::CheckHash(const wxString& filename)
|
||||||
{
|
{
|
||||||
if ( !m_Hash )
|
if ( !m_Hash )
|
||||||
{
|
m_Hash = new wxMemoryFSHash;
|
||||||
m_Hash = new wxHashTable(wxKEY_STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_Hash->Get(filename) )
|
if ( m_Hash->count(filename) )
|
||||||
{
|
{
|
||||||
wxLogError(_("Memory VFS already contains file '%s'!"), filename);
|
wxLogError(_("Memory VFS already contains file '%s'!"), filename);
|
||||||
return false;
|
return false;
|
||||||
@@ -178,7 +182,7 @@ void wxMemoryFSHandlerBase::AddFileWithMimeType(const wxString& filename,
|
|||||||
if ( !CheckHash(filename) )
|
if ( !CheckHash(filename) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_Hash->Put(filename, new MemFSHashObj(binarydata, size, mimetype));
|
(*m_Hash)[filename] = new MemFSHashObj(binarydata, size, mimetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
@@ -200,16 +204,19 @@ void wxMemoryFSHandlerBase::AddFile(const wxString& filename,
|
|||||||
|
|
||||||
/*static*/ void wxMemoryFSHandlerBase::RemoveFile(const wxString& filename)
|
/*static*/ void wxMemoryFSHandlerBase::RemoveFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
if ( !m_Hash || !m_Hash->Get(filename) )
|
if ( m_Hash )
|
||||||
{
|
{
|
||||||
wxLogError(_("Trying to remove file '%s' from memory VFS, "
|
wxMemoryFSHash::iterator i = m_Hash->find(filename);
|
||||||
"but it is not loaded!"),
|
if ( i != m_Hash->end() )
|
||||||
filename);
|
{
|
||||||
}
|
delete i->second;
|
||||||
else
|
m_Hash->erase(i);
|
||||||
{
|
}
|
||||||
delete m_Hash->Delete(filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxLogError(_("Trying to remove file '%s' from memory VFS, "
|
||||||
|
"but it is not loaded!"),
|
||||||
|
filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_BASE
|
#endif // wxUSE_BASE
|
||||||
@@ -226,17 +233,13 @@ wxMemoryFSHandler::AddFile(const wxString& filename,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
wxMemoryOutputStream mems;
|
wxMemoryOutputStream mems;
|
||||||
if (image.Ok() && image.SaveFile(mems, type))
|
if ( image.Ok() && image.SaveFile(mems, type) )
|
||||||
{
|
{
|
||||||
m_Hash->Put
|
(*m_Hash)[filename] = new MemFSHashObj
|
||||||
(
|
(
|
||||||
filename,
|
mems,
|
||||||
new MemFSHashObj
|
wxImage::FindHandler(type)->GetMimeType()
|
||||||
(
|
);
|
||||||
mems,
|
|
||||||
wxImage::FindHandler(type)->GetMimeType()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user