diff options
Diffstat (limited to 'include/mbgl/util')
24 files changed, 0 insertions, 1303 deletions
diff --git a/include/mbgl/util/clip_ids.hpp b/include/mbgl/util/clip_ids.hpp deleted file mode 100644 index 5855b16af7..0000000000 --- a/include/mbgl/util/clip_ids.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef MBGL_UTIL_CLIP_IDS -#define MBGL_UTIL_CLIP_IDS - -#include <mbgl/map/tile.hpp> -#include <list> -#include <set> -#include <vector> -#include <forward_list> -#include <map> - -namespace mbgl { - -class ClipIDGenerator { -private: - struct Leaf { - Leaf(Tile &tile); - void add(const Tile::ID &p); - bool operator==(const Leaf &other) const; - - Tile &tile; - std::forward_list<Tile::ID> children; - }; - - typedef std::vector<Leaf> Pool; - std::forward_list<Pool> pools; - uint8_t bit_offset = 0; - -private: - bool reuseExisting(Leaf &leaf); - -public: - void update(std::forward_list<Tile *> tiles); -}; - - -} - -#endif diff --git a/include/mbgl/util/compression.hpp b/include/mbgl/util/compression.hpp deleted file mode 100644 index a33b2476a7..0000000000 --- a/include/mbgl/util/compression.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MBGL_UTIL_COMPRESSION -#define MBGL_UTIL_COMPRESSION - -#include <string> - -namespace mbgl { -namespace util { - -std::string compress(const std::string &raw); -std::string decompress(const std::string &raw); - -} -} - -#endif diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp deleted file mode 100644 index 89e8af2ef1..0000000000 --- a/include/mbgl/util/constants.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MBGL_UTIL_CONSTANTS -#define MBGL_UTIL_CONSTANTS - -#include <cmath> - -#include "vec.hpp" - -namespace mbgl { - -namespace util { - -extern const float tileSize; - -} - -namespace debug { - -extern const bool tileParseWarnings; -extern const bool styleParseWarnings; -extern const bool spriteWarnings; -extern const bool renderWarnings; -extern const bool renderTree; -extern const bool labelTextMissingWarning; -extern const bool missingFontStackWarning; -extern const bool missingFontFaceWarning; -extern const bool glyphWarning; -extern const bool shapingWarning; - -} - -} - -#endif diff --git a/include/mbgl/util/error.hpp b/include/mbgl/util/error.hpp deleted file mode 100644 index 09fa8d3e21..0000000000 --- a/include/mbgl/util/error.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MBGL_UTIL_ERROR -#define MBGL_UTIL_ERROR - -#include <stdexcept> -#include <string> - -namespace mbgl { -namespace error { - -struct style_parse : std::exception { - 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; -}; -} - -} - -#endif
\ No newline at end of file diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp deleted file mode 100644 index c9232db4eb..0000000000 --- a/include/mbgl/util/interpolate.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MBGL_UTIL_INTERPOLATE -#define MBGL_UTIL_INTERPOLATE - -#include <array> - -namespace mbgl { -namespace util { - -template <typename T> -T interpolate(const T a, const T b, const double t) { - return a * (1.0 - t) + b * t; -} - -template <typename T> -inline std::array<T, 4> interpolate(const std::array<T, 4>& a, const std::array<T, 4>& b, const double t) { - return {{ - interpolate(a[0], b[0], t), - interpolate(a[1], b[1], t), - interpolate(a[2], b[2], t), - interpolate(a[3], b[3], t) - }}; -} - -} -} - -#endif diff --git a/include/mbgl/util/io.hpp b/include/mbgl/util/io.hpp deleted file mode 100644 index e95fc16d9d..0000000000 --- a/include/mbgl/util/io.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MBGL_UTIL_IO -#define MBGL_UTIL_IO - -#include <string> - -namespace mbgl { -namespace util { - -void write_file(const std::string &filename, const std::string &data); -std::string read_file(const std::string &filename); - -} -} - -#endif diff --git a/include/mbgl/util/mapbox.hpp b/include/mbgl/util/mapbox.hpp deleted file mode 100644 index 0fbb9a91ed..0000000000 --- a/include/mbgl/util/mapbox.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef MBGL_UTIL_MAPBOX -#define MBGL_UTIL_MAPBOX - -#include <string> - -namespace mbgl { -namespace util { -namespace mapbox { - -std::string normalizeSourceURL(const std::string& url, const std::string& accessToken); -std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken); - -} -} -} - -#endif diff --git a/include/mbgl/util/mat3.hpp b/include/mbgl/util/mat3.hpp deleted file mode 100644 index fa40751764..0000000000 --- a/include/mbgl/util/mat3.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// This is an incomplete port of http://glmatrix.net/ -// -// Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the -// use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim -// that you wrote the original software. If you use this software in a -// product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. - -#ifndef MBGL_UTIL_MAT3 -#define MBGL_UTIL_MAT3 - -#include <array> - -namespace mbgl { - -typedef std::array<float, 9> mat3; - -namespace matrix { - -void identity(mat3& out); -void translate(mat3& out, const mat3& a, float x, float y); -void rotate(mat3& out, const mat3& a, float rad); -void scale(mat3& out, const mat3& a, float x, float y); - -} -} - -#endif diff --git a/include/mbgl/util/optional.hpp b/include/mbgl/util/optional.hpp deleted file mode 100644 index 133e2c8f97..0000000000 --- a/include/mbgl/util/optional.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#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 deleted file mode 100644 index d017219a52..0000000000 --- a/include/mbgl/util/pbf.hpp +++ /dev/null @@ -1,184 +0,0 @@ -#ifndef MBGL_UTIL_PBF -#define MBGL_UTIL_PBF - -/* - * Some parts are from upb - a minimalist implementation of protocol buffers. - * - * Copyright (c) 2008-2011 Google Inc. See LICENSE for details. - * Author: Josh Haberman <jhaberman@gmail.com> - */ - -#include <string> -#include <cstring> - -namespace mbgl { - -struct pbf { - struct exception : std::exception { const char *what() const noexcept { return "pbf exception"; } }; - struct unterminated_varint_exception : exception { const char *what() const noexcept { return "pbf unterminated varint exception"; } }; - struct varint_too_long_exception : exception { const char *what() const noexcept { return "pbf varint too long exception"; } }; - struct unknown_field_type_exception : exception { const char *what() const noexcept { return "pbf unknown field type exception"; } }; - struct end_of_buffer_exception : exception { const char *what() const noexcept { return "pbf end of buffer exception"; } }; - - inline pbf(const unsigned char *data, size_t length); - inline pbf(); - - inline operator bool() const; - - inline bool next(); - inline bool next(uint32_t tag); - template <typename T = uint32_t> inline T varint(); - template <typename T = uint32_t> inline T svarint(); - - template <typename T = uint32_t, int bytes = 4> inline T fixed(); - inline float float32(); - inline double float64(); - - inline std::string string(); - inline bool boolean(); - - inline pbf message(); - - inline void skip(); - inline void skipValue(uint32_t val); - inline void skipBytes(uint32_t bytes); - - const uint8_t *data = nullptr; - const uint8_t *end = nullptr; - uint32_t value = 0; - uint32_t tag = 0; -}; - -pbf::pbf(const unsigned char *data_, size_t length) - : data(data_), - end(data_ + length), - value(0), - tag(0) { -} - -pbf::pbf() - : data(nullptr), - end(nullptr), - value(0), - tag(0) { -} - - -pbf::operator bool() const { - return data < end; -} - -bool pbf::next() { - if (data < end) { - value = static_cast<uint32_t>(varint()); - tag = value >> 3; - return true; - } - return false; -} - -bool pbf::next(uint32_t requested_tag) { - while (next()) { - if (tag == requested_tag) { - return true; - } else { - skip(); - } - } - return false; -} - -template <typename T> -T pbf::varint() { - uint8_t byte = 0x80; - T result = 0; - int bitpos; - for (bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { - if (data >= end) { - throw unterminated_varint_exception(); - } - result |= ((T)(byte = *data) & 0x7F) << bitpos; - - data++; - } - if (bitpos == 70 && (byte & 0x80)) { - throw varint_too_long_exception(); - } - - return result; -} - -template <typename T> -T pbf::svarint() { - T n = varint<T>(); - return (n >> 1) ^ -(T)(n & 1); -} - -template <typename T, int bytes> -T pbf::fixed() { - skipBytes(bytes); - T result; - memcpy(&result, data - bytes, bytes); - return result; -} - -float pbf::float32() { - return fixed<float, 4>(); -} - -double pbf::float64() { - return fixed<double, 8>(); -} - -std::string pbf::string() { - uint32_t bytes = static_cast<uint32_t>(varint()); - const char *string_data = reinterpret_cast<const char*>(data); - skipBytes(bytes); - return std::string(string_data, bytes); -} - -bool pbf::boolean() { - skipBytes(1); - return *(bool *)(data - 1); -} - -pbf pbf::message() { - uint32_t bytes = static_cast<uint32_t>(varint()); - const uint8_t *pos = data; - skipBytes(bytes); - return pbf(pos, bytes); -} - -void pbf::skip() { - skipValue(value); -} - -void pbf::skipValue(uint32_t val) { - switch (val & 0x7) { - case 0: // varint - varint(); - break; - case 1: // 64 bit - skipBytes(8); - break; - case 2: // string/message - skipBytes(static_cast<uint32_t>(varint())); - break; - case 5: // 32 bit - skipBytes(4); - break; - default: - throw unknown_field_type_exception(); - } -} - -void pbf::skipBytes(uint32_t bytes) { - if (data + bytes > end) { - throw end_of_buffer_exception(); - } - data += bytes; -} - -} // end namespace mbgl - -#endif diff --git a/include/mbgl/util/queue.h b/include/mbgl/util/queue.h deleted file mode 100644 index fe02b454ea..0000000000 --- a/include/mbgl/util/queue.h +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef QUEUE_H_ -#define QUEUE_H_ - -typedef void *QUEUE[2]; - -/* Private macros. */ -#define QUEUE_NEXT(q) (*(QUEUE **) &((*(q))[0])) -#define QUEUE_PREV(q) (*(QUEUE **) &((*(q))[1])) -#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT(QUEUE_PREV(q))) -#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q))) - -/* Public macros. */ -#define QUEUE_DATA(ptr, type, field) \ - ((type *) ((char *) (ptr) - ((char *) &((type *) 0)->field))) - -#define QUEUE_FOREACH(q, h) \ - for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q)) - -#define QUEUE_EMPTY(q) \ - ((const QUEUE *) (q) == (const QUEUE *) QUEUE_NEXT(q)) - -#define QUEUE_HEAD(q) \ - (QUEUE_NEXT(q)) - -#define QUEUE_INIT(q) \ - do { \ - QUEUE_NEXT(q) = (q); \ - QUEUE_PREV(q) = (q); \ - } \ - while (0) - -#define QUEUE_ADD(h, n) \ - do { \ - QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n); \ - QUEUE_NEXT_PREV(n) = QUEUE_PREV(h); \ - QUEUE_PREV(h) = QUEUE_PREV(n); \ - QUEUE_PREV_NEXT(h) = (h); \ - } \ - while (0) - -#define QUEUE_SPLIT(h, q, n) \ - do { \ - QUEUE_PREV(n) = QUEUE_PREV(h); \ - QUEUE_PREV_NEXT(n) = (n); \ - QUEUE_NEXT(n) = (q); \ - QUEUE_PREV(h) = QUEUE_PREV(q); \ - QUEUE_PREV_NEXT(h) = (h); \ - QUEUE_PREV(q) = (n); \ - } \ - while (0) - -#define QUEUE_INSERT_HEAD(h, q) \ - do { \ - QUEUE_NEXT(q) = QUEUE_NEXT(h); \ - QUEUE_PREV(q) = (h); \ - QUEUE_NEXT_PREV(q) = (q); \ - QUEUE_NEXT(h) = (q); \ - } \ - while (0) - -#define QUEUE_INSERT_TAIL(h, q) \ - do { \ - QUEUE_NEXT(q) = (h); \ - QUEUE_PREV(q) = QUEUE_PREV(h); \ - QUEUE_PREV_NEXT(q) = (q); \ - QUEUE_PREV(h) = (q); \ - } \ - while (0) - -#define QUEUE_REMOVE(q) \ - do { \ - QUEUE_PREV_NEXT(q) = QUEUE_NEXT(q); \ - QUEUE_NEXT_PREV(q) = QUEUE_PREV(q); \ - } \ - while (0) - -#endif /* QUEUE_H_ */ diff --git a/include/mbgl/util/raster.hpp b/include/mbgl/util/raster.hpp deleted file mode 100644 index ff27f509f4..0000000000 --- a/include/mbgl/util/raster.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef MBGL_UTIL_RASTER -#define MBGL_UTIL_RASTER - -#include <mbgl/util/transition.hpp> -#include <mbgl/util/texture_pool.hpp> -#include <mbgl/util/image.hpp> -#include <mbgl/util/ptr.hpp> -#include <mbgl/renderer/prerendered_texture.hpp> - -#include <string> -#include <mutex> - -typedef struct uv_loop_s uv_loop_t; - -namespace mbgl { - -class Raster : public std::enable_shared_from_this<Raster> { - -public: - Raster(TexturePool&); - ~Raster(); - - // load image data - bool load(const std::string &img); - - // bind current texture - void bind(bool linear = false); - - // bind prerendered texture - void bind(const GLuint texture); - - // loaded status - bool isLoaded() const; - - // transitions - void beginFadeInTransition(); - bool needsTransition() const; - void updateTransitions(timestamp now); - -public: - // loaded image dimensions - uint32_t width = 0, height = 0; - - // has been uploaded to texture - bool textured = false; - - // the uploaded texture - uint32_t texture = 0; - - // texture opacity - double opacity = 0; - -private: - mutable std::mutex mtx; - - // raw pixels have been loaded - bool loaded = false; - - // shared texture pool - TexturePool& texturePool; - - // min/mag filter - uint32_t filter = 0; - - // the raw pixels - std::unique_ptr<util::Image> img; - - // fade in transition - util::ptr<util::transition> fade_transition = nullptr; -}; - -} - -#endif diff --git a/include/mbgl/util/rect.hpp b/include/mbgl/util/rect.hpp deleted file mode 100644 index f5c77f93d1..0000000000 --- a/include/mbgl/util/rect.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MBGL_UTIL_RECT -#define MBGL_UTIL_RECT - -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_) {} - T x = 0, y = 0; - T w = 0, h = 0; - - template <typename Number> - Rect operator *(Number value) const { - return Rect(x * value, y * value, w * value, h * value); - } - - operator bool() const { return w != 0 && h != 0; } -}; -} - -#endif diff --git a/include/mbgl/util/sqlite3.hpp b/include/mbgl/util/sqlite3.hpp deleted file mode 100644 index 3e324f7ce1..0000000000 --- a/include/mbgl/util/sqlite3.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include <string> -#include <stdexcept> - -typedef struct sqlite3 sqlite3; -typedef struct sqlite3_stmt sqlite3_stmt; - -namespace mapbox { -namespace sqlite { - -enum OpenFlag : int { - ReadOnly = 0x00000001, - ReadWrite = 0x00000002, - Create = 0x00000004, - NoMutex = 0x00008000, - FullMutex = 0x00010000, - SharedCache = 0x00020000, - PrivateCache = 0x00040000, -}; - -struct Exception : std::runtime_error { - inline Exception(int err, const char *msg) : std::runtime_error(msg), code(err) {} - const int code = 0; -}; - -class Statement; - -class Database { -private: - Database(const Database &) = delete; - Database &operator=(const Database &) = delete; - -public: - Database(const std::string &filename, int flags = 0); - Database(Database &&); - ~Database(); - Database &operator=(Database &&); - - operator bool() const; - - void exec(const std::string &sql); - Statement prepare(const char *query); - -private: - sqlite3 *db = nullptr; -}; - -class Statement { -private: - Statement(const Statement &) = delete; - Statement &operator=(const Statement &) = delete; - -public: - Statement(sqlite3 *db, const char *sql); - Statement(Statement &&); - ~Statement(); - Statement &operator=(Statement &&); - - operator bool() const; - - template <typename T> void bind(int offset, T value); - void bind(int offset, const std::string &value, bool retain = true); - template <typename T> T get(int offset); - - bool run(); - void reset(); - -private: - sqlite3_stmt *stmt = nullptr; -}; - -} -} diff --git a/include/mbgl/util/stopwatch.hpp b/include/mbgl/util/stopwatch.hpp deleted file mode 100644 index 663bbb6fc7..0000000000 --- a/include/mbgl/util/stopwatch.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MBGL_UTIL_STOPWATCH -#define MBGL_UTIL_STOPWATCH - -#include <mbgl/platform/event.hpp> - -#include <string> - -namespace mbgl { -namespace util { - -#ifndef DISABLE_STOPWATCH -class stopwatch { -public: - stopwatch(Event event = Event::General); - stopwatch(EventSeverity severity, Event event = Event::General); - stopwatch(const std::string &name, Event event = Event::General); - stopwatch(const std::string &name, EventSeverity severity, Event event = Event::General); - void report(const std::string &name); - ~stopwatch(); - -private: - const std::string name; - EventSeverity severity = EventSeverity::Debug; - Event event = Event::General; - uint64_t start; -}; -#else -class stopwatch { - inline stopwatch(Event event = Event::General); - inline stopwatch(EventSeverity severity, Event event = Event::General); - inline stopwatch(const std::string &name, Event event = Event::General); - inline stopwatch(const std::string &name, EventSeverity severity, Event event = Event::General); - inline void report(const std::string &name) {} - inline ~stopwatch() {} -}; -#endif -} -} - -#endif diff --git a/include/mbgl/util/texture_pool.hpp b/include/mbgl/util/texture_pool.hpp deleted file mode 100644 index 95d918c237..0000000000 --- a/include/mbgl/util/texture_pool.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MBGL_UTIL_TEXTUREPOOL -#define MBGL_UTIL_TEXTUREPOOL - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/platform/gl.hpp> - -#include <set> -#include <mutex> - -namespace mbgl { - -class TexturePool : private util::noncopyable { - -public: - GLuint getTextureID(); - void removeTextureID(GLuint texture_id); - void clearTextureIDs(); - -private: - std::set<GLuint> texture_ids; -}; - -} - -#endif diff --git a/include/mbgl/util/token.hpp b/include/mbgl/util/token.hpp deleted file mode 100644 index 64192a99f9..0000000000 --- a/include/mbgl/util/token.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef MBGL_UTIL_TOKEN -#define MBGL_UTIL_TOKEN - -#include <map> -#include <string> -#include <algorithm> - -namespace mbgl { -namespace util { - -// Replaces {tokens} in a string by calling the lookup function. -template <typename Lookup> -std::string replaceTokens(const std::string &source, const Lookup &lookup) { - std::string result; - result.reserve(source.size()); - - auto pos = source.begin(); - const auto end = source.end(); - - while (pos != end) { - auto brace = std::find(pos, end, '{'); - result.append(pos, brace); - pos = brace; - if (pos != end) { - for (brace++; brace != end && (std::isalnum(*brace) || *brace == '_'); brace++); - if (brace != end && *brace == '}') { - result.append(lookup({ pos + 1, brace })); - pos = brace + 1; - } else { - result.append(pos, brace); - pos = brace; - } - } - } - - return result; -} - -template <typename T> -inline std::string replaceTokens(const std::string &source, const std::map<std::string, T> &properties) { - return replaceTokens(source, [&properties](const std::string &token) -> std::string { - const auto it_prop = properties.find(token); - return it_prop != properties.end() ? toString(it_prop->second) : ""; - }); -} - -} // end namespace util -} // end namespace mbgl - -#endif diff --git a/include/mbgl/util/transition.hpp b/include/mbgl/util/transition.hpp deleted file mode 100644 index b78abfa8fd..0000000000 --- a/include/mbgl/util/transition.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef MBGL_UTIL_TRANSITION -#define MBGL_UTIL_TRANSITION - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/time.hpp> -#include <mbgl/style/types.hpp> - -namespace mbgl { -namespace util { - -class transition : private noncopyable { -public: - enum state { - running, - complete - }; - - inline transition(timestamp start_, timestamp duration_) - : start(start_), - duration(duration_) {} - - inline float progress(timestamp now) const { - if (duration == 0) return 1; - if (start > now) return 0; - - return (float)(now - start) / duration; - } - - virtual state update(timestamp now) const = 0; - virtual ~transition(); - -protected: - const timestamp start, duration; -}; - -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_) {} - - state update(timestamp now) const; - -private: - const T from, to; - T& value; - -}; - -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_) {} - - state update(timestamp now) const { - if (progress(now) >= 1) { - value = final_value; - return complete; - } else { - return running; - } - } - -private: - const T final_value; - T& value; -}; - -} -} - -#endif diff --git a/include/mbgl/util/unitbezier.hpp b/include/mbgl/util/unitbezier.hpp deleted file mode 100644 index 095e15f809..0000000000 --- a/include/mbgl/util/unitbezier.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2008 Apple Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MBGL_UTIL_UNITBEZIER -#define MBGL_UTIL_UNITBEZIER - -#include <cmath> - -namespace mbgl { -namespace util { - -struct UnitBezier { - UnitBezier(double p1x, double p1y, double p2x, double p2y) { - // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1). - cx = 3.0 * p1x; - bx = 3.0 * (p2x - p1x) - cx; - ax = 1.0 - cx - bx; - - cy = 3.0 * p1y; - by = 3.0 * (p2y - p1y) - cy; - ay = 1.0 - cy - by; - } - - double sampleCurveX(double t) { - // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule. - return ((ax * t + bx) * t + cx) * t; - } - - double sampleCurveY(double t) { - return ((ay * t + by) * t + cy) * t; - } - - double sampleCurveDerivativeX(double t) { - return (3.0 * ax * t + 2.0 * bx) * t + cx; - } - - // Given an x value, find a parametric value it came from. - double solveCurveX(double x, double epsilon) { - double t0; - double t1; - double t2; - double x2; - double d2; - int i; - - // First try a few iterations of Newton's method -- normally very fast. - for (t2 = x, i = 0; i < 8; ++i) { - x2 = sampleCurveX(t2) - x; - if (fabs (x2) < epsilon) - return t2; - d2 = sampleCurveDerivativeX(t2); - if (fabs(d2) < 1e-6) - break; - t2 = t2 - x2 / d2; - } - - // Fall back to the bisection method for reliability. - t0 = 0.0; - t1 = 1.0; - t2 = x; - - if (t2 < t0) - return t0; - if (t2 > t1) - return t1; - - while (t0 < t1) { - x2 = sampleCurveX(t2); - if (fabs(x2 - x) < epsilon) - return t2; - if (x > x2) - t0 = t2; - else - t1 = t2; - t2 = (t1 - t0) * .5 + t0; - } - - // Failure. - return t2; - } - - double solve(double x, double epsilon) { - return sampleCurveY(solveCurveX(x, epsilon)); - } - -private: - double ax; - double bx; - double cx; - - double ay; - double by; - double cy; -}; - -} -} - -#endif diff --git a/include/mbgl/util/url.hpp b/include/mbgl/util/url.hpp deleted file mode 100644 index a7e5291ec5..0000000000 --- a/include/mbgl/util/url.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MBGL_UTIL_URL -#define MBGL_UTIL_URL - -#include <string> - -namespace mbgl { -namespace util { - -std::string percentEncode(const std::string&); -std::string percentDecode(const std::string&); - -} -} - -#endif diff --git a/include/mbgl/util/uv-channel.h b/include/mbgl/util/uv-channel.h deleted file mode 100644 index ea5c279f65..0000000000 --- a/include/mbgl/util/uv-channel.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MBGL_UTIL_UV_CHANNEL -#define MBGL_UTIL_UV_CHANNEL - -#ifdef __cplusplus -extern "C" { -#endif - -#include <uv.h> - -// Taken from http://navaneeth.github.io/blog/2013/08/02/channels-in-libuv/ - -typedef struct uv_chan_s uv_chan_t; - -struct uv_chan_s { - uv_mutex_t mutex; - uv_cond_t cond; - void *q[2]; -}; - -int uv_chan_init(uv_chan_t *chan); -void uv_chan_send(uv_chan_t *chan, void *data); -void *uv_chan_receive(uv_chan_t *chan); -void uv_chan_destroy(uv_chan_t *chan); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/mbgl/util/uv-worker.h b/include/mbgl/util/uv-worker.h deleted file mode 100644 index cb2075d1c3..0000000000 --- a/include/mbgl/util/uv-worker.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MBGL_UTIL_UV_WORKER -#define MBGL_UTIL_UV_WORKER - -#ifdef __cplusplus -extern "C" { -#endif - -#include <mbgl/util/uv-messenger.h> -#include <mbgl/util/uv-channel.h> - -#include <stdlib.h> - -typedef struct uv_worker_s uv_worker_t; - -typedef void (*uv_worker_cb)(void *data); -typedef void (*uv_worker_after_cb)(void *data); -typedef void (*uv_worker_close_cb)(uv_worker_t *worker); - -struct uv_worker_s { -#ifndef NDEBUG - unsigned long thread_id; -#endif - uv_loop_t *loop; - uv_messenger_t *msgr; - uv_chan_t chan; - const char *name; - int count; - uv_worker_close_cb close_cb; - unsigned int active_items; -}; - -int uv_worker_init(uv_worker_t *worker, uv_loop_t *loop, int count, const char *name); -void uv_worker_send(uv_worker_t *worker, void *data, uv_worker_cb work_cb, - uv_worker_after_cb after_work_cb); -void uv_worker_close(uv_worker_t *worker, uv_worker_close_cb close_cb); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp deleted file mode 100644 index 99f5edc145..0000000000 --- a/include/mbgl/util/uv_detail.hpp +++ /dev/null @@ -1,177 +0,0 @@ -#ifndef MBGL_UTIL_UV_DETAIL -#define MBGL_UTIL_UV_DETAIL - -#include <mbgl/util/uv-worker.h> -#include <mbgl/util/noncopyable.hpp> - -#include <uv.h> - -#include <functional> -#include <cassert> -#include <memory> -#include <string> - -namespace uv { - -template <class T> -void close(std::unique_ptr<T> ptr) { - uv_close(reinterpret_cast<uv_handle_t*>(ptr.release()), [](uv_handle_t* handle) { - delete reinterpret_cast<T*>(handle); - }); -} - -class loop : public mbgl::util::noncopyable { -public: - inline loop() { -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - l = uv_loop_new(); - if (l == nullptr) { -#else - l = new uv_loop_t; - if (uv_loop_init(l) != 0) { -#endif - throw std::runtime_error("failed to initialize loop"); - } - } - - inline ~loop() { -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - uv_loop_delete(l); -#else - uv_loop_close(l); - delete l; -#endif - - } - - inline uv_loop_t *operator*() { return l; } - -private: - uv_loop_t *l = nullptr; -}; - -class async : public mbgl::util::noncopyable { -public: - inline async(uv_loop_t* loop, std::function<void ()> fn_) - : a(new uv_async_t) - , fn(fn_) - { - a->data = this; - if (uv_async_init(loop, a.get(), async_cb) != 0) { - throw std::runtime_error("failed to initialize async"); - } - } - - inline ~async() { - close(std::move(a)); - } - - inline void send() { - if (uv_async_send(a.get()) != 0) { - throw std::runtime_error("failed to async send"); - } - } - -private: -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - static void async_cb(uv_async_t* a, int) { -#else - static void async_cb(uv_async_t* a) { -#endif - reinterpret_cast<async*>(a->data)->fn(); - } - - std::unique_ptr<uv_async_t> a; - std::function<void ()> fn; -}; - -class rwlock : public mbgl::util::noncopyable { -public: - inline rwlock() { - if (uv_rwlock_init(&mtx) != 0) { - throw std::runtime_error("failed to initialize read-write lock"); - } - } - inline ~rwlock() { uv_rwlock_destroy(&mtx); } - inline void rdlock() { uv_rwlock_rdlock(&mtx); } - inline void wrlock() { uv_rwlock_wrlock(&mtx); } - inline void rdunlock() { uv_rwlock_rdunlock(&mtx); } - inline void wrunlock() { uv_rwlock_wrunlock(&mtx); } - -private: - uv_rwlock_t mtx; -}; - -class readlock : public mbgl::util::noncopyable { -public: - 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: - rwlock &mtx; -}; - -class writelock : public mbgl::util::noncopyable { -public: - 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: - rwlock &mtx; -}; - -class worker : public mbgl::util::noncopyable { -public: - inline worker(uv_loop_t *loop, unsigned int count, const char *name = nullptr) : w(new uv_worker_t) { - uv_worker_init(w, loop, count, name); - } - inline ~worker() { - uv_worker_close(w, [](uv_worker_t *worker_) { - delete worker_; - }); - } - inline void add(void *data, uv_worker_cb work_cb, uv_worker_after_cb after_work_cb) { - uv_worker_send(w, data, work_cb, after_work_cb); - } - -private: - uv_worker_t *w; -}; - -template <typename T> -class work : public mbgl::util::noncopyable { -public: - typedef std::function<void (T&)> work_callback; - typedef std::function<void (T&)> after_work_callback; - - template<typename... 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_) { - worker.add(this, do_work, after_work); - } - -private: - static void do_work(void *data) { - work<T> *w = reinterpret_cast<work<T> *>(data); - w->work_cb(w->data); - } - - static void after_work(void *data) { - work<T> *w = reinterpret_cast<work<T> *>(data); - w->after_work_cb(w->data); - delete w; - } - -private: - T data; - work_callback work_cb; - after_work_callback after_work_cb; -}; - -} - -#endif diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp index 0179254fda..32de852758 100644 --- a/include/mbgl/util/vec.hpp +++ b/include/mbgl/util/vec.hpp @@ -105,11 +105,6 @@ struct vec4 { }; -struct box { - vec2<double> tl, tr, bl, br; - vec2<double> center; -}; - typedef vec2<int16_t> Coordinate; } |