10 #include <type_traits>
16 #define STR(x) __STR(x)
18 #define WIDECHAR(x) __WIDE(x)
19 #define __WIDE2(x) L##x
20 #define WIDECHAR2(x) __WIDE2(x)
21 #define CONCAT(x, y) (x##y)
24 #if defined(PWN_BUILD_FOR_WINDOWS)
25 #define UMDF_USING_NTSTATUS
29 #pragma warning(disable : 4005)
31 #include <phnt_windows.h>
36 #elif defined(PWN_BUILD_FOR_LINUX)
63 #ifndef UNREFERENCED_PARAMETER
64 #define UNREFERENCED_PARAMETER(x) ((void)x)
68 #ifndef UnusedParameter
69 #define UnusedParameter UNREFERENCED_PARAMETER
73 #define UnusedResult UNREFERENCED_PARAMETER
76 #ifndef PWN_DEPRECATED
77 #define PWN_DEPRECATED __declspec(deprecated)
81 #ifdef PWN_BUILD_FOR_WINDOWS
82 #define PWNAPI __declspec(dllexport)
89 #define __countof(x) (sizeof(x) / sizeof(x[0]))
94 #define MIN(x, y) ((((size_t)x) < ((size_t)y)) ? (x) : (y))
98 using u8 = std::uint8_t;
99 using u16 = std::uint16_t;
100 using u32 = std::uint32_t;
101 using u64 = std::uint64_t;
102 using i8 = std::int8_t;
103 using i16 = std::int16_t;
104 using i32 = std::int32_t;
105 using i64 = std::int64_t;
107 using usize =
unsigned long;
109 using usize = std::size_t;
111 using ssize = std::intptr_t;
112 using uptr = std::uintptr_t;
115 using namespace std::literals::string_view_literals;
116 using namespace std::literals::chrono_literals;
118 #ifdef PWN_BUILD_FOR_WINDOWS
119 constexpr std::string
120 constexpr_concat() noexcept
122 return std::string(
"");
126 template<
typename... Args>
127 constexpr std::string
128 constexpr_concat(std::string
const& arg, Args... args)
130 std::string rest = constexpr_concat(args...);
144 template<
typename Key,
typename Value, usize Size>
147 using CMapEntry = std::pair<Key, Value>;
148 std::array<CMapEntry, Size> data;
150 [[nodiscard]] constexpr Value
151 at(
const Key& key)
const
153 const auto itr = std::find_if(
156 [&key](
const auto& v)
158 return v.first == key;
160 if ( itr != end(data) )
164 throw std::range_error(
"Not Found");
167 [[nodiscard]] constexpr Value
168 operator[](
const Key& key)
const
185 constexpr
CBuffer(
size_t n) noexcept : size_(n), mem_(
new T[n])
193 constexpr
CBuffer(
const CBuffer& other) noexcept : size_(other.size_)
195 if ( &other !=
this )
198 std::copy(other.mem_, other.mem_ + size_, mem_);
204 if ( &other !=
this )
208 other.mem_ =
nullptr;
214 operator=(
const CBuffer& other) noexcept
216 if ( &other !=
this )
219 std::copy(other.mem_, other.mem_ + size_, mem_);
225 operator=(
CBuffer&& other) noexcept
227 if ( &other !=
this )
231 other.mem_ =
nullptr;
238 operator[](
size_t id) noexcept
243 operator[](
size_t id)
const noexcept
249 data()
const noexcept
254 size()
const noexcept
260 begin()
const noexcept
272 cbegin()
const noexcept
278 cend()
const noexcept
295 template<typename T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
298 using N =
typename std::underlying_type<T>::type;
303 return static_cast<N
>(a);
306 explicit constexpr
CBitMask(N a) : m_val(a)
315 constexpr
CBitMask(T a) : m_val(get(a))
328 return m_val & get(t);
348 concept Flattenable = std::same_as<T, std::vector<u8>> || std::same_as<T, std::string> || std::same_as<T, std::wstring>;
361 template<Flattenable T, Flattenable... Args>
363 SumSizeOfFlattenable(T arg, Args... args)
367 if constexpr ( std::is_same_v<T, std::string> )
371 else if constexpr ( std::is_same_v<T, std::wstring> )
373 sz += arg.size() *
sizeof(wchar_t);
375 else if constexpr ( std::is_same_v<T, std::vector<u8>> )
384 if constexpr (
sizeof...(args) > 0 )
386 return sz + SumSizeOfFlattenable(args...);
400 concept Indexable = requires(T t)
403 { t.Id() }-> std::same_as<u32>;
414 template<Indexable T>
430 template<Indexable T>
A basic constexpr bitmask class.
Definition: Common.hpp:297
A basic constexpr generic buffer https://www.cppstories.com/2021/constexpr-new-cpp20/.
Definition: Common.hpp:183
An IndexedVector is a vector of Indexable types. This allows to override [] to the Id attribute of th...
Definition: Common.hpp:416
T & operator[](int Id)
Definition: Common.hpp:432
A constexpr map https://xuhuisun.com/post/c++-weekly-2-constexpr-map/.
Definition: Common.hpp:146