From 515edbcad83405138795ce005109c5f8a6142320 Mon Sep 17 00:00:00 2001 From: Ryan <80224521+Rxann@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:04:16 -0400 Subject: [PATCH] Guid (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add guid * Update Guid.hpp * it’s too late for all of this * format --- classes.cpp | 3 ++- rage/Guid.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 rage/Guid.hpp diff --git a/classes.cpp b/classes.cpp index 51728cc..14f17ce 100644 --- a/classes.cpp +++ b/classes.cpp @@ -47,4 +47,5 @@ #include "script/scrThread.hpp" #include "script/scrThreadContext.hpp" #include "script/scrVector.hpp" -#include "script/types.hpp" \ No newline at end of file +#include "script/types.hpp" +#include "rage/Guid.hpp" \ No newline at end of file diff --git a/rage/Guid.hpp b/rage/Guid.hpp new file mode 100644 index 0000000..76bc42c --- /dev/null +++ b/rage/Guid.hpp @@ -0,0 +1,42 @@ +#pragma once +#include + +template +class Guid { +public: + static_assert(Len > 0); + + inline constexpr size_t size() const { return Len; } + + template + inline constexpr T &At(size_t i) { + static_assert(sizeof(T) <= sizeof(uint64_t)); + assert(i < Len); + return *reinterpret_cast(&m_Buffer[i]); + } + + inline constexpr uint32_t &operator[](size_t i) { return At(i); } + + inline constexpr Guid() { + for (size_t i = 0; i < size(); i++) + m_Buffer[i] = 0; + } + + template + inline constexpr Guid &operator=(Guid g) { + for (size_t i = 0; i < std::min(size(), g.size()); i++) + m_Buffer[i] = g[i]; + return *this; + } + + template + inline constexpr Guid(Guid g) { + *this = g; + } + + inline constexpr Any *get() { return reinterpret_cast(&m_Buffer); } + +private: + alignas(8) uint64_t m_Buffer[Len]; +}; +static_assert(sizeof(Guid<5>) == sizeof(uint64_t) * 5); \ No newline at end of file