libnick 2025.9.1
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
codehelpers.h
Go to the documentation of this file.
1
22
23#ifndef CODEHELPERS_H
24#define CODEHELPERS_H
25
26#include <cstddef>
27#include <filesystem>
28#include <string>
29#include <vector>
30#include <unordered_map>
31
32#define DEFINE_ENUM_FLAGS(ENUM_TYPE) \
33inline constexpr ENUM_TYPE operator~(ENUM_TYPE a) noexcept { \
34 using underlying = std::underlying_type_t<ENUM_TYPE>; \
35 return static_cast<ENUM_TYPE>(~static_cast<underlying>(a)); \
36} \
37inline constexpr ENUM_TYPE operator|(ENUM_TYPE lhs, ENUM_TYPE rhs) noexcept { \
38 using underlying = std::underlying_type_t<ENUM_TYPE>; \
39 return static_cast<ENUM_TYPE>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs)); \
40} \
41inline constexpr ENUM_TYPE operator&(ENUM_TYPE lhs, ENUM_TYPE rhs) noexcept { \
42 using underlying = std::underlying_type_t<ENUM_TYPE>; \
43 return static_cast<ENUM_TYPE>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs)); \
44} \
45inline constexpr ENUM_TYPE operator^(ENUM_TYPE lhs, ENUM_TYPE rhs) noexcept { \
46 using underlying = std::underlying_type_t<ENUM_TYPE>; \
47 return static_cast<ENUM_TYPE>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs)); \
48} \
49inline ENUM_TYPE& operator|=(ENUM_TYPE& lhs, ENUM_TYPE rhs) noexcept { \
50 return lhs = (lhs | rhs); \
51} \
52inline ENUM_TYPE& operator&=(ENUM_TYPE& lhs, ENUM_TYPE rhs) noexcept { \
53 return lhs = (lhs & rhs); \
54} \
55inline ENUM_TYPE& operator^=(ENUM_TYPE& lhs, ENUM_TYPE rhs) noexcept { \
56 return lhs = (lhs ^ rhs); \
57}
58
60{
67 size_t combineHash(size_t a, size_t b) noexcept;
73 std::vector<std::string> convertUrlMapToVector(const std::unordered_map<std::string, std::string>& urls) noexcept;
78 std::string getLastSystemError() noexcept;
84 std::vector<std::byte> readFileBytes(const std::filesystem::path& path) noexcept;
90 template<typename T>
91 const T& unmove(T&& t) noexcept
92 {
93 return t;
94 }
95
102 bool writeFileBytes(const std::filesystem::path& path, const std::vector<std::byte>& bytes, bool overwrite = true) noexcept;
103}
104
105#endif //CODEHELPERS_H
Definition codehelpers.h:60
const T & unmove(T &&t) noexcept
Unmoves a value.
Definition codehelpers.h:91
std::string getLastSystemError() noexcept
Get the last system api call error message.
size_t combineHash(size_t a, size_t b) noexcept
Combines two hash values together.
std::vector< std::string > convertUrlMapToVector(const std::unordered_map< std::string, std::string > &urls) noexcept
Converts a map of URLs to a vector.
std::vector< std::byte > readFileBytes(const std::filesystem::path &path) noexcept
Reads a file as a vector of bytes.
bool writeFileBytes(const std::filesystem::path &path, const std::vector< std::byte > &bytes, bool overwrite=true) noexcept
Writes a vector of bytes to a file.