From 62b56b799a7d4fcd1a8f151eed878054b862da5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 26 Oct 2016 15:22:31 -0700 Subject: [core] change std::array to mbgl::Size --- include/mbgl/util/image.hpp | 36 ++++++++++++++++++------------------ include/mbgl/util/size.hpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 include/mbgl/util/size.hpp (limited to 'include/mbgl/util') diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index 795d1f9d1a..3dbab27f41 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -18,39 +19,38 @@ class Image : private util::noncopyable { public: Image() = default; - Image(uint16_t w, uint16_t h) - : width(w), - height(h), - data(std::make_unique(size())) {} + Image(Size size_) + : size(std::move(size_)), + data(std::make_unique(bytes())) {} - Image(uint16_t w, uint16_t h, std::unique_ptr data_) - : width(w), - height(h), + Image(Size size_, std::unique_ptr data_) + : size(std::move(size_)), data(std::move(data_)) {} Image(Image&& o) - : width(o.width), - height(o.height), + : size(o.size), data(std::move(o.data)) {} Image& operator=(Image&& o) { - width = o.width; - height = o.height; + size = o.size; data = std::move(o.data); return *this; } bool operator==(const Image& rhs) const { - return width == rhs.width && height == rhs.height && - std::equal(data.get(), data.get() + size(), rhs.data.get(), - rhs.data.get() + rhs.size()); + return size == rhs.size && + std::equal(data.get(), data.get() + bytes(), rhs.data.get(), + rhs.data.get() + rhs.bytes()); } - size_t stride() const { return static_cast(width) * 4; } - size_t size() const { return static_cast(width) * height * 4; } + bool valid() const { + return size && data.get() != nullptr; + } + + size_t stride() const { return static_cast(size.width) * 4; } + size_t bytes() const { return stride() * size.height; } - uint16_t width = 0; - uint16_t height = 0; + Size size; std::unique_ptr data; }; diff --git a/include/mbgl/util/size.hpp b/include/mbgl/util/size.hpp new file mode 100644 index 0000000000..c0e2fd8180 --- /dev/null +++ b/include/mbgl/util/size.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +namespace mbgl { + +class Size { +public: + constexpr Size() : width(0), height(0) { + } + + constexpr Size(const uint32_t width_, const uint32_t height_) : width(width_), height(height_) { + } + + constexpr operator bool() const { + return width > 0 && height > 0; + } + + uint32_t width; + uint32_t height; +}; + +constexpr inline bool operator==(const Size& a, const Size& b) { + return a.width == b.width && a.height == b.height; +} + +constexpr inline bool operator!=(const Size& a, const Size& b) { + return !(a == b); +} + +} // namespace mbgl -- cgit v1.2.1