little event improvement & add OpenURL utility function

This commit is contained in:
CallowBlack 2022-05-29 15:29:42 +03:00
parent 57c2ff0db5
commit ec32e87eb3
3 changed files with 18 additions and 0 deletions

View File

@ -63,6 +63,12 @@ struct EventCore
{ {
using TMyHandlerPtr = typename TypeHelper<TParams...>::TEventHandlerPtr; using TMyHandlerPtr = typename TypeHelper<TParams...>::TEventHandlerPtr;
EventCore() {}
EventCore(const EventCore<TParams...>& other) : handlers(other.handlers) {}
EventCore(EventCore<TParams...>&& other) : handlers(std::move(handlers)) {}
EventCore<TParams...>& operator=(const EventCore<TParams...>& other) { handlers = other.handlers; return *this; }
EventCore<TParams...>& operator=(EventCore<TParams...>&& other) { handlers = std::move(other.handlers); return *this; }
std::list<TMyHandlerPtr> handlers; std::list<TMyHandlerPtr> handlers;
mutable std::shared_mutex coreMutex; mutable std::shared_mutex coreMutex;
}; };
@ -126,6 +132,11 @@ class TEvent : public IEvent<TParams...>
{ {
} }
TEvent(const TEvent& other) : m_core(other.m_core), m_handlerRunners(other.m_handlerRunners)
{
}
virtual void operator()( TParams... params ) virtual void operator()( TParams... params )
{ {
TMyHandlerRunner newHandlerRunner( m_core ); TMyHandlerRunner newHandlerRunner( m_core );

View File

@ -3,6 +3,7 @@
#include "util.h" #include "util.h"
#include <Windows.h> #include <Windows.h>
#include <shellapi.h>
#include <commdlg.h> #include <commdlg.h>
#include <shtypes.h> #include <shtypes.h>
#include <shobjidl_core.h> #include <shobjidl_core.h>
@ -270,4 +271,9 @@ namespace util
return static_cast<int64_t>(timezoneInfo.Bias) * 60; return static_cast<int64_t>(timezoneInfo.Bias) * 60;
} }
void OpenURL(const char* url)
{
ShellExecute(nullptr, nullptr, url, nullptr, nullptr, SW_SHOW);
}
} }

View File

@ -32,6 +32,7 @@ namespace util
std::optional<std::string> SelectDirectory(const char* title); std::optional<std::string> SelectDirectory(const char* title);
std::optional<std::string> GetOrSelectPath(CSimpleIni& ini, const char* section, const char* name, const char* friendName, const char* filter); std::optional<std::string> GetOrSelectPath(CSimpleIni& ini, const char* section, const char* name, const char* friendName, const char* filter);
void OpenURL(const char* url);
std::string GetLastErrorAsString(DWORD errorId = 0); std::string GetLastErrorAsString(DWORD errorId = 0);
int64_t GetCurrentTimeMillisec(); int64_t GetCurrentTimeMillisec();