summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-10-24 16:41:04 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-10-24 16:41:04 +0200
commitd299e580886353e0813d30f9dee74639f899924a (patch)
treee73137e3258538cb5bbc634d1aff24c22e0f7a0f /include
parentcd9a89257a0004ca18460befc4b141bc07ed5c22 (diff)
parentcd44abcc588c9fc988589c148e76e4590c2197b8 (diff)
downloadqtlocation-mapboxgl-d299e580886353e0813d30f9dee74639f899924a.tar.gz
Merge remote-tracking branch 'origin/headless-display' into gyp-restructuring
Conflicts: Makefile ios/mapbox-gl-cocoa
Diffstat (limited to 'include')
-rw-r--r--include/csscolorparser/csscolorparser.hpp4
-rw-r--r--include/mbgl/geometry/anchor.hpp8
-rw-r--r--include/mbgl/geometry/buffer.hpp6
-rw-r--r--include/mbgl/geometry/elements_buffer.hpp6
-rw-r--r--include/mbgl/geometry/geometry.hpp4
-rw-r--r--include/mbgl/geometry/glyph_atlas.hpp4
-rw-r--r--include/mbgl/map/map.hpp3
-rw-r--r--include/mbgl/map/tile.hpp4
-rw-r--r--include/mbgl/map/view.hpp12
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp1
-rw-r--r--include/mbgl/platform/default/headless_view.hpp36
-rw-r--r--include/mbgl/renderer/frame_history.hpp2
-rw-r--r--include/mbgl/renderer/painter.hpp10
-rw-r--r--include/mbgl/style/class_dictionary.hpp13
-rw-r--r--include/mbgl/style/class_properties.hpp4
-rw-r--r--include/mbgl/style/filter_comparison.hpp6
-rw-r--r--include/mbgl/style/filter_expression.hpp2
-rw-r--r--include/mbgl/style/function_properties.hpp6
-rw-r--r--include/mbgl/style/style_source.hpp4
-rw-r--r--include/mbgl/text/collision.hpp1
-rw-r--r--include/mbgl/text/glyph.hpp10
-rw-r--r--include/mbgl/text/types.hpp63
-rw-r--r--include/mbgl/util/enum.hpp8
-rw-r--r--include/mbgl/util/error.hpp2
-rw-r--r--include/mbgl/util/optional.hpp69
-rw-r--r--include/mbgl/util/pbf.hpp10
-rw-r--r--include/mbgl/util/rect.hpp2
-rw-r--r--include/mbgl/util/transition.hpp24
-rw-r--r--include/mbgl/util/uv_detail.hpp16
-rw-r--r--include/mbgl/util/variant.hpp20
-rw-r--r--include/mbgl/util/vec.hpp6
31 files changed, 223 insertions, 143 deletions
diff --git a/include/csscolorparser/csscolorparser.hpp b/include/csscolorparser/csscolorparser.hpp
index 1d074627f6..6caf796943 100644
--- a/include/csscolorparser/csscolorparser.hpp
+++ b/include/csscolorparser/csscolorparser.hpp
@@ -31,8 +31,8 @@ namespace CSSColorParser {
struct Color {
inline Color() {}
- inline Color(unsigned char r, unsigned char g, unsigned char b, float a)
- : r(r), g(g), b(b), a(a) {}
+ inline Color(unsigned char r_, unsigned char g_, unsigned char b_, float a_)
+ : r(r_), g(g_), b(b_), a(a_) {}
unsigned char r = 0, g = 0, b = 0;
float a = 1.0f;
};
diff --git a/include/mbgl/geometry/anchor.hpp b/include/mbgl/geometry/anchor.hpp
index ab006530ff..d30394f0b9 100644
--- a/include/mbgl/geometry/anchor.hpp
+++ b/include/mbgl/geometry/anchor.hpp
@@ -12,10 +12,10 @@ struct Anchor {
float scale = 0.0f;
int segment = -1;
- explicit Anchor(float x, float y, float angle, float scale)
- : x(x), y(y), angle(angle), scale(scale) {}
- explicit Anchor(float x, float y, float angle, float scale, int segment)
- : x(x), y(y), angle(angle), scale(scale), segment(segment) {}
+ explicit Anchor(float x_, float y_, float angle_, float scale_)
+ : x(x_), y(y_), angle(angle_), scale(scale_) {}
+ explicit Anchor(float x_, float y_, float angle_, float scale_, int segment_)
+ : x(x_), y(y_), angle(angle_), scale(scale_), segment(segment_) {}
};
typedef std::vector<Anchor> Anchors;
diff --git a/include/mbgl/geometry/buffer.hpp b/include/mbgl/geometry/buffer.hpp
index 446177d443..80cc6b9d1a 100644
--- a/include/mbgl/geometry/buffer.hpp
+++ b/include/mbgl/geometry/buffer.hpp
@@ -84,15 +84,15 @@ protected:
}
// Get a pointer to the item at a given index.
- inline void *getElement(size_t index) {
+ inline void *getElement(size_t i) {
if (array == nullptr) {
throw std::runtime_error("Buffer was already deleted or doesn't contain elements");
}
- if (index * itemSize >= pos) {
+ if (i * itemSize >= pos) {
throw new std::runtime_error("Can't get element after array bounds");
} else {
- return static_cast<char *>(array) + (index * itemSize);
+ return static_cast<char *>(array) + (i * itemSize);
}
}
diff --git a/include/mbgl/geometry/elements_buffer.hpp b/include/mbgl/geometry/elements_buffer.hpp
index 56080e29fe..045560f9aa 100644
--- a/include/mbgl/geometry/elements_buffer.hpp
+++ b/include/mbgl/geometry/elements_buffer.hpp
@@ -16,9 +16,9 @@ struct ElementGroup : public util::noncopyable {
uint32_t elements_length;
ElementGroup() : vertex_length(0), elements_length(0) {}
- ElementGroup(uint32_t vertex_length, uint32_t elements_length)
- : vertex_length(vertex_length),
- elements_length(elements_length) {
+ ElementGroup(uint32_t vertex_length_, uint32_t elements_length_)
+ : vertex_length(vertex_length_),
+ elements_length(elements_length_) {
}
ElementGroup(ElementGroup &&rhs) noexcept
diff --git a/include/mbgl/geometry/geometry.hpp b/include/mbgl/geometry/geometry.hpp
index 961569204d..484d17b36d 100644
--- a/include/mbgl/geometry/geometry.hpp
+++ b/include/mbgl/geometry/geometry.hpp
@@ -30,8 +30,8 @@ private:
int32_t ox, oy;
};
-Geometry::Geometry(pbf& data)
- : data(data),
+Geometry::Geometry(pbf& data_)
+ : data(data_),
cmd(1),
length(0),
x(0), y(0),
diff --git a/include/mbgl/geometry/glyph_atlas.hpp b/include/mbgl/geometry/glyph_atlas.hpp
index 336c4af284..5b09cbcd6d 100644
--- a/include/mbgl/geometry/glyph_atlas.hpp
+++ b/include/mbgl/geometry/glyph_atlas.hpp
@@ -18,8 +18,8 @@ public:
private:
struct GlyphValue {
- GlyphValue(const Rect<uint16_t>& rect, uint64_t id)
- : rect(rect), ids({ id }) {}
+ GlyphValue(const Rect<uint16_t>& rect_, uint64_t id)
+ : rect(rect_), ids({ id }) {}
Rect<uint16_t> rect;
std::set<uint64_t> ids;
};
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index bea82e6b4c..ab9775a8c9 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -63,6 +63,9 @@ public:
// Triggers a cleanup that releases resources.
void cleanup();
+ // Releases resources immediately
+ void terminate();
+
// Controls buffer swapping.
bool needsSwap();
void swapped();
diff --git a/include/mbgl/map/tile.hpp b/include/mbgl/map/tile.hpp
index b9f0556add..1ae13dd79d 100644
--- a/include/mbgl/map/tile.hpp
+++ b/include/mbgl/map/tile.hpp
@@ -37,8 +37,8 @@ public:
const int8_t z = 0;
const int32_t x = 0, y = 0;
- inline explicit ID(int8_t z, int32_t x, int32_t y)
- : w((x < 0 ? x - (1 << z) + 1 : x) / (1 << z)), z(z), x(x), y(y) {}
+ inline explicit ID(int8_t z_, int32_t x_, int32_t y_)
+ : w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_) {}
inline uint64_t to_uint64() const {
return ((std::pow(2, z) * y + x) * 32) + z;
diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp
index bbdcd97c79..513c73b483 100644
--- a/include/mbgl/map/view.hpp
+++ b/include/mbgl/map/view.hpp
@@ -22,8 +22,8 @@ enum MapChange : uint8_t {
class View {
public:
- virtual void initialize(Map *map) {
- this->map = map;
+ virtual void initialize(Map *map_) {
+ map = map_;
}
// Called from the render (=GL) thread. Signals that the context should
@@ -35,11 +35,9 @@ public:
// renderer setup since the render thread doesn't switch the contexts.
virtual void make_active() = 0;
- // Returns the base framebuffer object, if any, and 0 if using the system
- // provided framebuffer.
- virtual unsigned int root_fbo() {
- return 0;
- }
+ // Called from the render thread. Makes the GL context inactive in the current
+ // thread. This is called once just before the rendering thread terminates.
+ virtual void make_inactive() = 0;
virtual void notify() = 0;
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 481b1598bb..6e91c1125e 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -17,6 +17,7 @@ public:
void initialize(mbgl::Map *map);
void swap();
void make_active();
+ void make_inactive();
void notify();
void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0);
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp
index 42f9c46da2..c0baddb884 100644
--- a/include/mbgl/platform/default/headless_view.hpp
+++ b/include/mbgl/platform/default/headless_view.hpp
@@ -1,51 +1,63 @@
-#ifndef MBGL_COMMON_HEADLESS_CGL
-#define MBGL_COMMON_HEADLESS_CGL
+#ifndef MBGL_COMMON_HEADLESS_VIEW
+#define MBGL_COMMON_HEADLESS_VIEW
#ifdef __APPLE__
#define MBGL_USE_CGL 1
#else
+#define GL_GLEXT_PROTOTYPES
#include <GL/glx.h>
#define MBGL_USE_GLX 1
#endif
#include <mbgl/map/view.hpp>
#include <mbgl/platform/gl.hpp>
-#include <mbgl/util/time.hpp>
+
+#include <memory>
namespace mbgl {
+class HeadlessDisplay;
+
class HeadlessView : public View {
public:
HeadlessView();
+ HeadlessView(std::shared_ptr<HeadlessDisplay> display);
~HeadlessView();
+ void createContext();
+
void resize(uint16_t width, uint16_t height, float pixelRatio);
+ const std::unique_ptr<uint32_t[]> readPixels();
void notify();
void notify_map_change(MapChange change, timestamp delay = 0);
void make_active();
+ void make_inactive();
void swap();
- unsigned int root_fbo();
private:
void clear_buffers();
-
private:
+ std::shared_ptr<HeadlessDisplay> display_;
+ uint16_t width_;
+ uint16_t height_;
+ float pixelRatio_;
+
#if MBGL_USE_CGL
CGLContextObj gl_context;
- GLuint fbo = 0;
- GLuint fbo_depth_stencil = 0;
- GLuint fbo_color = 0;
#endif
#if MBGL_USE_GLX
- GLXContext gl_context = nullptr;
- XVisualInfo *x_info = nullptr;
Display *x_display = nullptr;
- Pixmap x_pixmap = 0;
- GLXPixmap glx_pixmap = 0;
+ GLXFBConfig *fb_configs = nullptr;
+ GLXContext gl_context = 0;
+ GLXPbuffer glx_pbuffer = 0;
#endif
+
+ GLuint fbo = 0;
+ GLuint fbo_depth_stencil = 0;
+ GLuint fbo_color = 0;
};
}
diff --git a/include/mbgl/renderer/frame_history.hpp b/include/mbgl/renderer/frame_history.hpp
index b1f0bcb597..61bb59da33 100644
--- a/include/mbgl/renderer/frame_history.hpp
+++ b/include/mbgl/renderer/frame_history.hpp
@@ -11,7 +11,7 @@
namespace mbgl {
struct FrameSnapshot {
- explicit inline FrameSnapshot(timestamp t, float z) : t(t), z(z) {}
+ explicit inline FrameSnapshot(timestamp t_, float z_) : t(t_), z(z_) {}
float t;
float z;
};
diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp
index 13c2050bd0..a8229a0978 100644
--- a/include/mbgl/renderer/painter.hpp
+++ b/include/mbgl/renderer/painter.hpp
@@ -64,6 +64,7 @@ public:
// lazy initialization) in case rendering continues.
void cleanup();
+ void terminate();
// Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any
// tiles whatsoever.
@@ -124,6 +125,7 @@ public:
private:
void setupShaders();
+ void deleteShaders();
mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor);
void prepareTile(const Tile& tile);
@@ -152,10 +154,10 @@ public:
// used to composite images and flips the geometry upside down
const mat4 flipMatrix = []{
- mat4 flipMatrix;
- matrix::ortho(flipMatrix, 0, 4096, -4096, 0, 0, 1);
- matrix::translate(flipMatrix, flipMatrix, 0, -4096, 0);
- return flipMatrix;
+ mat4 flip;
+ matrix::ortho(flip, 0, 4096, -4096, 0, 0, 1);
+ matrix::translate(flip, flip, 0, -4096, 0);
+ return flip;
}();
const mat4 identityMatrix = []{
diff --git a/include/mbgl/style/class_dictionary.hpp b/include/mbgl/style/class_dictionary.hpp
index c7f9c6a284..ecf80be3e3 100644
--- a/include/mbgl/style/class_dictionary.hpp
+++ b/include/mbgl/style/class_dictionary.hpp
@@ -14,17 +14,22 @@ enum class ClassID : uint32_t {
};
class ClassDictionary {
+private:
+ ClassDictionary();
+
public:
+ static ClassDictionary &Get();
+
// Returns an ID for a class name. If the class name does not yet have an ID, one is
// auto-generated and stored for future reference.
- static ClassID Lookup(const std::string &class_name);
+ ClassID lookup(const std::string &class_name);
// Returns either Fallback, Default or Named, depending on the type of the class id.
- static ClassID Normalize(ClassID id);
+ ClassID normalize(ClassID id);
private:
- static std::unordered_map<std::string, ClassID> store;
- static uint32_t offset;
+ std::unordered_map<std::string, ClassID> store = { { "", ClassID::Default } };
+ uint32_t offset = 0;
};
}
diff --git a/include/mbgl/style/class_properties.hpp b/include/mbgl/style/class_properties.hpp
index 84b6f483bd..888a90c5d7 100644
--- a/include/mbgl/style/class_properties.hpp
+++ b/include/mbgl/style/class_properties.hpp
@@ -12,8 +12,8 @@ namespace mbgl {
class ClassProperties {
public:
inline ClassProperties() {}
- inline ClassProperties(ClassProperties &&properties)
- : properties(std::move(properties.properties)) {}
+ inline ClassProperties(ClassProperties &&properties_)
+ : properties(std::move(properties_.properties)) {}
inline void set(PropertyKey key, const PropertyValue &value) {
properties.emplace(key, value);
diff --git a/include/mbgl/style/filter_comparison.hpp b/include/mbgl/style/filter_comparison.hpp
index bf48744f1e..1b0a9b5486 100644
--- a/include/mbgl/style/filter_comparison.hpp
+++ b/include/mbgl/style/filter_comparison.hpp
@@ -24,8 +24,8 @@ public:
class Instance {
public:
- Instance(Operator op, std::vector<Value> &&values)
- : op(op), values(values) {}
+ Instance(Operator op_, std::vector<Value> &&values_)
+ : op(op_), values(values_) {}
bool compare(const std::vector<Value> &property_values) const;
@@ -37,7 +37,7 @@ public:
};
public:
- FilterComparison(const std::string &field) : field(field) {};
+ FilterComparison(const std::string &field_) : field(field_) {};
const std::string &getField() const;
template <typename Extractor> inline bool compare(const Extractor &extractor) const;
diff --git a/include/mbgl/style/filter_expression.hpp b/include/mbgl/style/filter_expression.hpp
index 2a96578792..915d3931d1 100644
--- a/include/mbgl/style/filter_expression.hpp
+++ b/include/mbgl/style/filter_expression.hpp
@@ -28,7 +28,7 @@ public:
public:
FilterExpression() = default;
- FilterExpression(Operator op) : op(op) {};
+ FilterExpression(Operator op_) : op(op_) {};
bool empty() const;
diff --git a/include/mbgl/style/function_properties.hpp b/include/mbgl/style/function_properties.hpp
index 56092f9a63..924f192330 100644
--- a/include/mbgl/style/function_properties.hpp
+++ b/include/mbgl/style/function_properties.hpp
@@ -9,7 +9,7 @@ namespace mbgl {
template <typename T>
struct ConstantFunction {
- inline ConstantFunction(const T &value) : value(value) {}
+ inline ConstantFunction(const T &value_) : value(value_) {}
inline T evaluate(float) const { return value; }
private:
@@ -18,7 +18,7 @@ private:
template <typename T>
struct StopsFunction {
- inline StopsFunction(const std::vector<std::pair<float, T>> &values, float base) : values(values), base(base) {}
+ inline StopsFunction(const std::vector<std::pair<float, T>> &values_, float base_) : values(values_), base(base_) {}
T evaluate(float z) const;
private:
@@ -36,7 +36,7 @@ using Function = mapbox::util::variant<
template <typename T>
struct FunctionEvaluator {
typedef T result_type;
- inline FunctionEvaluator(float z) : z(z) {}
+ inline FunctionEvaluator(float z_) : z(z_) {}
inline result_type operator()(const std::false_type &) {
return result_type();
diff --git a/include/mbgl/style/style_source.hpp b/include/mbgl/style/style_source.hpp
index 00c48431a1..86473079cf 100644
--- a/include/mbgl/style/style_source.hpp
+++ b/include/mbgl/style/style_source.hpp
@@ -36,8 +36,8 @@ public:
bool enabled = false;
util::ptr<Source> source;
- StyleSource(const util::ptr<SourceInfo> &info)
- : info(info)
+ StyleSource(const util::ptr<SourceInfo> &info_)
+ : info(info_)
{}
};
diff --git a/include/mbgl/text/collision.hpp b/include/mbgl/text/collision.hpp
index b7ee6b4520..dfefab689e 100644
--- a/include/mbgl/text/collision.hpp
+++ b/include/mbgl/text/collision.hpp
@@ -6,6 +6,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
+#pragma GCC diagnostic ignored "-Wshadow"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wdeprecated-register"
#else
diff --git a/include/mbgl/text/glyph.hpp b/include/mbgl/text/glyph.hpp
index de7f55bdc6..4fbb75fc1e 100644
--- a/include/mbgl/text/glyph.hpp
+++ b/include/mbgl/text/glyph.hpp
@@ -30,9 +30,9 @@ struct GlyphMetrics {
struct Glyph {
inline explicit Glyph() : rect(0, 0, 0, 0), metrics() {}
- inline explicit Glyph(const Rect<uint16_t> &rect,
- const GlyphMetrics &metrics)
- : rect(rect), metrics(metrics) {}
+ inline explicit Glyph(const Rect<uint16_t> &rect_,
+ const GlyphMetrics &metrics_)
+ : rect(rect_), metrics(metrics_) {}
operator bool() const {
return metrics || rect;
@@ -46,8 +46,8 @@ typedef std::map<uint32_t, Glyph> GlyphPositions;
class PositionedGlyph {
public:
- inline explicit PositionedGlyph(uint32_t glyph, float x, float y)
- : glyph(glyph), x(x), y(y) {}
+ inline explicit PositionedGlyph(uint32_t glyph_, float x_, float y_)
+ : glyph(glyph_), x(x_), y(y_) {}
uint32_t glyph = 0;
float x = 0;
diff --git a/include/mbgl/text/types.hpp b/include/mbgl/text/types.hpp
index dbb483ea8f..23f49aa748 100644
--- a/include/mbgl/text/types.hpp
+++ b/include/mbgl/text/types.hpp
@@ -3,11 +3,10 @@
#include <mbgl/util/vec.hpp>
#include <mbgl/util/rect.hpp>
+#include <mbgl/util/optional.hpp>
#include <array>
#include <vector>
-#include <boost/optional.hpp>
-
namespace mbgl {
typedef vec2<float> CollisionPoint;
@@ -29,31 +28,31 @@ struct CollisionRect {
CollisionPoint::Type bx,
CollisionPoint::Type by)
: tl(ax, ay), br(bx, by) {}
- inline explicit CollisionRect(const CollisionPoint &tl,
- const CollisionPoint &br)
- : tl(tl), br(br) {}
+ inline explicit CollisionRect(const CollisionPoint &tl_,
+ const CollisionPoint &br_)
+ : tl(tl_), br(br_) {}
};
// These are the glyph boxes that we want to have placed.
struct GlyphBox {
explicit GlyphBox() {}
- explicit GlyphBox(const CollisionRect &box,
- const CollisionAnchor &anchor,
- float minScale,
- float maxScale,
- float padding)
- : box(box), anchor(anchor), minScale(minScale), maxScale(maxScale), padding(padding) {}
- explicit GlyphBox(const CollisionRect &box,
- float minScale,
- float padding)
- : box(box), minScale(minScale), padding(padding) {}
+ explicit GlyphBox(const CollisionRect &box_,
+ const CollisionAnchor &anchor_,
+ float minScale_,
+ float maxScale_,
+ float padding_)
+ : box(box_), anchor(anchor_), minScale(minScale_), maxScale(maxScale_), padding(padding_) {}
+ explicit GlyphBox(const CollisionRect &box_,
+ float minScale_,
+ float padding_)
+ : box(box_), minScale(minScale_), padding(padding_) {}
CollisionRect box;
CollisionAnchor anchor;
float minScale = 0.0f;
float maxScale = std::numeric_limits<float>::infinity();
float padding = 0.0f;
- boost::optional<CollisionRect> hBox;
+ mapbox::util::optional<CollisionRect> hBox;
};
typedef std::vector<GlyphBox> GlyphBoxes;
@@ -61,19 +60,19 @@ typedef std::vector<GlyphBox> GlyphBoxes;
// TODO: Transform the vec2<float>s to vec2<int16_t> to save bytes
struct PlacedGlyph {
- explicit PlacedGlyph(const vec2<float> &tl, const vec2<float> &tr,
- const vec2<float> &bl, const vec2<float> &br,
- const Rect<uint16_t> &tex, float angle, const vec2<float> &anchor,
- float minScale, float maxScale)
- : tl(tl),
- tr(tr),
- bl(bl),
- br(br),
- tex(tex),
- angle(angle),
- anchor(anchor),
- minScale(minScale),
- maxScale(maxScale) {}
+ explicit PlacedGlyph(const vec2<float> &tl_, const vec2<float> &tr_,
+ const vec2<float> &bl_, const vec2<float> &br_,
+ const Rect<uint16_t> &tex_, float angle_, const vec2<float> &anchor_,
+ float minScale_, float maxScale_)
+ : tl(tl_),
+ tr(tr_),
+ bl(bl_),
+ br(br_),
+ tex(tex_),
+ angle(angle_),
+ anchor(anchor_),
+ minScale(minScale_),
+ maxScale(maxScale_) {}
vec2<float> tl, tr, bl, br;
Rect<uint16_t> tex;
@@ -88,7 +87,7 @@ typedef std::vector<PlacedGlyph> PlacedGlyphs;
struct PlacementBox {
CollisionAnchor anchor;
CollisionRect box;
- boost::optional<CollisionRect> hBox;
+ mapbox::util::optional<CollisionRect> hBox;
PlacementRange placementRange = {{0.0f, 0.0f}};
float placementScale = 0.0f;
float maxScale = std::numeric_limits<float>::infinity();
@@ -97,8 +96,8 @@ struct PlacementBox {
struct PlacementProperty {
explicit PlacementProperty() {}
- explicit PlacementProperty(float zoom, const PlacementRange &rotationRange)
- : zoom(zoom), rotationRange(rotationRange) {}
+ explicit PlacementProperty(float zoom_, const PlacementRange &rotationRange_)
+ : zoom(zoom_), rotationRange(rotationRange_) {}
inline operator bool() const {
return !std::isnan(zoom) && zoom != std::numeric_limits<float>::infinity() &&
diff --git a/include/mbgl/util/enum.hpp b/include/mbgl/util/enum.hpp
index 195aaab5a5..3c3e4a5c4e 100644
--- a/include/mbgl/util/enum.hpp
+++ b/include/mbgl/util/enum.hpp
@@ -21,11 +21,11 @@ private:
static constexpr inline bool compare(const char *a, const char *b) {
return *a == *b && (*a == '\0' || compare(a + 1, b + 1));
}
- static constexpr inline const char *lookup_type(Type e, EnumValue<Type> const * const l, size_t r) {
- return r == 0 ? "" : l->value == e ? l->name : lookup_type(e, l + 1, r - 1);
+ static constexpr inline const char *lookup_type(Type e, EnumValue<Type> const * const list, size_t r) {
+ return r == 0 ? "" : list->value == e ? list->name : lookup_type(e, list + 1, r - 1);
}
- static constexpr inline Type lookup_name(const char *n, EnumValue<Type> const * const l, size_t r) {
- return r == 0 ? Type(-1) : compare(l->name, n) ? l->value : lookup_name(n, l + 1, r - 1);
+ static constexpr inline Type lookup_name(const char *n, EnumValue<Type> const * const list, size_t r) {
+ return r == 0 ? Type(-1) : compare(list->name, n) ? list->value : lookup_name(n, list + 1, r - 1);
}
public:
inline constexpr Enum(const char *n) : value(lookup_name(n, names, length)) {}
diff --git a/include/mbgl/util/error.hpp b/include/mbgl/util/error.hpp
index 99e27f770c..09fa8d3e21 100644
--- a/include/mbgl/util/error.hpp
+++ b/include/mbgl/util/error.hpp
@@ -8,7 +8,7 @@ namespace mbgl {
namespace error {
struct style_parse : std::exception {
- inline style_parse(size_t offset, const char *msg) : offset(offset), msg(msg) {}
+ inline style_parse(size_t offset_, const char *msg_) : offset(offset_), msg(msg_) {}
inline const char* what() const noexcept { return msg.c_str(); }
const size_t offset;
const std::string msg;
diff --git a/include/mbgl/util/optional.hpp b/include/mbgl/util/optional.hpp
new file mode 100644
index 0000000000..133e2c8f97
--- /dev/null
+++ b/include/mbgl/util/optional.hpp
@@ -0,0 +1,69 @@
+#ifndef MAPBOX_UTIL_OPTIONAL_HPP
+#define MAPBOX_UTIL_OPTIONAL_HPP
+
+#include <type_traits>
+
+#include "variant.hpp"
+
+namespace mapbox
+{
+namespace util
+{
+
+template <typename T> class optional
+{
+ static_assert(!std::is_reference<T>::value, "optional doesn't support references");
+
+ struct none_type
+ {
+ };
+
+ variant<none_type, T> variant_;
+
+ public:
+ optional() = default;
+
+ optional(optional const &rhs)
+ {
+ if (this != &rhs)
+ { // protect against invalid self-assignment
+ variant_ = rhs.variant_;
+ }
+ }
+
+ optional(T const &v) { variant_ = v; }
+
+ explicit operator bool() const noexcept { return variant_.template is<T>(); }
+
+ T const &get() const { return variant_.template get<T>(); }
+ T &get() { return variant_.template get<T>(); }
+
+ T const &operator*() const { return this->get(); }
+ T operator*() { return this->get(); }
+
+ optional &operator=(T const &v)
+ {
+ variant_ = v;
+ return *this;
+ }
+
+ optional &operator=(optional const &rhs)
+ {
+ if (this != &rhs)
+ {
+ variant_ = rhs.variant_;
+ }
+ return *this;
+ }
+
+ template <typename... Args> void emplace(Args &&... args)
+ {
+ variant_ = T{std::forward<Args>(args)...};
+ }
+
+ void reset() { variant_ = none_type{}; }
+};
+}
+}
+
+#endif
diff --git a/include/mbgl/util/pbf.hpp b/include/mbgl/util/pbf.hpp
index 1f78a0072f..d017219a52 100644
--- a/include/mbgl/util/pbf.hpp
+++ b/include/mbgl/util/pbf.hpp
@@ -49,9 +49,9 @@ struct pbf {
uint32_t tag = 0;
};
-pbf::pbf(const unsigned char *data, size_t length)
- : data(data),
- end(data + length),
+pbf::pbf(const unsigned char *data_, size_t length)
+ : data(data_),
+ end(data_ + length),
value(0),
tag(0) {
}
@@ -132,9 +132,9 @@ double pbf::float64() {
std::string pbf::string() {
uint32_t bytes = static_cast<uint32_t>(varint());
- const char *string = reinterpret_cast<const char*>(data);
+ const char *string_data = reinterpret_cast<const char*>(data);
skipBytes(bytes);
- return std::string(string, bytes);
+ return std::string(string_data, bytes);
}
bool pbf::boolean() {
diff --git a/include/mbgl/util/rect.hpp b/include/mbgl/util/rect.hpp
index dedd4afc94..f5c77f93d1 100644
--- a/include/mbgl/util/rect.hpp
+++ b/include/mbgl/util/rect.hpp
@@ -6,7 +6,7 @@ namespace mbgl {
template <typename T>
struct Rect {
inline Rect() {}
- inline Rect(T x, T y, T w, T h) : x(x), y(y), w(w), h(h) {}
+ inline Rect(T x_, T y_, T w_, T h_) : x(x_), y(y_), w(w_), h(h_) {}
T x = 0, y = 0;
T w = 0, h = 0;
diff --git a/include/mbgl/util/transition.hpp b/include/mbgl/util/transition.hpp
index 8a6836c885..b78abfa8fd 100644
--- a/include/mbgl/util/transition.hpp
+++ b/include/mbgl/util/transition.hpp
@@ -15,9 +15,9 @@ public:
complete
};
- inline transition(timestamp start, timestamp duration)
- : start(start),
- duration(duration) {}
+ inline transition(timestamp start_, timestamp duration_)
+ : start(start_),
+ duration(duration_) {}
inline float progress(timestamp now) const {
if (duration == 0) return 1;
@@ -36,11 +36,11 @@ protected:
template <typename T>
class ease_transition : public transition {
public:
- ease_transition(T from, T to, T& value, timestamp start, timestamp duration)
- : transition(start, duration),
- from(from),
- to(to),
- value(value) {}
+ ease_transition(T from_, T to_, T& value_, timestamp start_, timestamp duration_)
+ : transition(start_, duration_),
+ from(from_),
+ to(to_),
+ value(value_) {}
state update(timestamp now) const;
@@ -53,10 +53,10 @@ private:
template <typename T>
class timeout : public transition {
public:
- timeout(T final_value, T& value, timestamp start, timestamp duration)
- : transition(start, duration),
- final_value(final_value),
- value(value) {}
+ timeout(T final_value_, T& value_, timestamp start_, timestamp duration_)
+ : transition(start_, duration_),
+ final_value(final_value_),
+ value(value_) {}
state update(timestamp now) const {
if (progress(now) >= 1) {
diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp
index f80ca1bff5..b4b41f31af 100644
--- a/include/mbgl/util/uv_detail.hpp
+++ b/include/mbgl/util/uv_detail.hpp
@@ -68,7 +68,7 @@ private:
class lock {
public:
- lock(mutex &mtx) : mtx(mtx) { mtx.lock(); }
+ lock(mutex &mtx_) : mtx(mtx_) { mtx.lock(); }
~lock() { mtx.unlock(); }
private:
@@ -94,8 +94,8 @@ private:
class readlock {
public:
- inline readlock(rwlock &mtx) : mtx(mtx) { mtx.rdlock(); }
- inline readlock(const std::unique_ptr<rwlock> &mtx) : mtx(*mtx) { mtx->rdlock(); }
+ inline readlock(rwlock &mtx_) : mtx(mtx_) { mtx.rdlock(); }
+ inline readlock(const std::unique_ptr<rwlock> &mtx_) : mtx(*mtx_) { mtx.rdlock(); }
inline ~readlock() { mtx.rdunlock(); }
private:
@@ -104,8 +104,8 @@ private:
class writelock {
public:
- inline writelock(rwlock &mtx) : mtx(mtx) { mtx.wrlock(); }
- inline writelock(const std::unique_ptr<rwlock> &mtx) : mtx(*mtx) { mtx->wrlock(); }
+ inline writelock(rwlock &mtx_) : mtx(mtx_) { mtx.wrlock(); }
+ inline writelock(const std::unique_ptr<rwlock> &mtx_) : mtx(*mtx_) { mtx.wrlock(); }
inline ~writelock() { mtx.wrunlock(); }
private:
@@ -148,10 +148,10 @@ public:
typedef void (*after_work_callback)(T &object);
template<typename... Args>
- work(worker &worker, work_callback work_cb, after_work_callback after_work_cb, Args&&... args)
+ work(worker &worker, work_callback work_cb_, after_work_callback after_work_cb_, Args&&... args)
: data(std::forward<Args>(args)...),
- work_cb(work_cb),
- after_work_cb(after_work_cb) {
+ work_cb(work_cb_),
+ after_work_cb(after_work_cb_) {
worker.add(this, do_work, after_work);
}
diff --git a/include/mbgl/util/variant.hpp b/include/mbgl/util/variant.hpp
index 1eca5160c7..3b5659425a 100644
--- a/include/mbgl/util/variant.hpp
+++ b/include/mbgl/util/variant.hpp
@@ -4,7 +4,6 @@
#include <utility>
#include <typeinfo>
#include <type_traits>
-#include <algorithm> // std::move/swap
#include <stdexcept> // runtime_error
#include <new> // operator new
#include <cstddef> // size_t
@@ -515,22 +514,13 @@ public:
VARIANT_INLINE variant(no_init)
: type_index(detail::invalid_value) {}
+ // http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
template <typename T, class = typename std::enable_if<
- detail::is_valid_type<T, Types...>::value>::type>
- VARIANT_INLINE explicit variant(T const& val) noexcept
- : type_index(detail::value_traits<T, Types...>::index)
- {
- constexpr std::size_t index = sizeof...(Types) - detail::value_traits<T, Types...>::index - 1;
- using target_type = typename detail::select_type<index, Types...>::type;
- new (&data) target_type(val);
- }
-
- template <typename T, class = typename std::enable_if<
- detail::is_valid_type<T, Types...>::value>::type>
+ detail::is_valid_type<typename std::remove_reference<T>::type, Types...>::value>::type>
VARIANT_INLINE variant(T && val) noexcept
- : type_index(detail::value_traits<T, Types...>::index)
+ : type_index(detail::value_traits<typename std::remove_reference<T>::type, Types...>::index)
{
- constexpr std::size_t index = sizeof...(Types) - detail::value_traits<T, Types...>::index - 1;
+ constexpr std::size_t index = sizeof...(Types) - detail::value_traits<typename std::remove_reference<T>::type, Types...>::index - 1;
using target_type = typename detail::select_type<index, Types...>::type;
new (&data) target_type(std::forward<T>(val)); // nothrow
}
@@ -565,7 +555,7 @@ public:
template <typename T>
VARIANT_INLINE variant<Types...>& operator=(T && rhs) noexcept
{
- variant<Types...> temp(std::move(rhs));
+ variant<Types...> temp(std::forward<T>(rhs));
swap(*this, temp);
return *this;
}
diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp
index a5fbee477b..0179254fda 100644
--- a/include/mbgl/util/vec.hpp
+++ b/include/mbgl/util/vec.hpp
@@ -29,7 +29,7 @@ struct vec2 {
template<typename U>
inline vec2(const U& u) : x(u.x), y(u.y) {}
- inline vec2(T x, T y) : x(x), y(y) {}
+ inline vec2(T x_, T y_) : x(x_), y(y_) {}
inline bool operator==(const vec2& rhs) const {
return x == rhs.x && y == rhs.y;
@@ -86,7 +86,7 @@ struct vec3 {
inline vec3() {}
inline vec3(const vec3& o) : x(o.x), y(o.y), z(o.z) {}
- inline vec3(T x, T y, T z) : x(x), y(y), z(z) {}
+ inline vec3(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}
inline bool operator==(const vec3& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z;
}
@@ -98,7 +98,7 @@ struct vec4 {
inline vec4() {}
inline vec4(const vec4& o) : x(o.x), y(o.y), z(o.z), w(o.w) {}
- inline vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
+ inline vec4(T x_, T y_, T z_, T w_) : x(x_), y(y_), z(z_), w(w_) {}
inline bool operator==(const vec4& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
}