#pragma once #include #include #include #include #include "HostFunctionHandler.h" #include "JSIStoreValueUser.h" #include "SharedParent.h" #include "WorkletsCache.h" namespace reanimated { class HostFunctionWrapper; class AnimatedSensorModule; class ValueWrapper { friend AnimatedSensorModule; public: ValueWrapper() {} explicit ValueWrapper(ValueType _type) : type(_type) {} ValueType getType() const { return type; } virtual ~ValueWrapper() {} static inline bool asBoolean( const std::unique_ptr &valueContainer); static inline double asNumber( const std::unique_ptr &valueContainer); static inline const std::string &asString( const std::unique_ptr &valueContainer); static inline const std::shared_ptr &asHostFunction( const std::unique_ptr &valueContainer); static inline const std::shared_ptr &asFrozenObject( const std::unique_ptr &valueContainer); static inline const std::shared_ptr &asRemoteObject( const std::unique_ptr &valueContainer); static inline std::vector> &asFrozenArray( const std::unique_ptr &valueContainer); static inline const std::shared_ptr &asMutableValue( const std::unique_ptr &valueContainer); static const HostFunctionWrapper *asHostFunctionWrapper( const std::unique_ptr &valueContainer); protected: ValueType type; }; class BooleanValueWrapper : public ValueWrapper { public: explicit BooleanValueWrapper(const bool _value) : ValueWrapper(ValueType::BoolType), value(_value) {} bool value; }; class NumberValueWrapper : public ValueWrapper { public: explicit NumberValueWrapper(const double _value) : ValueWrapper(ValueType::NumberType), value(_value) {} double value; }; class StringValueWrapper : public ValueWrapper { public: explicit StringValueWrapper(const std::string &_value) : ValueWrapper(ValueType::StringType), value(_value) {} std::string value; }; class HostFunctionWrapper : public ValueWrapper { public: explicit HostFunctionWrapper( const std::shared_ptr &_value) : ValueWrapper(ValueType::HostFunctionType), value(_value) {} std::shared_ptr value; }; class FrozenObjectWrapper : public ValueWrapper { public: explicit FrozenObjectWrapper(const std::shared_ptr &_value) : ValueWrapper(ValueType::FrozenObjectType), value(_value) {} std::shared_ptr value; }; class RemoteObjectWrapper : public ValueWrapper { public: explicit RemoteObjectWrapper(const std::shared_ptr &_value) : ValueWrapper(ValueType::RemoteObjectType), value(_value) {} std::shared_ptr value; }; class FrozenArrayWrapper : public ValueWrapper { public: FrozenArrayWrapper() : ValueWrapper(ValueType::FrozenArrayType) {} explicit FrozenArrayWrapper( const std::vector> &_value) : ValueWrapper(ValueType::FrozenArrayType), value(_value) {} std::vector> value; }; class MutableValueWrapper : public ValueWrapper { public: explicit MutableValueWrapper(const std::shared_ptr &_value) : ValueWrapper(ValueType::MutableValueType), value(_value) {} std::shared_ptr value; }; inline bool ValueWrapper::asBoolean( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline double ValueWrapper::asNumber( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline const std::string &ValueWrapper::asString( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline const std::shared_ptr &ValueWrapper::asHostFunction( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline const std::shared_ptr &ValueWrapper::asFrozenObject( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline const std::shared_ptr &ValueWrapper::asRemoteObject( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline std::vector> &ValueWrapper::asFrozenArray( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline const std::shared_ptr &ValueWrapper::asMutableValue( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get())->value; } inline const HostFunctionWrapper *ValueWrapper::asHostFunctionWrapper( const std::unique_ptr &valueContainer) { return static_cast(valueContainer.get()); } } // namespace reanimated