#ifndef AnyValue_hpp #define AnyValue_hpp #include #import #include #include "Lottie/Private/Model/Text/TextDocument.hpp" #include "Lottie/Private/Model/ShapeItems/GradientFill.hpp" #include "Lottie/Private/Model/Objects/DashElement.hpp" #include #include namespace lottie { class AnyValue { public: enum class Type { Float, Vector1D, Vector2D, Vector3D, Color, BezierPath, TextDocument, GradientColorSet, DashPattern }; public: AnyValue(float value) : _type(Type::Float), _floatValue(value) { } AnyValue(Vector1D const &value) : _type(Type::Vector1D), _vector1DValue(value) { } AnyValue(Vector2D const &value) : _type(Type::Vector2D), _vector2DValue(value) { } AnyValue(Vector3D const & value) : _type(Type::Vector3D), _vector3DValue(value) { } AnyValue(Color const &value) : _type(Type::Color), _colorValue(value) { } AnyValue(BezierPath const &value) : _type(Type::BezierPath), _bezierPathValue(value) { } AnyValue(TextDocument const &value) : _type(Type::TextDocument), _textDocumentValue(value) { } AnyValue(GradientColorSet const &value) : _type(Type::GradientColorSet), _gradientColorSetValue(value) { } AnyValue(DashPattern const &value) : _type(Type::DashPattern), _dashPatternValue(value) { } template::value>> float get() { return asFloat(); } template::value>> Vector1D get() { return asVector1D(); } template::value>> Vector2D get() { return asVector2D(); } template::value>> Vector3D get() { return asVector3D(); } template::value>> Color get() { return asColor(); } template::value>> BezierPath get() { return asBezierPath(); } template::value>> TextDocument get() { return asTextDocument(); } template::value>> GradientColorSet get() { return asGradientColorSet(); } template::value>> DashPattern get() { return asDashPattern(); } public: Type type() { return _type; } float asFloat() { return _floatValue.value(); } Vector1D asVector1D() { return _vector1DValue.value(); } Vector2D asVector2D() { return _vector2DValue.value(); } Vector3D asVector3D() { return _vector3DValue.value(); } Color asColor() { return _colorValue.value(); } BezierPath asBezierPath() { return _bezierPathValue.value(); } TextDocument asTextDocument() { return _textDocumentValue.value(); } GradientColorSet asGradientColorSet() { return _gradientColorSetValue.value(); } DashPattern asDashPattern() { return _dashPatternValue.value(); } private: Type _type; std::optional _floatValue; std::optional _vector1DValue; std::optional _vector2DValue; std::optional _vector3DValue; std::optional _colorValue; std::optional _bezierPathValue; std::optional _textDocumentValue; std::optional _gradientColorSetValue; std::optional _dashPatternValue; }; template struct AnyValueType { }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::Float; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::Vector1D; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::Vector2D; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::Vector3D; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::Color; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::BezierPath; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::TextDocument; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::GradientColorSet; } }; template<> struct AnyValueType { static AnyValue::Type type() { return AnyValue::Type::DashPattern; } }; } #endif /* AnyValue_hpp */