Add and use c++ cast aliases

This commit is contained in:
Kamikadze 2025-08-06 04:42:15 +05:00
parent c65d41d4f4
commit fe5ee8a3a5
14 changed files with 90 additions and 60 deletions

View file

@ -1,4 +1,6 @@
#pragma once #pragma once
#include "hyprutils/memory/Casts.hpp"
#include <cstdint> #include <cstdint>
namespace Hyprutils::Math { namespace Hyprutils::Math {
@ -18,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(static_cast<eEdges>(edges)) {} CEdges(uint8_t edges) : m_edges(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;
@ -80,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 = static_cast<eEdges>((m_edges & ~TOP) | (TOP * top)); m_edges = 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 = static_cast<eEdges>((m_edges & ~LEFT) | (LEFT * left)); m_edges = 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 = static_cast<eEdges>((m_edges & ~BOTTOM) | (BOTTOM * bottom)); m_edges = 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 = static_cast<eEdges>((m_edges & ~RIGHT) | (RIGHT * right)); m_edges = sc<eEdges>((m_edges & ~RIGHT) | (RIGHT * right));
} }
eEdges m_edges = NONE; eEdges m_edges = NONE;

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
#pragma once
#include "./ImplBase.hpp" #include "./ImplBase.hpp"
#include "./SharedPtr.hpp" #include "./SharedPtr.hpp"
@ -143,7 +144,7 @@ namespace Hyprutils::Memory {
// -> must unlock BEFORE reset // -> must unlock BEFORE reset
// not last ref? // not last ref?
// -> must unlock AFTER reset // -> must unlock AFTER reset
auto& mutex = ((Atomic_::impl<T>*)m_ptr.impl_)->getMutex(); auto& mutex = sc<Atomic_::impl<T>*>(m_ptr.impl_)->getMutex();
mutex.lock(); mutex.lock();
if (m_ptr.impl_->ref() > 1) { if (m_ptr.impl_->ref() > 1) {
@ -208,7 +209,7 @@ namespace Hyprutils::Memory {
private: private:
std::lock_guard<std::recursive_mutex> implLockGuard() const { std::lock_guard<std::recursive_mutex> implLockGuard() const {
return ((Atomic_::impl<T>*)m_ptr.impl_)->lockGuard(); return sc<Atomic_::impl<T>*>(m_ptr.impl_)->lockGuard();
} }
CSharedPointer<T> m_ptr; CSharedPointer<T> m_ptr;
@ -316,7 +317,7 @@ namespace Hyprutils::Memory {
// -> must unlock BEFORE reset // -> must unlock BEFORE reset
// not last ref? // not last ref?
// -> must unlock AFTER reset // -> must unlock AFTER reset
auto& mutex = ((Atomic_::impl<T>*)m_ptr.impl_)->getMutex(); auto& mutex = sc<Atomic_::impl<T>*>(m_ptr.impl_)->getMutex();
mutex.lock(); mutex.lock();
if (m_ptr.impl_->ref() == 0 && m_ptr.impl_->wref() == 1) { if (m_ptr.impl_->ref() == 0 && m_ptr.impl_->wref() == 1) {
mutex.unlock(); mutex.unlock();
@ -379,7 +380,7 @@ namespace Hyprutils::Memory {
private: private:
std::lock_guard<std::recursive_mutex> implLockGuard() const { std::lock_guard<std::recursive_mutex> implLockGuard() const {
return ((Atomic_::impl<T>*)m_ptr.impl_)->lockGuard(); return sc<Atomic_::impl<T>*>(m_ptr.impl_)->lockGuard();
} }
CWeakPointer<T> m_ptr; CWeakPointer<T> m_ptr;

View file

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

View file

@ -2,6 +2,7 @@
#include <cstdint> #include <cstdint>
#include "ImplBase.hpp" #include "ImplBase.hpp"
#include "Casts.hpp"
/* /*
This is a custom impl of std::shared_ptr. This is a custom impl of std::shared_ptr.
@ -114,11 +115,11 @@ namespace Hyprutils {
} }
bool operator()(const CSharedPointer& lhs, const CSharedPointer& rhs) const { bool operator()(const CSharedPointer& lhs, const CSharedPointer& rhs) const {
return reinterpret_cast<uintptr_t>(lhs.impl_) < reinterpret_cast<uintptr_t>(rhs.impl_); return rc<uintptr_t>(lhs.impl_) < rc<uintptr_t>(rhs.impl_);
} }
bool operator<(const CSharedPointer& rhs) const { bool operator<(const CSharedPointer& rhs) const {
return reinterpret_cast<uintptr_t>(impl_) < reinterpret_cast<uintptr_t>(rhs.impl_); return rc<uintptr_t>(impl_) < rc<uintptr_t>(rhs.impl_);
} }
T* operator->() const { T* operator->() const {
@ -135,7 +136,7 @@ namespace Hyprutils {
} }
T* get() const { T* get() const {
return impl_ ? static_cast<T*>(impl_->getData()) : nullptr; return impl_ ? sc<T*>(impl_->getData()) : nullptr;
} }
unsigned int strongRef() const { unsigned int strongRef() const {

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "ImplBase.hpp" #include "ImplBase.hpp"
#include "Casts.hpp"
/* /*
This is a custom impl of std::unique_ptr. This is a custom impl of std::unique_ptr.
@ -74,7 +75,7 @@ namespace Hyprutils {
} }
bool operator()(const CUniquePointer& lhs, const CUniquePointer& rhs) const { bool operator()(const CUniquePointer& lhs, const CUniquePointer& rhs) const {
return reinterpret_cast<uintptr_t>(lhs.impl_) < reinterpret_cast<uintptr_t>(rhs.impl_); return rc<uintptr_t>(lhs.impl_) < rc<uintptr_t>(rhs.impl_);
} }
T* operator->() const { T* operator->() const {
@ -91,7 +92,7 @@ namespace Hyprutils {
} }
T* get() const { T* get() const {
return impl_ ? static_cast<T*>(impl_->getData()) : nullptr; return impl_ ? sc<T*>(impl_->getData()) : nullptr;
} }
Impl_::impl_base* impl_ = nullptr; Impl_::impl_base* impl_ = nullptr;

View file

@ -2,6 +2,7 @@
#include "./SharedPtr.hpp" #include "./SharedPtr.hpp"
#include "./UniquePtr.hpp" #include "./UniquePtr.hpp"
#include "./Casts.hpp"
/* /*
This is a Hyprland implementation of std::weak_ptr. This is a Hyprland implementation of std::weak_ptr.
@ -91,7 +92,7 @@ namespace Hyprutils {
/* create a weak ptr from a shared ptr with assignment */ /* create a weak ptr from a shared ptr with assignment */
template <typename U> template <typename U>
validHierarchy<const CWeakPointer<U>&> operator=(const CSharedPointer<U>& rhs) { validHierarchy<const CWeakPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
if (reinterpret_cast<uintptr_t>(impl_) == reinterpret_cast<uintptr_t>(rhs.impl_)) if (rc<uintptr_t>(impl_) == rc<uintptr_t>(rhs.impl_))
return *this; return *this;
decrementWeak(); decrementWeak();
@ -162,15 +163,15 @@ namespace Hyprutils {
} }
bool operator()(const CWeakPointer& lhs, const CWeakPointer& rhs) const { bool operator()(const CWeakPointer& lhs, const CWeakPointer& rhs) const {
return reinterpret_cast<uintptr_t>(lhs.impl_) < reinterpret_cast<uintptr_t>(rhs.impl_); return rc<uintptr_t>(lhs.impl_) < rc<uintptr_t>(rhs.impl_);
} }
bool operator<(const CWeakPointer& rhs) const { bool operator<(const CWeakPointer& rhs) const {
return reinterpret_cast<uintptr_t>(impl_) < reinterpret_cast<uintptr_t>(rhs.impl_); return rc<uintptr_t>(impl_) < rc<uintptr_t>(rhs.impl_);
} }
T* get() const { T* get() const {
return impl_ ? static_cast<T*>(impl_->getData()) : nullptr; return impl_ ? sc<T*>(impl_->getData()) : nullptr;
} }
T* operator->() const { T* operator->() const {

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(const_cast<void*>(static_cast<const void*>(&std::get<0>(argsTuple)))); emitInternal(cc<void*>(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(*static_cast<std::remove_reference_t<std::tuple_element_t<0, std::tuple<RefArg<Args>...>>>*>(args)); handler(*sc<std::remove_reference_t<std::tuple_element_t<0, std::tuple<RefArg<Args>...>>>*>(args));
else else
std::apply(handler, *static_cast<std::tuple<RefArg<Args>...>*>(args)); std::apply(handler, *sc<std::tuple<RefArg<Args>...>*>(args));
}; };
} }
}; };

View file

@ -1,4 +1,5 @@
#include <hyprutils/animation/BezierCurve.hpp> #include <hyprutils/animation/BezierCurve.hpp>
#include <hyprutils/memory/Casts.hpp>
#include <array> #include <array>
#include <cmath> #include <cmath>
@ -21,7 +22,7 @@ void CBezierCurve::setup(const std::array<Vector2D, 2>& pVec) {
// bake BAKEDPOINTS points for faster lookups // bake BAKEDPOINTS points for faster lookups
// T -> X ( / BAKEDPOINTS ) // T -> X ( / BAKEDPOINTS )
for (int i = 0; i < BAKEDPOINTS; ++i) { for (int i = 0; i < BAKEDPOINTS; ++i) {
float const t = (i + 1) / (float)BAKEDPOINTS; float const t = (i + 1) / sc<float>(BAKEDPOINTS);
m_aPointsBaked[i] = Vector2D(getXForT(t), getYForT(t)); m_aPointsBaked[i] = Vector2D(getXForT(t), getYForT(t));
} }

View file

@ -1,6 +1,7 @@
#include <hyprutils/math/Mat3x3.hpp> #include <hyprutils/math/Mat3x3.hpp>
#include <hyprutils/math/Vector2D.hpp> #include <hyprutils/math/Vector2D.hpp>
#include <hyprutils/math/Box.hpp> #include <hyprutils/math/Box.hpp>
#include <hyprutils/memory/Casts.hpp>
#include <cmath> #include <cmath>
#include <unordered_map> #include <unordered_map>
#include <format> #include <format>
@ -98,7 +99,7 @@ Mat3x3& Mat3x3::rotate(float rot) {
} }
Mat3x3& Mat3x3::scale(const Vector2D& scale_) { Mat3x3& Mat3x3::scale(const Vector2D& scale_) {
multiply(std::array<float, 9>{(float)scale_.x, 0.0f, 0.0f, 0.0f, (float)scale_.y, 0.0f, 0.0f, 0.0f, 1.0f}); multiply(std::array<float, 9>{sc<float>(scale_.x), 0.0f, 0.0f, 0.0f, sc<float>(scale_.y), 0.0f, 0.0f, 0.0f, 1.0f});
return *this; return *this;
} }
@ -107,7 +108,7 @@ Mat3x3& Mat3x3::scale(const float scale_) {
} }
Mat3x3& Mat3x3::translate(const Vector2D& offset) { Mat3x3& Mat3x3::translate(const Vector2D& offset) {
multiply(std::array<float, 9>{1.0f, 0.0f, (float)offset.x, 0.0f, 1.0f, (float)offset.y, 0.0f, 0.0f, 1.0f}); multiply(std::array<float, 9>{1.0f, 0.0f, sc<float>(offset.x), 0.0f, 1.0f, sc<float>(offset.y), 0.0f, 0.0f, 1.0f});
return *this; return *this;
} }

View file

@ -1,3 +1,4 @@
#include "hyprutils/memory/Casts.hpp"
#include <hyprutils/math/Region.hpp> #include <hyprutils/math/Region.hpp>
#include <cmath> #include <cmath>
@ -86,7 +87,7 @@ CRegion& Hyprutils::Math::CRegion::invert(pixman_box32_t* box) {
} }
CRegion& Hyprutils::Math::CRegion::invert(const CBox& box) { CRegion& Hyprutils::Math::CRegion::invert(const CBox& box) {
pixman_box32 pixmanBox = {.x1 = (int32_t)box.x, .y1 = (int32_t)box.y, .x2 = (int32_t)box.w + (int32_t)box.x, .y2 = (int32_t)box.h + (int32_t)box.y}; pixman_box32 pixmanBox = {.x1 = sc<int32_t>(box.x), .y1 = sc<int32_t>(box.y), .x2 = sc<int32_t>(box.w) + sc<int32_t>(box.x), .y2 = sc<int32_t>(box.h) + sc<int32_t>(box.y)};
return this->invert(&pixmanBox); return this->invert(&pixmanBox);
} }
@ -104,7 +105,7 @@ CRegion& Hyprutils::Math::CRegion::transform(const eTransform t, double w, doubl
clear(); clear();
for (auto& r : rects) { for (auto& r : rects) {
CBox xfmd{(double)r.x1, (double)r.y1, (double)r.x2 - r.x1, (double)r.y2 - r.y1}; CBox xfmd{r.x1, r.y1, r.x2 - r.x1, r.y2 - r.y1};
xfmd.transform(t, w, h); xfmd.transform(t, w, h);
add(xfmd); add(xfmd);
} }
@ -118,7 +119,7 @@ CRegion& Hyprutils::Math::CRegion::expand(double units) {
clear(); clear();
for (auto& r : rects) { for (auto& r : rects) {
CBox b{(double)r.x1 - units, (double)r.y1 - units, (double)r.x2 - r.x1 + (units * 2), (double)r.y2 - r.y1 + (units * 2)}; CBox b{sc<double>(r.x1) - units, sc<double>(r.y1) - units, sc<double>(r.x2) - r.x1 + (units * 2), sc<double>(r.y2) - r.y1 + (units * 2)};
add(b); add(b);
} }
@ -171,7 +172,7 @@ std::vector<pixman_box32_t> Hyprutils::Math::CRegion::getRects() const {
CBox Hyprutils::Math::CRegion::getExtents() { CBox Hyprutils::Math::CRegion::getExtents() {
pixman_box32_t* box = pixman_region32_extents(&m_rRegion); pixman_box32_t* box = pixman_region32_extents(&m_rRegion);
return {(double)box->x1, (double)box->y1, (double)box->x2 - box->x1, (double)box->y2 - box->y1}; return {sc<double>(box->x1), sc<double>(box->y1), sc<double>(box->x2) - box->x1, sc<double>(box->y2) - box->y1};
} }
bool Hyprutils::Math::CRegion::containsPoint(const Vector2D& vec) const { bool Hyprutils::Math::CRegion::containsPoint(const Vector2D& vec) const {

View file

@ -1,4 +1,5 @@
#include <hyprutils/math/Vector2D.hpp> #include <hyprutils/math/Vector2D.hpp>
#include <hyprutils/memory/Casts.hpp>
#include <hyprutils/math/Misc.hpp> #include <hyprutils/math/Misc.hpp>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
@ -9,7 +10,7 @@ Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) : x(xx), y(yy) {
; ;
} }
Hyprutils::Math::Vector2D::Vector2D(int xx, int yy) : x((double)xx), y((double)yy) { Hyprutils::Math::Vector2D::Vector2D(int xx, int yy) : x(sc<double>(xx)), y(sc<double>(yy)) {
; ;
} }
@ -59,23 +60,14 @@ Vector2D Hyprutils::Math::Vector2D::getComponentMax(const Vector2D& other) const
Vector2D Hyprutils::Math::Vector2D::transform(eTransform transform, const Vector2D& monitorSize) const { Vector2D Hyprutils::Math::Vector2D::transform(eTransform transform, const Vector2D& monitorSize) const {
switch (transform) { switch (transform) {
case HYPRUTILS_TRANSFORM_NORMAL: case HYPRUTILS_TRANSFORM_NORMAL: return *this;
return *this; case HYPRUTILS_TRANSFORM_90: return Vector2D(y, monitorSize.y - x);
case HYPRUTILS_TRANSFORM_90: case HYPRUTILS_TRANSFORM_180: return Vector2D(monitorSize.x - x, monitorSize.y - y);
return Vector2D(y, monitorSize.y - x); case HYPRUTILS_TRANSFORM_270: return Vector2D(monitorSize.x - y, x);
case HYPRUTILS_TRANSFORM_180: case HYPRUTILS_TRANSFORM_FLIPPED: return Vector2D(monitorSize.x - x, y);
return Vector2D(monitorSize.x - x, monitorSize.y - y); case HYPRUTILS_TRANSFORM_FLIPPED_90: return Vector2D(y, x);
case HYPRUTILS_TRANSFORM_270: case HYPRUTILS_TRANSFORM_FLIPPED_180: return Vector2D(x, monitorSize.y - y);
return Vector2D(monitorSize.x - y, x); case HYPRUTILS_TRANSFORM_FLIPPED_270: return Vector2D(monitorSize.x - y, monitorSize.y - x);
case HYPRUTILS_TRANSFORM_FLIPPED: default: return *this;
return Vector2D(monitorSize.x - x, y);
case HYPRUTILS_TRANSFORM_FLIPPED_90:
return Vector2D(y, x);
case HYPRUTILS_TRANSFORM_FLIPPED_180:
return Vector2D(x, monitorSize.y - y);
case HYPRUTILS_TRANSFORM_FLIPPED_270:
return Vector2D(monitorSize.x - y, monitorSize.y - x);
default:
return *this;
} }
} }

View file

@ -1,4 +1,5 @@
#include <hyprutils/os/Process.hpp> #include <hyprutils/os/Process.hpp>
#include <hyprutils/memory/Casts.hpp>
using namespace Hyprutils::OS; using namespace Hyprutils::OS;
#include <csignal> #include <csignal>
@ -61,7 +62,7 @@ bool Hyprutils::OS::CProcess::runSync() {
dup2(errPipe[1], 2 /* stderr */); dup2(errPipe[1], 2 /* stderr */);
// build argv // build argv
std::vector<const char*> argsC; std::vector<char*> argsC;
argsC.emplace_back(strdup(m_impl->binary.c_str())); argsC.emplace_back(strdup(m_impl->binary.c_str()));
for (auto& arg : m_impl->args) { for (auto& arg : m_impl->args) {
// TODO: does this leak? Can we just pipe c_str() as the strings won't be realloc'd? // TODO: does this leak? Can we just pipe c_str() as the strings won't be realloc'd?
@ -75,7 +76,7 @@ bool Hyprutils::OS::CProcess::runSync() {
setenv(n.c_str(), v.c_str(), 1); setenv(n.c_str(), v.c_str(), 1);
} }
execvp(m_impl->binary.c_str(), (char* const*)argsC.data()); execvp(m_impl->binary.c_str(), argsC.data());
exit(1); exit(1);
} else { } else {
// parent // parent
@ -129,7 +130,7 @@ bool Hyprutils::OS::CProcess::runSync() {
if (pollfds[0].revents & POLLIN) { if (pollfds[0].revents & POLLIN) {
while ((ret = read(outPipe[0], buf.data(), 1023)) > 0) { while ((ret = read(outPipe[0], buf.data(), 1023)) > 0) {
m_impl->out += std::string_view{(char*)buf.data(), (size_t)ret}; m_impl->out += std::string_view{buf.data(), sc<size_t>(ret)};
} }
buf.fill(0); buf.fill(0);
@ -137,7 +138,7 @@ bool Hyprutils::OS::CProcess::runSync() {
if (pollfds[1].revents & POLLIN) { if (pollfds[1].revents & POLLIN) {
while ((ret = read(errPipe[0], buf.data(), 1023)) > 0) { while ((ret = read(errPipe[0], buf.data(), 1023)) > 0) {
m_impl->err += std::string_view{(char*)buf.data(), (size_t)ret}; m_impl->err += std::string_view{buf.data(), sc<size_t>(ret)};
} }
buf.fill(0); buf.fill(0);
@ -146,13 +147,13 @@ bool Hyprutils::OS::CProcess::runSync() {
// Final reads. Nonblock, so its ok. // Final reads. Nonblock, so its ok.
while ((ret = read(outPipe[0], buf.data(), 1023)) > 0) { while ((ret = read(outPipe[0], buf.data(), 1023)) > 0) {
m_impl->out += std::string_view{(char*)buf.data(), (size_t)ret}; m_impl->out += std::string_view{buf.data(), sc<size_t>(ret)};
} }
buf.fill(0); buf.fill(0);
while ((ret = read(errPipe[0], buf.data(), 1023)) > 0) { while ((ret = read(errPipe[0], buf.data(), 1023)) > 0) {
m_impl->err += std::string_view{(char*)buf.data(), (size_t)ret}; m_impl->err += std::string_view{buf.data(), sc<size_t>(ret)};
} }
buf.fill(0); buf.fill(0);
@ -198,7 +199,7 @@ bool Hyprutils::OS::CProcess::runAsync() {
close(socket[0]); close(socket[0]);
close(socket[1]); close(socket[1]);
// build argv // build argv
std::vector<const char*> argsC; std::vector<char*> argsC;
argsC.emplace_back(strdup(m_impl->binary.c_str())); argsC.emplace_back(strdup(m_impl->binary.c_str()));
for (auto& arg : m_impl->args) { for (auto& arg : m_impl->args) {
argsC.emplace_back(strdup(arg.c_str())); argsC.emplace_back(strdup(arg.c_str()));
@ -216,7 +217,7 @@ bool Hyprutils::OS::CProcess::runAsync() {
if (m_impl->stderrFD != -1) if (m_impl->stderrFD != -1)
dup2(m_impl->stderrFD, 2); dup2(m_impl->stderrFD, 2);
execvp(m_impl->binary.c_str(), (char* const*)argsC.data()); execvp(m_impl->binary.c_str(), argsC.data());
_exit(0); _exit(0);
} }
close(socket[0]); close(socket[0]);

View file

@ -16,5 +16,5 @@ void Hyprutils::Signal::CSignalListener::emitInternal(void* data) {
void Hyprutils::Signal::CSignalListener::emit(std::any data) { void Hyprutils::Signal::CSignalListener::emit(std::any data) {
auto dataTuple = std::tuple<std::any>(data); auto dataTuple = std::tuple<std::any>(data);
emitInternal(static_cast<void*>(&dataTuple)); emitInternal(&dataTuple);
} }

View file

@ -62,7 +62,7 @@ class CMyAnimationManager : public CAnimationManager {
switch (PAV->m_Type) { switch (PAV->m_Type) {
case eAVTypes::INT: { case eAVTypes::INT: {
auto avInt = dynamic_cast<CAnimatedVariable<int>*>(PAV.get()); auto avInt = dc<CAnimatedVariable<int>*>(PAV.get());
if (!avInt) if (!avInt)
std::cout << Colors::RED << "Dynamic cast upcast failed" << Colors::RESET; std::cout << Colors::RED << "Dynamic cast upcast failed" << Colors::RESET;
@ -70,7 +70,7 @@ class CMyAnimationManager : public CAnimationManager {
avInt->value() = avInt->begun() + (DELTA * POINTY); avInt->value() = avInt->begun() + (DELTA * POINTY);
} break; } break;
case eAVTypes::TEST: { case eAVTypes::TEST: {
auto avCustom = dynamic_cast<CAnimatedVariable<SomeTestType>*>(PAV.get()); auto avCustom = dc<CAnimatedVariable<SomeTestType>*>(PAV.get());
if (!avCustom) if (!avCustom)
std::cout << Colors::RED << "Dynamic cast upcast failed" << Colors::RESET; std::cout << Colors::RED << "Dynamic cast upcast failed" << Colors::RESET;
@ -93,7 +93,7 @@ class CMyAnimationManager : public CAnimationManager {
constexpr const eAVTypes EAVTYPE = std::is_same_v<VarType, int> ? eAVTypes::INT : eAVTypes::TEST; constexpr const eAVTypes EAVTYPE = std::is_same_v<VarType, int> ? eAVTypes::INT : eAVTypes::TEST;
const auto PAV = makeShared<CGenericAnimatedVariable<VarType, EmtpyContext>>(); const auto PAV = makeShared<CGenericAnimatedVariable<VarType, EmtpyContext>>();
PAV->create(EAVTYPE, static_cast<CAnimationManager*>(this), PAV, v); PAV->create(EAVTYPE, sc<CAnimationManager*>(this), PAV, v);
PAV->setConfig(animationTree.getConfig(animationConfigName)); PAV->setConfig(animationTree.getConfig(animationConfigName));
av = std::move(PAV); av = std::move(PAV);
} }
@ -348,7 +348,7 @@ int main(int argc, char** argv, char** envp) {
*s.m_iA = 5; *s.m_iA = 5;
s.m_iA->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> v) { s.m_iA->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> v) {
endCallbackRan++; endCallbackRan++;
const auto PAV = dynamic_cast<CAnimatedVariable<int>*>(v.lock().get()); const auto PAV = dc<CAnimatedVariable<int>*>(v.lock().get());
*PAV = 10; *PAV = 10;
PAV->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> v) { endCallbackRan++; }); PAV->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> v) { endCallbackRan++; });