move to std::map for classes
This commit is contained in:
@@ -2,21 +2,35 @@
|
||||
#define LLMR_STYLE_CLASS_DESCRIPTION
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include "properties.hpp"
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class ClassDescription {
|
||||
public:
|
||||
BackgroundClass background;
|
||||
std::map<std::string, FillClass> fill;
|
||||
std::map<std::string, LineClass> line;
|
||||
std::map<std::string, IconClass> icon;
|
||||
std::map<std::string, TextClass> text;
|
||||
std::map<std::string, RasterClass> raster;
|
||||
std::map<std::string, CompositeClass> composite;
|
||||
inline const ClassProperties &operator[](const std::string &name) const {
|
||||
auto it = styles.find(name);
|
||||
if (it != styles.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
return defaultProperties;
|
||||
}
|
||||
}
|
||||
|
||||
void addClass(const std::string &name, ClassProperties &&properties);
|
||||
|
||||
inline std::unordered_map<std::string, ClassProperties>::const_iterator begin() const {
|
||||
return styles.begin();
|
||||
}
|
||||
|
||||
inline std::unordered_map<std::string, ClassProperties>::const_iterator end() const {
|
||||
return styles.end();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, ClassProperties> styles;
|
||||
static const ClassProperties defaultProperties;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -6,9 +6,12 @@
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
#include <memory>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <llmr/util/variant.hpp>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
@@ -16,7 +19,10 @@ namespace llmr {
|
||||
typedef std::array<float, 4> Color;
|
||||
|
||||
struct PropertyTransition {
|
||||
inline PropertyTransition(uint16_t duration, uint16_t delay = 0) : duration(duration), delay(delay) {}
|
||||
inline PropertyTransition(uint16_t duration, uint16_t delay = 0)
|
||||
: duration(duration), delay(delay) {}
|
||||
inline PropertyTransition(const PropertyTransition &transition)
|
||||
: duration(transition.duration), delay(transition.delay) {}
|
||||
uint16_t duration = 0;
|
||||
uint16_t delay = 0;
|
||||
};
|
||||
@@ -82,21 +88,124 @@ struct FunctionProperty {
|
||||
std::vector<float> values;
|
||||
|
||||
inline FunctionProperty() : function(&functions::null) {}
|
||||
|
||||
inline FunctionProperty(const FunctionProperty &property)
|
||||
: function(property.function), values(property.values) {}
|
||||
inline FunctionProperty(FunctionProperty &&property)
|
||||
: function(property.function), values(std::move(property.values)) {}
|
||||
|
||||
|
||||
inline void operator=(const FunctionProperty &rhs) {
|
||||
function = rhs.function;
|
||||
values = rhs.values;
|
||||
}
|
||||
|
||||
inline FunctionProperty(float value) : function(&functions::constant), values(1, value) {}
|
||||
template <typename T> inline T evaluate(float z) const { return function(z, values); }
|
||||
};
|
||||
|
||||
struct GenericClass {
|
||||
boost::optional<FunctionProperty> enabled;
|
||||
boost::optional<std::array<FunctionProperty, 2>> translate;
|
||||
boost::optional<PropertyTransition> translate_transition;
|
||||
boost::optional<TranslateAnchor> translateAnchor;
|
||||
boost::optional<FunctionProperty> opacity;
|
||||
boost::optional<PropertyTransition> opacity_transition;
|
||||
boost::optional<FunctionProperty> prerender;
|
||||
boost::optional<FunctionProperty> prerenderBuffer;
|
||||
boost::optional<FunctionProperty> prerenderSize;
|
||||
boost::optional<FunctionProperty> prerenderBlur;
|
||||
|
||||
enum class RenderType {
|
||||
Fill,
|
||||
Line,
|
||||
Icon,
|
||||
Text,
|
||||
Raster,
|
||||
Composite,
|
||||
Background
|
||||
};
|
||||
|
||||
enum class ClassPropertyKey {
|
||||
Enabled,
|
||||
TranslateX,
|
||||
TranslateY,
|
||||
TranslateTransition,
|
||||
TranslateAnchor,
|
||||
Opacity,
|
||||
OpacityTransition,
|
||||
Prerender,
|
||||
PrerenderBuffer,
|
||||
PrerenderSize,
|
||||
PrerenderBlur,
|
||||
|
||||
FillWinding,
|
||||
FillAntialias,
|
||||
FillColor,
|
||||
FillColorTransition,
|
||||
FillStrokeColor,
|
||||
FillStrokeColorTransition,
|
||||
FillImage,
|
||||
|
||||
LineWidth,
|
||||
LineWidthTransition,
|
||||
LineOffset,
|
||||
LineOffsetTransition,
|
||||
LineColor,
|
||||
LineColorTransition,
|
||||
LineDashLand,
|
||||
LineDashGap,
|
||||
LineDashTransition,
|
||||
|
||||
IconSize,
|
||||
IconColor,
|
||||
IconColorTransition,
|
||||
IconImage,
|
||||
IconRadius,
|
||||
IconRadiusTransition,
|
||||
IconBlur,
|
||||
IconBlurTransition,
|
||||
|
||||
TextColor,
|
||||
TextColorTransition,
|
||||
TextHaloColor,
|
||||
TextHaloColorTransition,
|
||||
TextHaloRadius,
|
||||
TextHaloRadiusTransition,
|
||||
TextHaloBlur,
|
||||
TextHaloBlurTransition,
|
||||
TextSize,
|
||||
TextRotate,
|
||||
TextAlwaysVisible,
|
||||
|
||||
BackgroundColor,
|
||||
BackgroundColorTransition,
|
||||
};
|
||||
|
||||
typedef util::variant<
|
||||
FunctionProperty,
|
||||
PropertyTransition,
|
||||
TranslateAnchor,
|
||||
Color,
|
||||
Winding,
|
||||
std::string,
|
||||
bool
|
||||
> ClassPropertyValue;
|
||||
|
||||
class ClassProperties {
|
||||
public:
|
||||
inline ClassProperties(RenderType type) : type(type) {}
|
||||
inline ClassProperties(ClassProperties &&properties)
|
||||
: type(properties.type), properties(std::move(properties.properties)) {}
|
||||
|
||||
template <typename T>
|
||||
inline const T *get(ClassPropertyKey key) const {
|
||||
const auto it = properties.find(key);
|
||||
if (it != properties.end() && it->second.is<T>()) {
|
||||
return ::std::addressof(it->second.get<T>());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
inline void emplace(Args&& ...args) {
|
||||
properties.emplace(::std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
const RenderType type;
|
||||
|
||||
private:
|
||||
std::map<ClassPropertyKey, ClassPropertyValue> properties;
|
||||
};
|
||||
|
||||
struct PrerenderProperties {
|
||||
@@ -137,17 +246,6 @@ struct GenericProperties {
|
||||
}
|
||||
};
|
||||
|
||||
struct IconClass : public GenericClass {
|
||||
boost::optional<FunctionProperty> size;
|
||||
boost::optional<Color> color;
|
||||
boost::optional<PropertyTransition> color_transition;
|
||||
boost::optional<std::string> image;
|
||||
boost::optional<FunctionProperty> radius;
|
||||
boost::optional<PropertyTransition> radius_transition;
|
||||
boost::optional<FunctionProperty> blur;
|
||||
boost::optional<PropertyTransition> blur_transition;
|
||||
};
|
||||
|
||||
struct IconProperties : public GenericProperties {
|
||||
inline IconProperties() : GenericProperties() {}
|
||||
float size = 0;
|
||||
@@ -157,17 +255,6 @@ struct IconProperties : public GenericProperties {
|
||||
float blur = 0;
|
||||
};
|
||||
|
||||
struct LineClass : public GenericClass {
|
||||
boost::optional<FunctionProperty> width;
|
||||
boost::optional<PropertyTransition> width_transition;
|
||||
boost::optional<FunctionProperty> offset;
|
||||
boost::optional<PropertyTransition> offset_transition;
|
||||
boost::optional<Color> color;
|
||||
boost::optional<PropertyTransition> color_transition;
|
||||
boost::optional<std::array<FunctionProperty, 2>> dash_array;
|
||||
boost::optional<PropertyTransition> dash_array_transition;
|
||||
};
|
||||
|
||||
struct LineProperties : public GenericProperties {
|
||||
inline LineProperties() : GenericProperties() {}
|
||||
float width = 0;
|
||||
@@ -176,16 +263,6 @@ struct LineProperties : public GenericProperties {
|
||||
std::array<float, 2> dash_array = {{ 1, -1 }};
|
||||
};
|
||||
|
||||
struct FillClass : public GenericClass {
|
||||
boost::optional<Winding> winding;
|
||||
boost::optional<FunctionProperty> antialias;
|
||||
boost::optional<Color> fill_color;
|
||||
boost::optional<PropertyTransition> fill_color_transition;
|
||||
boost::optional<Color> stroke_color;
|
||||
boost::optional<PropertyTransition> stroke_color_transition;
|
||||
boost::optional<std::string> image;
|
||||
};
|
||||
|
||||
struct FillProperties : public GenericProperties {
|
||||
inline FillProperties() : GenericProperties() {}
|
||||
Winding winding = Winding::NonZero;
|
||||
@@ -196,20 +273,6 @@ struct FillProperties : public GenericProperties {
|
||||
std::string image;
|
||||
};
|
||||
|
||||
struct TextClass : public GenericClass {
|
||||
boost::optional<Color> color;
|
||||
boost::optional<PropertyTransition> color_transition;
|
||||
boost::optional<Color> halo;
|
||||
boost::optional<PropertyTransition> halo_transition;
|
||||
boost::optional<FunctionProperty> halo_radius;
|
||||
boost::optional<PropertyTransition> halo_radius_transition;
|
||||
boost::optional<FunctionProperty> halo_blur;
|
||||
boost::optional<PropertyTransition> halo_blur_transition;
|
||||
boost::optional<FunctionProperty> size;
|
||||
boost::optional<FunctionProperty> rotate;
|
||||
boost::optional<FunctionProperty> always_visible;
|
||||
};
|
||||
|
||||
struct TextProperties : public GenericProperties {
|
||||
inline TextProperties() : GenericProperties() {}
|
||||
Color color = {{ 0, 0, 0, 1 }};
|
||||
@@ -221,26 +284,15 @@ struct TextProperties : public GenericProperties {
|
||||
bool always_visible = false;
|
||||
};
|
||||
|
||||
struct BackgroundClass : public GenericClass {
|
||||
boost::optional<Color> color;
|
||||
boost::optional<PropertyTransition> color_transition;
|
||||
};
|
||||
|
||||
struct BackgroundProperties : public GenericProperties {
|
||||
inline BackgroundProperties() : GenericProperties() {}
|
||||
Color color = {{ 1, 1, 1, 1 }};
|
||||
};
|
||||
|
||||
struct RasterClass : public GenericClass {
|
||||
};
|
||||
|
||||
struct RasterProperties : public GenericProperties {
|
||||
inline RasterProperties() : GenericProperties() {}
|
||||
};
|
||||
|
||||
struct CompositeClass : public GenericClass {
|
||||
};
|
||||
|
||||
struct CompositeProperties : public GenericProperties {
|
||||
inline CompositeProperties() : GenericProperties() {}
|
||||
};
|
||||
|
||||
@@ -69,7 +69,14 @@ private:
|
||||
uint64_t transitionDuration(const std::string &layer_name, TransitionablePropertyKey key) const;
|
||||
uint64_t transitionDelay(const std::string &layer_name, TransitionablePropertyKey key) const;
|
||||
|
||||
void cascadeProperties(GenericProperties &properties, const GenericClass& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(GenericProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(FillProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(LineProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(IconProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(TextProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(RasterProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(CompositeProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
void cascadeProperties(BackgroundProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z);
|
||||
|
||||
private:
|
||||
// Last applied settings.
|
||||
|
||||
@@ -30,14 +30,14 @@ private:
|
||||
const std::map<std::string, BucketDescription> &buckets,
|
||||
const std::map<std::string, std::string> &layerBuckets);
|
||||
|
||||
void parseGenericClass(GenericClass &klass, JSVal value);
|
||||
FillClass parseFillClass(JSVal value);
|
||||
LineClass parseLineClass(JSVal value);
|
||||
IconClass parseIconClass(JSVal value);
|
||||
TextClass parseTextClass(JSVal value);
|
||||
BackgroundClass parseBackgroundClass(JSVal value);
|
||||
RasterClass parseRasterClass(JSVal value);
|
||||
CompositeClass parseCompositeClass(JSVal value);
|
||||
void parseGenericClass(ClassProperties &klass, JSVal value);
|
||||
ClassProperties parseFillClass(JSVal value);
|
||||
ClassProperties parseLineClass(JSVal value);
|
||||
ClassProperties parseIconClass(JSVal value);
|
||||
ClassProperties parseTextClass(JSVal value);
|
||||
ClassProperties parseBackgroundClass(JSVal value);
|
||||
ClassProperties parseRasterClass(JSVal value);
|
||||
ClassProperties parseCompositeClass(JSVal value);
|
||||
|
||||
PropertyFilterExpression parseFilterOrExpression(JSVal value);
|
||||
|
||||
@@ -49,7 +49,7 @@ private:
|
||||
Value parseValue(JSVal value);
|
||||
FunctionProperty::fn parseFunctionType(JSVal type);
|
||||
FunctionProperty parseFunction(JSVal value);
|
||||
boost::optional<PropertyTransition> parseTransition(JSVal value, std::string property_name);
|
||||
void parseTransition(ClassProperties &klass, ClassPropertyKey key, JSVal value, std::string property_name);
|
||||
|
||||
private:
|
||||
std::map<std::string, const rapidjson::Value *> constants;
|
||||
|
||||
Reference in New Issue
Block a user