diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-12-03 11:27:24 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-12-03 11:27:24 +0100 |
commit | 82f3574d09064a442e30eb2dc7639f473749c5bd (patch) | |
tree | dfb0aa6182a0d7d04b6131199d67ff90a87cb9c1 /platform | |
parent | 50669307c5648e62941a63e0c75dba8602448d9d (diff) | |
download | qtlocation-mapboxgl-82f3574d09064a442e30eb2dc7639f473749c5bd.tar.gz |
add array overloads to make_unique and move it to mbgl::util from std
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/http_request_baton_cocoa.mm | 6 | ||||
-rw-r--r-- | platform/darwin/image.mm | 3 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 6 | ||||
-rw-r--r-- | platform/default/http_request_baton_curl.cpp | 5 | ||||
-rw-r--r-- | platform/default/image.cpp | 3 | ||||
-rw-r--r-- | platform/default/image_reader.cpp | 4 |
6 files changed, 16 insertions, 11 deletions
diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm index 03fa3bb821..28afbb5086 100644 --- a/platform/darwin/http_request_baton_cocoa.mm +++ b/platform/darwin/http_request_baton_cocoa.mm @@ -51,7 +51,7 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { } else { // TODO: Use different codes for host not found, timeout, invalid URL etc. // These can be categorized in temporary and permanent errors. - baton->response = std::make_unique<Response>(); + baton->response = util::make_unique<Response>(); baton->response->code = [(NSHTTPURLResponse *)res statusCode]; baton->response->message = [[error localizedDescription] UTF8String]; @@ -86,7 +86,7 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { // Assume a Response object already exists. assert(baton->response); } else { - baton->response = std::make_unique<Response>(); + baton->response = util::make_unique<Response>(); baton->response->code = code; baton->response->data = {(const char *)[data bytes], [data length]}; } @@ -117,7 +117,7 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { } else { // This should never happen. baton->type = HTTPResponseType::PermanentError; - baton->response = std::make_unique<Response>(); + baton->response = util::make_unique<Response>(); baton->response->code = -1; baton->response->message = "response class is not NSHTTPURLResponse"; } diff --git a/platform/darwin/image.mm b/platform/darwin/image.mm index b8df3c403e..4819d2cd3c 100644 --- a/platform/darwin/image.mm +++ b/platform/darwin/image.mm @@ -1,4 +1,5 @@ #include <mbgl/util/image.hpp> +#include <mbgl/util/std.hpp> #import <ImageIO/ImageIO.h> @@ -97,7 +98,7 @@ Image::Image(const std::string &source_data) { height = uint32_t(CGImageGetHeight(image)); CGRect rect = {{ 0, 0 }, { static_cast<CGFloat>(width), static_cast<CGFloat>(height) }}; - img = ::std::unique_ptr<char[]>(new char[width * height * 4]()); + img = util::make_unique<char[]>(width * height * 4); CGContextRef context = CGBitmapContextCreate(img.get(), width, height, 8, width * 4, color_space, kCGImageAlphaPremultipliedLast); if (!context) { diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 10d6ed8f42..5b95c76026 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -1,6 +1,8 @@ #include <mbgl/platform/default/headless_view.hpp> #include <mbgl/platform/default/headless_display.hpp> +#include <mbgl/util/std.hpp> + #include <stdexcept> #include <sstream> #include <string> @@ -232,14 +234,14 @@ std::unique_ptr<uint32_t[]> HeadlessView::readPixels() { const unsigned int w = width_ * pixelRatio_; const unsigned int h = height_ * pixelRatio_; - auto pixels = std::unique_ptr<uint32_t[]>(new uint32_t[w * h]); + auto pixels = util::make_unique<uint32_t[]>(w * h); make_active(); glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); make_inactive(); const int stride = w * 4; - auto tmp = std::unique_ptr<char[]>(new char[stride]()); + auto tmp = util::make_unique<char[]>(stride); char *rgba = reinterpret_cast<char *>(pixels.get()); for (int i = 0, j = height_ - 1; i < j; i++, j--) { std::memcpy(tmp.get(), rgba + i * stride, stride); diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index 02e9497c9e..4b825622ae 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -2,6 +2,7 @@ #include <mbgl/util/uv-messenger.h> #include <mbgl/util/time.hpp> #include <mbgl/util/string.hpp> +#include <mbgl/util/std.hpp> #include <uv.h> #include <curl/curl.h> @@ -114,7 +115,7 @@ struct Context { CURLMcode error = curl_multi_remove_handle(multi, handle); if (error != CURLM_OK) { - baton->response = std::unique_ptr<Response>(new Response()); + baton->response = util::make_unique<Response>(); baton->response->code = -1; baton->response->message = curl_multi_strerror(error); } @@ -429,7 +430,7 @@ void start_request(void *const ptr) { } if (!context->baton->response) { - context->baton->response = std::unique_ptr<Response>(new Response()); + context->baton->response = util::make_unique<Response>(); } // Carry on the shared pointer in the private information of the CURL handle. diff --git a/platform/default/image.cpp b/platform/default/image.cpp index 242367e889..d881b9231c 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -1,5 +1,6 @@ #include <mbgl/util/image.hpp> #include <mbgl/util/string.hpp> +#include <mbgl/util/std.hpp> #include <png.h> @@ -80,7 +81,7 @@ Image::Image(std::string const& data) auto reader = getImageReader(data.c_str(), data.size()); width = reader->width(); height = reader->height(); - img = ::std::unique_ptr<char[]>(new char[width * height * 4]()); + img = util::make_unique<char[]>(width * height * 4); reader->read(0, 0, width, height, img.get()); } catch (ImageReaderException const& ex) diff --git a/platform/default/image_reader.cpp b/platform/default/image_reader.cpp index e80ccb6819..fc6daec6a5 100644 --- a/platform/default/image_reader.cpp +++ b/platform/default/image_reader.cpp @@ -49,11 +49,11 @@ std::unique_ptr<ImageReader> getImageReader(char const* data, size_t size) { if (*type == "png") { - return std::make_unique<PngReader<boost::iostreams::array_source>>(data, size); + return util::make_unique<PngReader<boost::iostreams::array_source>>(data, size); } else if (*type == "jpeg") { - return std::make_unique<JpegReader<boost::iostreams::array_source>>(data, size); + return util::make_unique<JpegReader<boost::iostreams::array_source>>(data, size); } } throw ImageReaderException("ImageReader: can't determine type from input data"); |