wrap cast aliases in namespace

This commit is contained in:
Kamikadze 2025-08-06 05:00:14 +05:00
parent fe5ee8a3a5
commit ec78bdf704
8 changed files with 34 additions and 28 deletions

View file

@ -20,7 +20,7 @@ namespace Hyprutils::Math {
CEdges() = default; CEdges() = default;
CEdges(eEdges edges) : m_edges(edges) {} CEdges(eEdges edges) : m_edges(edges) {}
CEdges(uint8_t edges) : m_edges(sc<eEdges>(edges)) {} CEdges(uint8_t edges) : m_edges(Memory::sc<eEdges>(edges)) {}
bool operator==(const CEdges& other) { bool operator==(const CEdges& other) {
return m_edges == other.m_edges; return m_edges == other.m_edges;
@ -82,28 +82,28 @@ namespace Hyprutils::Math {
* @param top The state the top edge should be set to. * @param top The state the top edge should be set to.
*/ */
void setTop(bool top) { void setTop(bool top) {
m_edges = sc<eEdges>((m_edges & ~TOP) | (TOP * top)); m_edges = Memory::sc<eEdges>((m_edges & ~TOP) | (TOP * top));
} }
/** /**
* @param left The state the left edge should be set to. * @param left The state the left edge should be set to.
*/ */
void setLeft(bool left) { void setLeft(bool left) {
m_edges = sc<eEdges>((m_edges & ~LEFT) | (LEFT * left)); m_edges = Memory::sc<eEdges>((m_edges & ~LEFT) | (LEFT * left));
} }
/** /**
* @param bottom The state the bottom edge should be set to. * @param bottom The state the bottom edge should be set to.
*/ */
void setBottom(bool bottom) { void setBottom(bool bottom) {
m_edges = sc<eEdges>((m_edges & ~BOTTOM) | (BOTTOM * bottom)); m_edges = Memory::sc<eEdges>((m_edges & ~BOTTOM) | (BOTTOM * bottom));
} }
/** /**
* @param right The state the right edge should be set to. * @param right The state the right edge should be set to.
*/ */
void setRight(bool right) { void setRight(bool right) {
m_edges = sc<eEdges>((m_edges & ~RIGHT) | (RIGHT * right)); m_edges = Memory::sc<eEdges>((m_edges & ~RIGHT) | (RIGHT * right));
} }
eEdges m_edges = NONE; eEdges m_edges = NONE;

View file

@ -1,28 +1,29 @@
#pragma once #pragma once
#include <bit> #include <bit>
#include <utility> #include <utility>
namespace Hyprutils::Memory {
template <typename To, typename From>
constexpr To sc(From&& from) noexcept {
return static_cast<To>(std::forward<From>(from));
}
template <typename To, typename From> template <typename To, typename From>
constexpr To sc(From&& from) noexcept { constexpr To cc(From&& from) noexcept {
return static_cast<To>(std::forward<From>(from)); return const_cast<To>(std::forward<From>(from));
} }
template <typename To, typename From> template <typename To, typename From>
constexpr To cc(From&& from) noexcept { constexpr To rc(From&& from) noexcept {
return const_cast<To>(std::forward<From>(from)); return reinterpret_cast<To>(std::forward<From>(from));
} }
template <typename To, typename From> template <typename To, typename From>
constexpr To rc(From&& from) noexcept { constexpr To dc(From&& from) {
return reinterpret_cast<To>(std::forward<From>(from)); return dynamic_cast<To>(std::forward<From>(from));
} }
template <typename To, typename From> template <typename To, typename From>
constexpr To dc(From&& from) { constexpr To bc(const From& from) noexcept {
return dynamic_cast<To>(std::forward<From>(from)); return std::bit_cast<To>(from);
} }
template <typename To, typename From>
constexpr To bc(const From& from) noexcept {
return std::bit_cast<To>(from);
} }

View file

@ -37,7 +37,7 @@ namespace Hyprutils {
if constexpr (sizeof...(Args) == 1) if constexpr (sizeof...(Args) == 1)
// NOLINTNEXTLINE: const is reapplied by handler invocation if required // NOLINTNEXTLINE: const is reapplied by handler invocation if required
emitInternal(cc<void*>(sc<const void*>(&std::get<0>(argsTuple)))); emitInternal(Memory::cc<void*>(Memory::sc<const void*>(&std::get<0>(argsTuple))));
else else
emitInternal(&argsTuple); emitInternal(&argsTuple);
} }
@ -94,9 +94,9 @@ namespace Hyprutils {
if constexpr (sizeof...(Args) == 0) if constexpr (sizeof...(Args) == 0)
handler(); handler();
else if constexpr (sizeof...(Args) == 1) else if constexpr (sizeof...(Args) == 1)
handler(*sc<std::remove_reference_t<std::tuple_element_t<0, std::tuple<RefArg<Args>...>>>*>(args)); handler(*Memory::sc<std::remove_reference_t<std::tuple_element_t<0, std::tuple<RefArg<Args>...>>>*>(args));
else else
std::apply(handler, *sc<std::tuple<RefArg<Args>...>*>(args)); std::apply(handler, *Memory::sc<std::tuple<RefArg<Args>...>*>(args));
}; };
} }
}; };

View file

@ -6,6 +6,7 @@
using namespace Hyprutils::Animation; using namespace Hyprutils::Animation;
using namespace Hyprutils::Math; using namespace Hyprutils::Math;
using namespace Hyprutils::Memory;
void CBezierCurve::setup(const std::array<Vector2D, 2>& pVec) { void CBezierCurve::setup(const std::array<Vector2D, 2>& pVec) {
// Avoid reallocations by reserving enough memory upfront // Avoid reallocations by reserving enough memory upfront

View file

@ -7,6 +7,7 @@
#include <format> #include <format>
using namespace Hyprutils::Math; using namespace Hyprutils::Math;
using namespace Hyprutils::Memory;
static std::unordered_map<eTransform, Mat3x3> transforms = { static std::unordered_map<eTransform, Mat3x3> transforms = {
{HYPRUTILS_TRANSFORM_NORMAL, std::array<float, 9>{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, {HYPRUTILS_TRANSFORM_NORMAL, std::array<float, 9>{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},

View file

@ -3,6 +3,7 @@
#include <cmath> #include <cmath>
using namespace Hyprutils::Math; using namespace Hyprutils::Math;
using namespace Hyprutils::Memory;
constexpr const int64_t MAX_REGION_SIDE = 10000000; constexpr const int64_t MAX_REGION_SIDE = 10000000;

View file

@ -5,6 +5,7 @@
#include <cmath> #include <cmath>
using namespace Hyprutils::Math; using namespace Hyprutils::Math;
using namespace Hyprutils::Memory;
Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) : x(xx), y(yy) { Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) : x(xx), y(yy) {
; ;

View file

@ -1,6 +1,7 @@
#include <hyprutils/os/Process.hpp> #include <hyprutils/os/Process.hpp>
#include <hyprutils/memory/Casts.hpp> #include <hyprutils/memory/Casts.hpp>
using namespace Hyprutils::OS; using namespace Hyprutils::OS;
using namespace Hyprutils::Memory;
#include <csignal> #include <csignal>
#include <cstdio> #include <cstdio>