From 17e0c79139a6b742ce63a7e87d282b0fbaaf956f Mon Sep 17 00:00:00 2001 From: vaxerski Date: Sun, 31 Dec 2023 14:20:50 +0100 Subject: [PATCH] api: add typedefs for config types --- include/hyprlang.hpp | 50 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/include/hyprlang.hpp b/include/hyprlang.hpp index 4cf64a0..263e7b0 100644 --- a/include/hyprlang.hpp +++ b/include/hyprlang.hpp @@ -14,6 +14,36 @@ struct SSpecialCategory; namespace Hyprlang { + struct SVector2D; + class CConfigCustomValueType; + + /* Variable typedefs */ + + /*! + Basic integer config type + */ + typedef int64_t INT; + + /*! + Basic float config type + */ + typedef float FLOAT; + + /*! + Basic string config type + */ + typedef const char* STRING; + + /*! + Basic vec2 config type + */ + typedef SVector2D VEC2; + + /*! + Custom config type + */ + typedef CConfigCustomValueType CUSTOMTYPE; + /*! A very simple vector type */ @@ -136,11 +166,11 @@ namespace Hyprlang { class CConfigValue { public: CConfigValue(); - CConfigValue(const int64_t value); - CConfigValue(const float value); - CConfigValue(const char* value); - CConfigValue(const SVector2D value); - CConfigValue(CConfigCustomValueType&& value); + CConfigValue(const INT value); + CConfigValue(const FLOAT value); + CConfigValue(const STRING value); + CConfigValue(const VEC2 value); + CConfigValue(CUSTOMTYPE&& value); CConfigValue(const CConfigValue&) = delete; CConfigValue(CConfigValue&&) = delete; CConfigValue(const CConfigValue&&) = delete; @@ -168,11 +198,11 @@ namespace Hyprlang { std::any getValue() const { switch (m_eType) { case CONFIGDATATYPE_EMPTY: throw; - case CONFIGDATATYPE_INT: return std::any(*reinterpret_cast(m_pData)); - case CONFIGDATATYPE_FLOAT: return std::any(*reinterpret_cast(m_pData)); - case CONFIGDATATYPE_STR: return std::any(reinterpret_cast(m_pData)); - case CONFIGDATATYPE_VEC2: return std::any(*reinterpret_cast(m_pData)); - case CONFIGDATATYPE_CUSTOM: return std::any(reinterpret_cast(m_pData)->data); + case CONFIGDATATYPE_INT: return std::any(*reinterpret_cast(m_pData)); + case CONFIGDATATYPE_FLOAT: return std::any(*reinterpret_cast(m_pData)); + case CONFIGDATATYPE_STR: return std::any(reinterpret_cast(m_pData)); + case CONFIGDATATYPE_VEC2: return std::any(*reinterpret_cast(m_pData)); + case CONFIGDATATYPE_CUSTOM: return std::any(reinterpret_cast(m_pData)->data); default: throw; } return {}; // unreachable