12 #include "aegis/fwd.hpp"
13 #include "aegis/config.hpp"
14 #include <nlohmann/json.hpp>
24 constexpr
snowflake() noexcept : _id(0) {}
25 constexpr
snowflake(int64_t _snowflake) noexcept : _id(_snowflake) {}
27 explicit snowflake(
const char * _snowflake) noexcept : _id(std::stoll(std::string(_snowflake))) {}
28 explicit snowflake(
const std::string & _snowflake) noexcept : _id(std::stoll(_snowflake)) {}
29 #if defined(AEGIS_CXX17)
30 explicit snowflake(
const std::string_view _snowflake) noexcept : _id(std::stoll(std::string{ _snowflake })) {}
32 explicit snowflake(
const nlohmann::json & _snowflake) noexcept : _id(std::stoll(_snowflake.get<std::string>())) {}
41 constexpr
operator int64_t()
const noexcept
50 constexpr int64_t
get()
const noexcept
59 std::string
gets() const noexcept
61 return std::to_string(_id);
68 constexpr std::tuple<int64_t, int8_t, int8_t, int16_t>
get_all() const noexcept
79 return static_cast<int16_t
>(_id & _countMask);
88 return static_cast<int8_t
>((_id & _workerMask) >> 12);
97 return static_cast<int8_t
>((_id & _workerMask) >> 17);
106 return (_id & _timestampMask) >> 22;
113 static constexpr std::tuple<int64_t, int8_t, int8_t, int16_t>
c_get_all(int64_t _snowflake) noexcept
124 return static_cast<int16_t
>(_snowflake & _countMask);
133 return static_cast<int8_t
>((_snowflake & _workerMask) >> 12);
142 return static_cast<int8_t
>((_snowflake & _workerMask) >> 17);
151 return (_snowflake & _timestampMask) >> 22;
167 static constexpr int64_t
c_get_time(int64_t _snowflake) noexcept
174 static constexpr uint64_t _countMask = 0x0000000000000FFFL;
175 static constexpr uint64_t _processMask = 0x000000000001F000L;
176 static constexpr uint64_t _workerMask = 0x00000000003E0000L;
177 static constexpr uint64_t _timestampMask = 0xFFFFFFFFFFC00000L;
178 static constexpr uint64_t _discordEpoch = 1420070400000;
182 AEGIS_DECL
void from_json(
const nlohmann::json& j, snowflake& s);
183 AEGIS_DECL
void to_json(nlohmann::json& j,
const snowflake& s);
193 struct hash<aegis::snowflake>
197 return hash<int64_t>()(k.
get());
204 #if defined(AEGIS_HEADER_ONLY)
205 #include "aegis/impl/snowflake.cpp"
constexpr int64_t get_time() const noexcept
Definition: snowflake.hpp:158
static constexpr int16_t c_get_count(int64_t _snowflake) noexcept
Definition: snowflake.hpp:122
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
constexpr std::tuple< int64_t, int8_t, int8_t, int16_t > get_all() const noexcept
Obtain all the snowflake values as a tuple.
Definition: snowflake.hpp:68
constexpr int8_t get_process() const noexcept
Definition: snowflake.hpp:86
Class for performing actions pertaining to a specified guild.
Definition: guild.hpp:159
constexpr int64_t get() const noexcept
Get snowflake as int64_t.
Definition: snowflake.hpp:50
constexpr int8_t get_worker() const noexcept
Definition: snowflake.hpp:95
Definition: message.hpp:57
Class for performing actions pertaining to a specified channel.
Definition: channel.hpp:170
Stores user-specific and guild-specific attributes of users.
Definition: user.hpp:37
Definition: attachment.hpp:28
static constexpr int8_t c_get_process(int64_t _snowflake) noexcept
Definition: snowflake.hpp:131
static constexpr std::tuple< int64_t, int8_t, int8_t, int16_t > c_get_all(int64_t _snowflake) noexcept
Obtain all the snowflake values as a tuple.
Definition: snowflake.hpp:113
static constexpr int64_t c_get_time(int64_t _snowflake) noexcept
Definition: snowflake.hpp:167
std::string gets() const noexcept
Get snowflake as std::string.
Definition: snowflake.hpp:59
Discord Emoji Object.
Definition: emoji.hpp:26
Stores info pertaining to guild roles.
Definition: role.hpp:34
constexpr int64_t get_timestamp() const noexcept
Definition: snowflake.hpp:104
constexpr int16_t get_count() const noexcept
Definition: snowflake.hpp:77
static constexpr int64_t c_get_timestamp(int64_t _snowflake) noexcept
Definition: snowflake.hpp:149
static constexpr int8_t c_get_worker(int64_t _snowflake) noexcept
Definition: snowflake.hpp:140