#ifndef CREATURELIB_EFFECTPARAMETER_HPP #define CREATURELIB_EFFECTPARAMETER_HPP #include #include #include #include "Exceptions/CreatureException.hpp" namespace CreatureLib::Library { ENUM(EffectParameterType, uint8_t, None, Bool, Int, Float, String); class EffectParameter { private: EffectParameterType _type = EffectParameterType::None; std::variant _value; public: inline EffectParameter() : _type(EffectParameterType::None){}; inline explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){}; inline explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){}; inline explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){}; inline explicit EffectParameter(const ArbUt::StringView& s) : _type(EffectParameterType::String), _value(s){}; EffectParameter(const EffectParameter& other) = delete; EffectParameter& operator=(const EffectParameter& other) = delete; inline EffectParameterType GetType() const noexcept { return _type; } bool AsBool() const { if (_type != EffectParameterType::Bool) { std::stringstream ss; ss << "Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type); throw CreatureException(ss.str()); } return std::get(_value); } int64_t AsInt() const { if (_type != EffectParameterType::Int) { if (_type == EffectParameterType::Float) { return static_cast(std::get(_value)); } std::stringstream ss; ss << "Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type); throw CreatureException(ss.str()); } return std::get(_value); } float AsFloat() const { if (_type != EffectParameterType::Float) { if (_type == EffectParameterType::Int) { return static_cast(std::get(_value)); } std::stringstream ss; ss << "Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type); throw CreatureException(ss.str()); } return std::get(_value); } const ArbUt::StringView& AsString() const { if (_type != EffectParameterType::String) { std::stringstream ss; ss << "Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type); throw CreatureException(ss.str()); } return std::get(_value); } }; } #endif // CREATURELIB_EFFECTPARAMETER_HPP