+private:
+ wxArchiveFSEntry *AddToCache(wxArchiveEntry *entry);
+ void CloseStreams();
+
+ int m_refcount;
+
+ wxArchiveFSEntryHash m_hash;
+ wxArchiveFSEntry *m_begin;
+ wxArchiveFSEntry **m_endptr;
+
+ wxBackingFile m_backer;
+ wxInputStream *m_stream;
+ wxArchiveInputStream *m_archive;
+};
+
+wxArchiveFSCacheDataImpl::wxArchiveFSCacheDataImpl(
+ const wxArchiveClassFactory& factory,
+ const wxBackingFile& backer)
+ : m_refcount(1),
+ m_begin(NULL),
+ m_endptr(&m_begin),
+ m_backer(backer),
+ m_stream(new wxBackedInputStream(backer)),
+ m_archive(factory.NewStream(*m_stream))
+{
+}
+
+wxArchiveFSCacheDataImpl::wxArchiveFSCacheDataImpl(
+ const wxArchiveClassFactory& factory,
+ wxInputStream *stream)
+ : m_refcount(1),
+ m_begin(NULL),
+ m_endptr(&m_begin),
+ m_stream(stream),
+ m_archive(factory.NewStream(*m_stream))
+{
+}
+
+wxArchiveFSCacheDataImpl::~wxArchiveFSCacheDataImpl()
+{
+ WX_CLEAR_HASH_MAP(wxArchiveFSEntryHash, m_hash);
+
+ wxArchiveFSEntry *entry = m_begin;
+
+ while (entry)
+ {
+ wxArchiveFSEntry *next = entry->next;
+ delete entry;
+ entry = next;
+ }
+
+ CloseStreams();
+}
+
+wxArchiveFSEntry *wxArchiveFSCacheDataImpl::AddToCache(wxArchiveEntry *entry)
+{
+ m_hash[entry->GetName()] = entry;
+ wxArchiveFSEntry *fse = new wxArchiveFSEntry;
+ *m_endptr = fse;
+ (*m_endptr)->entry = entry;
+ (*m_endptr)->next = NULL;
+ m_endptr = &(*m_endptr)->next;
+ return fse;
+}
+
+void wxArchiveFSCacheDataImpl::CloseStreams()
+{
+ delete m_archive;
+ m_archive = NULL;
+ delete m_stream;
+ m_stream = NULL;
+}
+
+wxArchiveEntry *wxArchiveFSCacheDataImpl::Get(const wxString& name)
+{
+ wxArchiveFSEntryHash::iterator it = m_hash.find(name);
+
+ if (it != m_hash.end())
+ return it->second;
+
+ if (!m_archive)
+ return NULL;
+
+ wxArchiveEntry *entry;
+
+ while ((entry = m_archive->GetNextEntry()) != NULL)
+ {
+ AddToCache(entry);
+
+ if (entry->GetName() == name)
+ return entry;
+ }
+
+ CloseStreams();
+
+ return NULL;
+}
+
+wxInputStream* wxArchiveFSCacheDataImpl::NewStream() const
+{
+ if (m_backer)
+ return new wxBackedInputStream(m_backer);
+ else
+ return NULL;
+}
+
+wxArchiveFSEntry *wxArchiveFSCacheDataImpl::GetNext(wxArchiveFSEntry *fse)
+{
+ wxArchiveFSEntry *next = fse ? fse->next : m_begin;
+
+ if (!next && m_archive)
+ {
+ wxArchiveEntry *entry = m_archive->GetNextEntry();
+
+ if (entry)
+ next = AddToCache(entry);
+ else
+ CloseStreams();
+ }
+
+ return next;
+}