From: Vadim Zeitlin Date: Mon, 6 Oct 2008 13:55:39 +0000 (+0000) Subject: implemented wxMemoryFSHandler::FindFirst/Next() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fcc65883db459e0261bb49b1e6719dc95577aeaf implemented wxMemoryFSHandler::FindFirst/Next() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56120 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index d377bf8695..95ffa32070 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -267,6 +267,7 @@ All: - Added wxMutex::LockTimeout() (Aleksandr Napylov). - Added wxMemoryInputStream(wxInputStream&) ctor (Stas Sergeev). - Implemented wxMemoryInputStream::CanRead(). +- Implemented wxMemoryFSHandler::FindFirst/Next(). - Added wxEXEC_BLOCK flag (Hank Schultz). - Add support for wxStream-derived classes to wxRTTI (Stas Sergeev). - Added wxStreamBuffer::Truncate() (Stas Sergeev). diff --git a/include/wx/fs_mem.h b/include/wx/fs_mem.h index cdfc35cc81..4c478b759b 100644 --- a/include/wx/fs_mem.h +++ b/include/wx/fs_mem.h @@ -61,6 +61,15 @@ protected: // the hash map indexed by the names of the files stored in the memory FS static wxMemoryFSHash m_Hash; + + // the file name currently being searched for, i.e. the argument of the + // last FindFirst() call or empty string if FindFirst() hasn't been called + // yet or FindNext() didn't find anything + wxString m_findArgument; + + // iterator into m_Hash used by FindFirst/Next(), possibly m_Hash.end() or + // even invalid (can only be used when m_findArgument is not empty) + wxMemoryFSHash::const_iterator m_findIter; }; // ---------------------------------------------------------------------------- diff --git a/src/common/fs_mem.cpp b/src/common/fs_mem.cpp index 41cc094434..f13ab26c5d 100644 --- a/src/common/fs_mem.cpp +++ b/src/common/fs_mem.cpp @@ -122,19 +122,47 @@ wxFSFile * wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs), ); } -wxString wxMemoryFSHandlerBase::FindFirst(const wxString& WXUNUSED(spec), - int WXUNUSED(flags)) +wxString wxMemoryFSHandlerBase::FindFirst(const wxString& spec, int flags) { - wxFAIL_MSG(wxT("wxMemoryFSHandlerBase::FindFirst not implemented")); + if ( (flags & wxDIR) && !(flags & wxFILE) ) + { + // we only store files, not directories, so we don't risk finding + // anything + return wxString(); + } + + if ( spec.find_first_of("?*") == wxString::npos ) + { + // simple case: there are no wildcard characters so we can return + // either 0 or 1 results and we can find the potential match quickly + return m_Hash.count(spec) ? spec : wxString(); + } + //else: deal with wildcards in FindNext() - return wxEmptyString; + m_findArgument = spec; + m_findIter = m_Hash.begin(); + + return FindNext(); } wxString wxMemoryFSHandlerBase::FindNext() { - wxFAIL_MSG(wxT("wxMemoryFSHandlerBase::FindNext not implemented")); + // m_findArgument is used to indicate that search is in progress, we reset + // it to empty string after iterating over all elements + while ( !m_findArgument.empty() ) + { + // advance m_findIter before checking the value at the current position + // as we need to do it anyhow, whether it matches or not + const wxMemoryFSHash::const_iterator current = m_findIter; + + if ( ++m_findIter == m_Hash.end() ) + m_findArgument.clear(); + + if ( current->first.Matches(m_findArgument) ) + return current->first; + } - return wxEmptyString; + return wxString(); } bool wxMemoryFSHandlerBase::CheckDoesntExist(const wxString& filename)