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:
parent
8bd30d2a8a
commit
46231704bc
4 changed files with 28 additions and 24 deletions
|
|
@ -19,7 +19,8 @@
|
||||||
#include "wx/evtloop.h"
|
#include "wx/evtloop.h"
|
||||||
#include "wx/filename.h"
|
#include "wx/filename.h"
|
||||||
#include "wx/dir.h"
|
#include "wx/dir.h"
|
||||||
#include "wx/hashmap.h"
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#define wxTRACE_FSWATCHER "fswatcher"
|
#define wxTRACE_FSWATCHER "fswatcher"
|
||||||
|
|
||||||
|
|
@ -279,7 +280,7 @@ protected:
|
||||||
int m_refcount;
|
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
|
* Encapsulation of platform-specific file system event mechanism
|
||||||
|
|
|
||||||
|
|
@ -12,20 +12,22 @@
|
||||||
|
|
||||||
#include "wx/sharedptr.h"
|
#include "wx/sharedptr.h"
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#ifdef wxHAS_INOTIFY
|
#ifdef wxHAS_INOTIFY
|
||||||
class wxFSWatchEntryUnix;
|
class wxFSWatchEntryUnix;
|
||||||
#define wxFSWatchEntry 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"
|
#include "wx/unix/private/fswatcher_inotify.h"
|
||||||
#elif defined(wxHAS_KQUEUE)
|
#elif defined(wxHAS_KQUEUE)
|
||||||
class wxFSWatchEntryKq;
|
class wxFSWatchEntryKq;
|
||||||
#define wxFSWatchEntry 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"
|
#include "wx/unix/private/fswatcher_kqueue.h"
|
||||||
#elif defined(__WINDOWS__)
|
#elif defined(__WINDOWS__)
|
||||||
class wxFSWatchEntryMSW;
|
class wxFSWatchEntryMSW;
|
||||||
#define wxFSWatchEntry 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"
|
#include "wx/msw/private/fswatcher.h"
|
||||||
#else
|
#else
|
||||||
#define wxFSWatchEntry wxFSWatchEntryPolling
|
#define wxFSWatchEntry wxFSWatchEntryPolling
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
// A small class that we will give the FSEvents
|
// A small class that we will give the FSEvents
|
||||||
// framework, which will be forwarded to the function
|
// framework, which will be forwarded to the function
|
||||||
// that gets called when files change.
|
// that gets called when files change.
|
||||||
|
|
@ -275,12 +277,10 @@ static void wxDeleteContext(const void* context)
|
||||||
delete watcherContext;
|
delete watcherContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_DECLARE_STRING_HASH_MAP(FSEventStreamRef, FSEventStreamRefMap);
|
|
||||||
|
|
||||||
struct wxFsEventsFileSystemWatcher::PrivateData
|
struct wxFsEventsFileSystemWatcher::PrivateData
|
||||||
{
|
{
|
||||||
// map of path => FSEventStreamRef
|
// map of path => FSEventStreamRef
|
||||||
FSEventStreamRefMap m_streams;
|
std::unordered_map<wxString, FSEventStreamRef> m_streams;
|
||||||
};
|
};
|
||||||
|
|
||||||
wxFsEventsFileSystemWatcher::wxFsEventsFileSystemWatcher()
|
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;
|
bool removed = false;
|
||||||
if ( it != m_pImpl->m_streams.end() )
|
if ( it != m_pImpl->m_streams.end() )
|
||||||
{
|
{
|
||||||
|
|
@ -425,17 +425,18 @@ bool wxFsEventsFileSystemWatcher::RemoveAll()
|
||||||
{
|
{
|
||||||
// remove all watches created with Add()
|
// remove all watches created with Add()
|
||||||
bool ret = wxKqueueFileSystemWatcher::RemoveAll();
|
bool ret = wxKqueueFileSystemWatcher::RemoveAll();
|
||||||
FSEventStreamRefMap::iterator it = m_pImpl->m_streams.begin();
|
if ( m_pImpl->m_streams.empty() )
|
||||||
while ( it != m_pImpl->m_streams.end() )
|
return ret;
|
||||||
|
|
||||||
|
for ( const auto& kv : m_pImpl->m_streams )
|
||||||
{
|
{
|
||||||
FSEventStreamStop(it->second);
|
FSEventStreamRef stream = kv.second;
|
||||||
FSEventStreamInvalidate(it->second);
|
FSEventStreamStop(stream);
|
||||||
FSEventStreamRelease(it->second);
|
FSEventStreamInvalidate(stream);
|
||||||
++it;
|
FSEventStreamRelease(stream);
|
||||||
ret = true;
|
|
||||||
}
|
}
|
||||||
m_pImpl->m_streams.clear();
|
m_pImpl->m_streams.clear();
|
||||||
return ret;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFsEventsFileSystemWatcher::PostChange(const wxFileName& oldFileName,
|
void wxFsEventsFileSystemWatcher::PostChange(const wxFileName& oldFileName,
|
||||||
|
|
@ -510,10 +511,10 @@ int wxFsEventsFileSystemWatcher::GetWatchedPaths(wxArrayString* paths) const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
wxFileSystemWatcherBase::GetWatchedPaths(paths);
|
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();
|
return paths->size();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,17 +21,17 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "wx/private/fswatcher.h"
|
#include "wx/private/fswatcher.h"
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxFSWatcherImpl implementation & helper wxFSWSourceHandler implementation
|
// wxFSWatcherImpl implementation & helper wxFSWSourceHandler implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// inotify watch descriptor => wxFSWatchEntry* map
|
// inotify watch descriptor => wxFSWatchEntry* map
|
||||||
WX_DECLARE_HASH_MAP(int, wxFSWatchEntry*, wxIntegerHash, wxIntegerEqual,
|
using wxFSWatchEntryDescriptors = std::unordered_map<int, wxFSWatchEntry*>;
|
||||||
wxFSWatchEntryDescriptors);
|
|
||||||
|
|
||||||
// inotify event cookie => inotify_event* map
|
// inotify event cookie => inotify_event* map
|
||||||
WX_DECLARE_HASH_MAP(int, inotify_event*, wxIntegerHash, wxIntegerEqual,
|
using wxInotifyCookies = std::unordered_map<int, inotify_event*>;
|
||||||
wxInotifyCookies);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class encapsulating inotify mechanism
|
* Helper class encapsulating inotify mechanism
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue