mirror of
https://github.com/YimMenu/RDR-Classes.git
synced 2024-12-22 14:37:30 +08:00
Guid (#11)
* add guid * Update Guid.hpp * it’s too late for all of this * format
This commit is contained in:
parent
c6c93b1286
commit
515edbcad8
@ -48,3 +48,4 @@
|
||||
#include "script/scrThreadContext.hpp"
|
||||
#include "script/scrVector.hpp"
|
||||
#include "script/types.hpp"
|
||||
#include "rage/Guid.hpp"
|
42
rage/Guid.hpp
Normal file
42
rage/Guid.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
template <typename size_t Len>
|
||||
class Guid {
|
||||
public:
|
||||
static_assert(Len > 0);
|
||||
|
||||
inline constexpr size_t size() const { return Len; }
|
||||
|
||||
template <typename T>
|
||||
inline constexpr T &At(size_t i) {
|
||||
static_assert(sizeof(T) <= sizeof(uint64_t));
|
||||
assert(i < Len);
|
||||
return *reinterpret_cast<T *>(&m_Buffer[i]);
|
||||
}
|
||||
|
||||
inline constexpr uint32_t &operator[](size_t i) { return At<uint32_t>(i); }
|
||||
|
||||
inline constexpr Guid() {
|
||||
for (size_t i = 0; i < size(); i++)
|
||||
m_Buffer[i] = 0;
|
||||
}
|
||||
|
||||
template <typename size_t Len2>
|
||||
inline constexpr Guid<Len> &operator=(Guid<Len2> g) {
|
||||
for (size_t i = 0; i < std::min(size(), g.size()); i++)
|
||||
m_Buffer[i] = g[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename size_t Len2>
|
||||
inline constexpr Guid(Guid<Len2> g) {
|
||||
*this = g;
|
||||
}
|
||||
|
||||
inline constexpr Any *get() { return reinterpret_cast<Any *>(&m_Buffer); }
|
||||
|
||||
private:
|
||||
alignas(8) uint64_t m_Buffer[Len];
|
||||
};
|
||||
static_assert(sizeof(Guid<5>) == sizeof(uint64_t) * 5);
|
Loading…
Reference in New Issue
Block a user