From c902f9098b331302aaa1baac77d1575db624a132 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 26 Apr 2016 16:39:56 -0700 Subject: [core] Rationalize naming for style-related code --- include/mbgl/style/property_value.hpp | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 include/mbgl/style/property_value.hpp (limited to 'include/mbgl/style/property_value.hpp') diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp new file mode 100644 index 0000000000..d8f83a0fb3 --- /dev/null +++ b/include/mbgl/style/property_value.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace style { + +class Undefined {}; + +template +class PropertyValue { +private: + using Value = variant>; + Value value; + +public: + PropertyValue() : value() {} + PropertyValue( T constant) : value(constant) {} + PropertyValue(Function function) : value(function) {} + + bool isUndefined() const { return value.which() == 0; } + bool isConstant() const { return value.which() == 1; } + bool isFunction() const { return value.which() == 2; } + + const T & asConstant() const { return value.template get< T >(); } + const Function& asFunction() const { return value.template get>(); } + + explicit operator bool() const { return !isUndefined(); }; + + template + static auto visit(const PropertyValue& value, Visitor&& visitor) { + return Value::visit(value.value, visitor); + } +}; + +} // namespace style +} // namespace mbgl -- cgit v1.2.1