Use std::unordered_map<> in wxFileSystemWatcher code

Use the standard containers directly instead of defining a typedef for
it using wx macros.
This commit is contained in:
Vadim Zeitlin 2023-04-17 20:36:21 +01:00
parent d3480f58b0
commit 070f778dcd
4 changed files with 28 additions and 24 deletions

View file

@ -19,7 +19,8 @@
#include "wx/evtloop.h"
#include "wx/filename.h"
#include "wx/dir.h"
#include "wx/hashmap.h"
#include <unordered_map>
#define wxTRACE_FSWATCHER "fswatcher"
@ -279,7 +280,7 @@ protected:
int m_refcount;
};
WX_DECLARE_STRING_HASH_MAP(wxFSWatchInfo, wxFSWatchInfoMap);
using wxFSWatchInfoMap = std::unordered_map<wxString, wxFSWatchInfo>;
/**
* Encapsulation of platform-specific file system event mechanism

View file

@ -12,20 +12,22 @@
#include "wx/sharedptr.h"
#include <unordered_map>
#ifdef wxHAS_INOTIFY
class wxFSWatchEntryUnix;
#define wxFSWatchEntry wxFSWatchEntryUnix
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
using wxFSWatchEntries = std::unordered_map<wxString, wxSharedPtr<wxFSWatchEntry>>;
#include "wx/unix/private/fswatcher_inotify.h"
#elif defined(wxHAS_KQUEUE)
class wxFSWatchEntryKq;
#define wxFSWatchEntry wxFSWatchEntryKq
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
using wxFSWatchEntries = std::unordered_map<wxString, wxSharedPtr<wxFSWatchEntry>>;
#include "wx/unix/private/fswatcher_kqueue.h"
#elif defined(__WINDOWS__)
class wxFSWatchEntryMSW;
#define wxFSWatchEntry wxFSWatchEntryMSW
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
using wxFSWatchEntries = std::unordered_map<wxString, wxSharedPtr<wxFSWatchEntry>>;
#include "wx/msw/private/fswatcher.h"
#else
#define wxFSWatchEntry wxFSWatchEntryPolling

View file

@ -21,6 +21,8 @@
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <unordered_map>
// A small class that we will give the FSEvents
// framework, which will be forwarded to the function
// that gets called when files change.
@ -275,12 +277,10 @@ static void wxDeleteContext(const void* context)
delete watcherContext;
}
WX_DECLARE_STRING_HASH_MAP(FSEventStreamRef, FSEventStreamRefMap);
struct wxFsEventsFileSystemWatcher::PrivateData
{
// map of path => FSEventStreamRef
FSEventStreamRefMap m_streams;
std::unordered_map<wxString, FSEventStreamRef> m_streams;
};
wxFsEventsFileSystemWatcher::wxFsEventsFileSystemWatcher()
@ -408,7 +408,7 @@ bool wxFsEventsFileSystemWatcher::RemoveTree(const wxFileName& path)
}
}
FSEventStreamRefMap::iterator it = m_pImpl->m_streams.find(canonical);
const auto it = m_pImpl->m_streams.find(canonical);
bool removed = false;
if ( it != m_pImpl->m_streams.end() )
{
@ -425,17 +425,18 @@ bool wxFsEventsFileSystemWatcher::RemoveAll()
{
// remove all watches created with Add()
bool ret = wxKqueueFileSystemWatcher::RemoveAll();
FSEventStreamRefMap::iterator it = m_pImpl->m_streams.begin();
while ( it != m_pImpl->m_streams.end() )
if ( m_pImpl->m_streams.empty() )
return ret;
for ( const auto& kv : m_pImpl->m_streams )
{
FSEventStreamStop(it->second);
FSEventStreamInvalidate(it->second);
FSEventStreamRelease(it->second);
++it;
ret = true;
FSEventStreamRef stream = kv.second;
FSEventStreamStop(stream);
FSEventStreamInvalidate(stream);
FSEventStreamRelease(stream);
}
m_pImpl->m_streams.clear();
return ret;
return true;
}
void wxFsEventsFileSystemWatcher::PostChange(const wxFileName& oldFileName,
@ -510,10 +511,10 @@ int wxFsEventsFileSystemWatcher::GetWatchedPaths(wxArrayString* paths) const
return 0;
}
wxFileSystemWatcherBase::GetWatchedPaths(paths);
FSEventStreamRefMap::const_iterator it = m_pImpl->m_streams.begin();
for ( ; it != m_pImpl->m_streams.end(); ++it )
for ( const auto& kv : m_pImpl->m_streams )
{
paths->push_back(it->first);
paths->push_back(kv.first);
}
return paths->size();
}

View file

@ -21,17 +21,17 @@
#include <unistd.h>
#include "wx/private/fswatcher.h"
#include <unordered_map>
// ============================================================================
// wxFSWatcherImpl implementation & helper wxFSWSourceHandler implementation
// ============================================================================
// inotify watch descriptor => wxFSWatchEntry* map
WX_DECLARE_HASH_MAP(int, wxFSWatchEntry*, wxIntegerHash, wxIntegerEqual,
wxFSWatchEntryDescriptors);
using wxFSWatchEntryDescriptors = std::unordered_map<int, wxFSWatchEntry*>;
// inotify event cookie => inotify_event* map
WX_DECLARE_HASH_MAP(int, inotify_event*, wxIntegerHash, wxIntegerEqual,
wxInotifyCookies);
using wxInotifyCookies = std::unordered_map<int, inotify_event*>;
/**
* Helper class encapsulating inotify mechanism