Skip to content

Commit

Permalink
add noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Mar 12, 2024
1 parent 7ab6396 commit 0687cac
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 142 deletions.
20 changes: 10 additions & 10 deletions bee/filewatch/filewatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace bee::filewatch {
};
flag flags;
std::string path;
notify(const flag& flags, const std::string& path)
notify(const flag& flags, const std::string& path) noexcept
: flags(flags)
, path(path) {}
};
Expand All @@ -47,30 +47,30 @@ namespace bee::filewatch {
static inline filter DefaultFilter = [](const char*) { return true; };

watch() noexcept;
~watch();
~watch() noexcept;

void stop() noexcept;
void add(const string_type& path);
void add(const string_type& path) noexcept;
void set_recursive(bool enable) noexcept;
bool set_follow_symlinks(bool enable) noexcept;
bool set_filter(filter f = DefaultFilter);
void update();
std::optional<notify> select();
bool set_filter(filter f = DefaultFilter) noexcept;
void update() noexcept;
std::optional<notify> select() noexcept;

private:
#if defined(_WIN32)
bool event_update(task& task);
bool event_update(task& task) noexcept;
#elif defined(__APPLE__)
bool create_stream(CFArrayRef cf_paths) noexcept;
void destroy_stream() noexcept;
void update_stream();
void update_stream() noexcept;

public:
void event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n);
void event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n) noexcept;

private:
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
void event_update(void* event);
void event_update(void* event) noexcept;
#endif

private:
Expand Down
12 changes: 6 additions & 6 deletions bee/filewatch/filewatch_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace bee::filewatch {
assert(m_inotify_fd != -1);
}

watch::~watch() {
watch::~watch() noexcept {
stop();
}

Expand All @@ -39,7 +39,7 @@ namespace bee::filewatch {
m_inotify_fd = -1;
}

void watch::add(const string_type& str) {
void watch::add(const string_type& str) noexcept {
if (m_inotify_fd == -1) {
return;
}
Expand Down Expand Up @@ -84,12 +84,12 @@ namespace bee::filewatch {
return true;
}

bool watch::set_filter(filter f) {
bool watch::set_filter(filter f) noexcept {
m_filter = f;
return true;
}

void watch::update() {
void watch::update() noexcept {
if (m_inotify_fd == -1) {
return;
}
Expand All @@ -113,7 +113,7 @@ namespace bee::filewatch {
}
}

void watch::event_update(void* e) {
void watch::event_update(void* e) noexcept {
inotify_event* event = (inotify_event*)e;
if (event->mask & IN_Q_OVERFLOW) {
// TODO?
Expand Down Expand Up @@ -143,7 +143,7 @@ namespace bee::filewatch {
}
}

std::optional<notify> watch::select() {
std::optional<notify> watch::select() noexcept {
if (m_notify.empty()) {
return std::nullopt;
}
Expand Down
14 changes: 7 additions & 7 deletions bee/filewatch/filewatch_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace bee::filewatch {
return "fsevent";
}

static void event_cb(ConstFSEventStreamRef streamRef, void* info, size_t numEvents, void* eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) {
static void event_cb(ConstFSEventStreamRef streamRef, void* info, size_t numEvents, void* eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) noexcept {
(void)streamRef;
(void)eventIds;
watch* self = (watch*)info;
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace bee::filewatch {
m_stream = NULL;
}

void watch::add(const string_type& path) {
void watch::add(const string_type& path) noexcept {
m_paths.emplace(path);
update_stream();
}
Expand All @@ -78,11 +78,11 @@ namespace bee::filewatch {
return false;
}

bool watch::set_filter(filter f) {
bool watch::set_filter(filter f) noexcept {
return false;
}

void watch::update_stream() {
void watch::update_stream() noexcept {
destroy_stream();
if (m_paths.empty()) {
return;
Expand All @@ -106,10 +106,10 @@ namespace bee::filewatch {
CFRelease(cf_paths);
}

void watch::update() {
void watch::update() noexcept {
}

void watch::event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n) {
void watch::event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n) noexcept {
std::unique_lock<std::mutex> lock(m_mutex);
for (size_t i = 0; i < n; ++i) {
const char* path = paths[i];
Expand All @@ -125,7 +125,7 @@ namespace bee::filewatch {
}
}

std::optional<notify> watch::select() {
std::optional<notify> watch::select() noexcept {
std::unique_lock<std::mutex> lock(m_mutex);
if (m_notify.empty()) {
return std::nullopt;
Expand Down
18 changes: 9 additions & 9 deletions bee/filewatch/filewatch_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace bee::filewatch {

public:
task() noexcept;
~task();
~task() noexcept;

enum class result {
success,
Expand All @@ -26,7 +26,7 @@ namespace bee::filewatch {
zero,
};

bool open(const std::wstring& path);
bool open(const std::wstring& path) noexcept;
bool start(bool recursive) noexcept;
void cancel() noexcept;
result try_read() noexcept;
Expand All @@ -47,11 +47,11 @@ namespace bee::filewatch {
hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
}

task::~task() {
task::~task() noexcept {
assert(m_directory == INVALID_HANDLE_VALUE);
}

bool task::open(const std::wstring& path) {
bool task::open(const std::wstring& path) noexcept {
if (m_directory != INVALID_HANDLE_VALUE) {
return true;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace bee::filewatch {
m_tasks.clear();
}

void watch::add(const string_type& path) {
void watch::add(const string_type& path) noexcept {
auto& t = m_tasks.emplace_back();
if (t.open(path)) {
if (t.start(m_recursive)) {
Expand All @@ -170,11 +170,11 @@ namespace bee::filewatch {
return false;
}

bool watch::set_filter(filter f) {
bool watch::set_filter(filter f) noexcept {
return false;
}

bool watch::event_update(task& task) {
bool watch::event_update(task& task) noexcept {
switch (task.try_read()) {
case task::result::wait:
return true;
Expand Down Expand Up @@ -213,7 +213,7 @@ namespace bee::filewatch {
return task.start(m_recursive);
}

void watch::update() {
void watch::update() noexcept {
for (auto iter = m_tasks.begin(); iter != m_tasks.end();) {
if (event_update(*iter)) {
++iter;
Expand All @@ -224,7 +224,7 @@ namespace bee::filewatch {
}
}

std::optional<notify> watch::select() {
std::optional<notify> watch::select() noexcept {
if (m_notify.empty()) {
return std::nullopt;
}
Expand Down
10 changes: 5 additions & 5 deletions bee/net/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace bee::net::socket {
}

static WSAPROTOCOL_INFOW UnixProtocol;
static bool supportUnixDomainSocket_() {
static bool supportUnixDomainSocket_() noexcept {
static GUID AF_UNIX_PROVIDER_ID = { 0xA00943D9, 0x9C2E, 0x4633, { 0x9B, 0x59, 0x00, 0x57, 0xA3, 0x16, 0x09, 0x94 } };
DWORD len = 0;
::WSAEnumProtocolsW(0, NULL, &len);
Expand All @@ -152,7 +152,7 @@ namespace bee::net::socket {
}
return false;
}
static bool supportUnixDomainSocket() {
static bool supportUnixDomainSocket() noexcept {
static bool support = supportUnixDomainSocket_();
return support;
}
Expand Down Expand Up @@ -499,7 +499,7 @@ namespace bee::net::socket {
return status::success;
}

expected<endpoint, status> recvfrom(fd_t s, int& rc, char* buf, int len) {
expected<endpoint, status> recvfrom(fd_t s, int& rc, char* buf, int len) noexcept {
endpoint ep;
rc = ::recvfrom(s, buf, len, 0, ep.out_addr(), ep.out_addrlen());
if (rc == 0) {
Expand All @@ -524,7 +524,7 @@ namespace bee::net::socket {
return status::success;
}

std::optional<endpoint> getpeername(fd_t s) {
std::optional<endpoint> getpeername(fd_t s) noexcept {
endpoint ep;
const int ok = ::getpeername(s, ep.out_addr(), ep.out_addrlen());
if (!net_success(ok)) {
Expand All @@ -533,7 +533,7 @@ namespace bee::net::socket {
return ep;
}

std::optional<endpoint> getsockname(fd_t s) {
std::optional<endpoint> getsockname(fd_t s) noexcept {
endpoint ep;
const int ok = ::getsockname(s, ep.out_addr(), ep.out_addrlen());
if (!net_success(ok)) {
Expand Down
6 changes: 3 additions & 3 deletions bee/net/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ namespace bee::net::socket {
fdstat accept(fd_t s, fd_t& newfd, fd_flags flags = fd_flags::nonblock) noexcept;
status recv(fd_t s, int& rc, char* buf, int len) noexcept;
status send(fd_t s, int& rc, const char* buf, int len) noexcept;
expected<endpoint, status> recvfrom(fd_t s, int& rc, char* buf, int len);
expected<endpoint, status> recvfrom(fd_t s, int& rc, char* buf, int len) noexcept;
status sendto(fd_t s, int& rc, const char* buf, int len, const endpoint& ep) noexcept;
std::optional<endpoint> getpeername(fd_t s);
std::optional<endpoint> getsockname(fd_t s);
std::optional<endpoint> getpeername(fd_t s) noexcept;
std::optional<endpoint> getsockname(fd_t s) noexcept;
bool unlink(const endpoint& ep);
std::error_code errcode(fd_t s) noexcept;
fd_t dup(fd_t s) noexcept;
Expand Down
6 changes: 3 additions & 3 deletions bee/platform/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace bee {
}

# if defined(_WIN32)
static uint32_t toint(std::wstring_view wstr, uint32_t def = 0) {
static uint32_t toint(std::wstring_view wstr, uint32_t def = 0) noexcept {
std::string str;
str.resize(wstr.size());
for (size_t i = 0; i < wstr.size(); ++i) {
Expand All @@ -46,7 +46,7 @@ namespace bee {
# endif

template <typename CharT>
static version to_version(std::basic_string_view<CharT> verstr) {
static version to_version(std::basic_string_view<CharT> verstr) noexcept {
constexpr auto npos = std::basic_string_view<CharT>::npos;
version v { 0, 0, 0 };
size_t pos = 0;
Expand All @@ -68,7 +68,7 @@ namespace bee {
}
#endif

version os_version() {
version os_version() noexcept {
#if defined(__APPLE__)
// id processInfo = [NSProcessInfo processInfo]
id processInfo = reinterpret_cast<id (*)(Class, SEL)>(objc_msgSend)(objc_getClass("NSProcessInfo"), sel_getUid("processInfo"));
Expand Down
2 changes: 1 addition & 1 deletion bee/platform/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ namespace bee {
}
};

version os_version();
version os_version() noexcept;
}
4 changes: 2 additions & 2 deletions bee/platform/win/module_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace bee::win {
class module_version {
public:
module_version(const wchar_t* module_path);
module_version(const wchar_t* module_path) noexcept;
bool select_language(uint16_t langid) noexcept;
std::wstring_view get_value(const wchar_t* key) const;
std::wstring_view get_value(const wchar_t* key) const noexcept;

protected:
struct translation {
Expand Down
4 changes: 2 additions & 2 deletions bee/platform/win/module_version_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace bee::win {

module_version::module_version(const wchar_t* module_path)
module_version::module_version(const wchar_t* module_path) noexcept
: current_(0)
, translation_()
, version_info_() {
Expand Down Expand Up @@ -36,7 +36,7 @@ namespace bee::win {
select_language(::GetUserDefaultLangID());
}

std::wstring_view module_version::get_value(const wchar_t* key) const {
std::wstring_view module_version::get_value(const wchar_t* key) const noexcept {
if (translation_.empty()) {
return L"";
}
Expand Down
12 changes: 6 additions & 6 deletions bee/platform/win/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <string>

namespace bee::win {
std::wstring u2w(zstring_view str);
std::string w2u(wzstring_view wstr);
std::wstring a2w(zstring_view str);
std::string w2a(wzstring_view wstr);
std::string a2u(zstring_view str);
std::string u2a(zstring_view str);
std::wstring u2w(zstring_view str) noexcept;
std::string w2u(wzstring_view wstr) noexcept;
std::wstring a2w(zstring_view str) noexcept;
std::string w2a(wzstring_view wstr) noexcept;
std::string a2u(zstring_view str) noexcept;
std::string u2a(zstring_view str) noexcept;
}
Loading

0 comments on commit 0687cac

Please sign in to comment.