diff options
Diffstat (limited to 'include/mbgl/util')
-rw-r--r-- | include/mbgl/util/exception.hpp | 20 | ||||
-rw-r--r-- | include/mbgl/util/exclusive.hpp | 30 | ||||
-rw-r--r-- | include/mbgl/util/std.hpp | 23 |
3 files changed, 50 insertions, 23 deletions
diff --git a/include/mbgl/util/exception.hpp b/include/mbgl/util/exception.hpp index 0b4403270c..da61aa482a 100644 --- a/include/mbgl/util/exception.hpp +++ b/include/mbgl/util/exception.hpp @@ -11,6 +11,11 @@ struct Exception : std::runtime_error { inline Exception(const std::string &msg) : std::runtime_error(msg) {} }; +struct GlyphRangeLoadingException : Exception { + inline GlyphRangeLoadingException(const char *msg) : Exception(msg) {} + inline GlyphRangeLoadingException(const std::string &msg) : Exception(msg) {} +}; + struct MisuseException : Exception { inline MisuseException(const char *msg) : Exception(msg) {} inline MisuseException(const std::string &msg) : Exception(msg) {} @@ -21,6 +26,21 @@ struct ShaderException : Exception { inline ShaderException(const std::string &msg) : Exception(msg) {} }; +struct SourceLoadingException : Exception { + inline SourceLoadingException(const char *msg) : Exception(msg) {} + inline SourceLoadingException(const std::string &msg) : Exception(msg) {} +}; + +struct SpriteLoadingException : Exception { + inline SpriteLoadingException(const char *msg) : Exception(msg) {} + inline SpriteLoadingException(const std::string &msg) : Exception(msg) {} +}; + +struct TileLoadingException : Exception { + inline TileLoadingException(const char *msg) : Exception(msg) {} + inline TileLoadingException(const std::string &msg) : Exception(msg) {} +}; + } } diff --git a/include/mbgl/util/exclusive.hpp b/include/mbgl/util/exclusive.hpp new file mode 100644 index 0000000000..bb3395996b --- /dev/null +++ b/include/mbgl/util/exclusive.hpp @@ -0,0 +1,30 @@ +#ifndef MBGL_UTIL_EXCLUSIVE +#define MBGL_UTIL_EXCLUSIVE + +#include <memory> +#include <mutex> + + +namespace mbgl { +namespace util { + +template <class T> +class exclusive { +public: + inline exclusive(T* val, std::unique_ptr<std::lock_guard<std::mutex>> mtx) : ptr(val), lock(std::move(mtx)) {} + + inline T* operator->() { return ptr; } + inline const T* operator->() const { return ptr; } + inline T* operator*() { return ptr; } + inline const T* operator*() const { return ptr; } + +private: + T *ptr; + std::unique_ptr<std::lock_guard<std::mutex>> lock; +}; + + +} // end namespace util +} // end namespace mbgl + +#endif diff --git a/include/mbgl/util/std.hpp b/include/mbgl/util/std.hpp index e64820de47..0e2d3346bf 100644 --- a/include/mbgl/util/std.hpp +++ b/include/mbgl/util/std.hpp @@ -8,29 +8,6 @@ namespace mbgl { namespace util { -// C++14 backfill based on http://llvm.org/svn/llvm-project/libcxx/trunk/include/memory - -namespace detail { -template<class T> struct unique_type { typedef ::std::unique_ptr<T> single; }; -template<class T> struct unique_type<T[]> { typedef ::std::unique_ptr<T[]> unknown_bound; }; -template<class T, size_t size> struct unique_type<T[size]> { typedef void known_bound; }; -} - -template<class T, class... Args> -typename detail::unique_type<T>::single make_unique(Args&&... args) { - return ::std::unique_ptr<T>(new T(::std::forward<Args>(args)...)); -} - -template<class T> -typename detail::unique_type<T>::unknown_bound make_unique(size_t size) { - return ::std::unique_ptr<T>(new typename ::std::remove_extent<T>::type[size]()); -} - -template<class T, class... Args> -typename detail::unique_type<T>::known_bound make_unique(Args&&...) = delete; - - - template <typename Container, typename ForwardIterator, typename Predicate> void erase_if(Container &container, ForwardIterator it, const ForwardIterator end, Predicate pred) { while (it != end) { |