[core] remove some uses of <iostream> and <sstream>

This commit is contained in:
Konstantin Käfer
2018-10-18 18:41:59 +02:00
parent 70d5972e10
commit 8bf66ef7a7
21 changed files with 61 additions and 56 deletions

View File

@@ -53,6 +53,27 @@ mapbox::geometry::geometry<double> parseGeometry(const std::string& json) {
});
}
std::ostream& operator<<(std::ostream& os, mbgl::Response::Error::Reason r) {
switch (r) {
case mbgl::Response::Error::Reason::Success:
return os << "Response::Error::Reason::Success";
case mbgl::Response::Error::Reason::NotFound:
return os << "Response::Error::Reason::NotFound";
case mbgl::Response::Error::Reason::Server:
return os << "Response::Error::Reason::Server";
case mbgl::Response::Error::Reason::Connection:
return os << "Response::Error::Reason::Connection";
case mbgl::Response::Error::Reason::RateLimit:
return os << "Response::Error::Reason::RateLimit";
case mbgl::Response::Error::Reason::Other:
return os << "Response::Error::Reason::Other";
}
// The above switch is exhaustive, but placate GCC nonetheless:
assert(false);
return os;
}
int main(int argc, char *argv[]) {
args::ArgumentParser argumentParser("Mapbox GL offline tool");
args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", {'h', "help"});

View File

@@ -752,6 +752,7 @@ src/mbgl/util/math.hpp
src/mbgl/util/offscreen_texture.cpp
src/mbgl/util/offscreen_texture.hpp
src/mbgl/util/premultiply.cpp
src/mbgl/util/rapidjson.cpp
src/mbgl/util/rapidjson.hpp
src/mbgl/util/rect.hpp
src/mbgl/util/std.hpp

View File

@@ -69,6 +69,4 @@ public:
Error(Reason, std::string = "", optional<Timestamp> = {});
};
std::ostream& operator<<(std::ostream&, Response::Error::Reason);
} // namespace mbgl

View File

@@ -1,7 +1,7 @@
#include "constant.hpp"
#include "collection.hpp"
#include <sstream>
#include <mbgl/util/string.hpp>
namespace mbgl {
namespace android {
@@ -24,9 +24,18 @@ Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, std::stri
}
Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, Color>::operator()(jni::JNIEnv& env, const Color& value) const {
std::stringstream sstream;
sstream << "rgba(" << value.r << ", " << value.g << ", " << value.b << ", " << value.a << ")";
return jni::Make<jni::String>(env, sstream.str());
std::string result;
result.reserve(32);
result += "rgba(";
result += util::toString(value.r);
result += ", ";
result += util::toString(value.g);
result += ", ";
result += util::toString(value.b);
result += ", ";
result += util::toString(value.a);
result += ")";
return jni::Make<jni::String>(env, result);
}
Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, style::expression::Formatted>::operator()(jni::JNIEnv& env, const style::expression::Formatted& value) const {

View File

@@ -317,7 +317,7 @@ test('Map', function(t) {
t.throws(function() {
map.load('foo bar');
}, /Failed to parse style: 1 - Invalid value./);
}, /Failed to parse style: Invalid value. at offset 1/);
t.throws(function() {
map.load('""');
@@ -349,7 +349,7 @@ test('Map', function(t) {
t.throws(function() {
map.load('invalid');
}, /Failed to parse style: 0 - Invalid value./);
}, /Failed to parse style: Invalid value. at offset 0/);
});
t.test('accepts an empty stylesheet string', function(t) {

View File

@@ -7,7 +7,6 @@
#include <vector>
#include <bitset>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <iterator>

View File

@@ -4,7 +4,6 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/hash.hpp>
#include <sstream>
#include <cmath>
namespace mbgl {

View File

@@ -4,7 +4,6 @@
#include <mbgl/algorithm/update_tile_masks.hpp>
#include <mbgl/geometry/dem_data.hpp>
#include <mbgl/renderer/buckets/hillshade_bucket.hpp>
#include <iostream>
namespace mbgl {

View File

@@ -9,7 +9,6 @@
#include <cmath>
#include <limits>
#include <sstream>
namespace mbgl {
@@ -91,9 +90,7 @@ std::vector<std::unique_ptr<style::Image>> parseSprite(const std::string& encode
JSDocument doc;
doc.Parse<0>(json.c_str());
if (doc.HasParseError()) {
std::stringstream message;
message << "Failed to parse JSON: " << rapidjson::GetParseError_En(doc.GetParseError()) << " at offset " << doc.GetErrorOffset();
throw std::runtime_error(message.str());
throw std::runtime_error("Failed to parse JSON: " + formatJSONParseError(doc));
} else if (!doc.IsObject()) {
throw std::runtime_error("Sprite JSON root must be an object");
} else {

View File

@@ -1,8 +1,4 @@
#include <mbgl/storage/response.hpp>
#include <mbgl/util/chrono.hpp>
#include <iostream>
#include <cassert>
namespace mbgl {
@@ -26,25 +22,4 @@ Response::Error::Error(Reason reason_, std::string message_, optional<Timestamp>
: reason(reason_), message(std::move(message_)), retryAfter(std::move(retryAfter_)) {
}
std::ostream& operator<<(std::ostream& os, Response::Error::Reason r) {
switch (r) {
case Response::Error::Reason::Success:
return os << "Response::Error::Reason::Success";
case Response::Error::Reason::NotFound:
return os << "Response::Error::Reason::NotFound";
case Response::Error::Reason::Server:
return os << "Response::Error::Reason::Server";
case Response::Error::Reason::Connection:
return os << "Response::Error::Reason::Connection";
case Response::Error::Reason::RateLimit:
return os << "Response::Error::Reason::RateLimit";
case Response::Error::Reason::Other:
return os << "Response::Error::Reason::Other";
}
// The above switch is exhaustive, but placate GCC nonetheless:
assert(false);
return os;
}
} // namespace mbgl

View File

@@ -4,7 +4,6 @@
#include <mbgl/style/rapidjson_conversion.hpp>
#include <string>
#include <sstream>
namespace mbgl {
namespace style {
@@ -16,9 +15,7 @@ optional<T> convertJSON(const std::string& json, Error& error, Args&&...args) {
document.Parse<0>(json.c_str());
if (document.HasParseError()) {
std::stringstream message;
message << document.GetErrorOffset() << " - " << rapidjson::GetParseError_En(document.GetParseError());
error = { message.str() };
error = { formatJSONParseError(document) };
return {};
}

View File

@@ -18,7 +18,6 @@
#include <algorithm>
#include <set>
#include <sstream>
namespace mbgl {
namespace style {
@@ -30,11 +29,7 @@ StyleParseResult Parser::parse(const std::string& json) {
document.Parse<0>(json.c_str());
if (document.HasParseError()) {
std::stringstream message;
message << document.GetErrorOffset() << " - "
<< rapidjson::GetParseError_En(document.GetParseError());
return std::make_exception_ptr(std::runtime_error(message.str()));
return std::make_exception_ptr(std::runtime_error(formatJSONParseError(document)));
}
if (!document.IsObject()) {

View File

@@ -5,6 +5,7 @@
#include <mbgl/text/bidi.hpp>
#include <algorithm>
#include <list>
#include <cmath>
namespace mbgl {

View File

@@ -19,8 +19,6 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <iostream>
namespace mbgl {
using namespace style;

View File

@@ -6,7 +6,6 @@
#include <stdexcept>
#include <vector>
#include <iostream>
#include <cstring>
namespace {

View File

@@ -0,0 +1,13 @@
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/util/string.hpp>
namespace mbgl {
std::string formatJSONParseError(const JSDocument& doc) {
return std::string{ rapidjson::GetParseError_En(doc.GetParseError()) } + " at offset " +
util::toString(doc.GetErrorOffset());
}
} // namespace mbgl

View File

@@ -8,4 +8,6 @@ namespace mbgl {
using JSDocument = rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator>;
using JSValue = rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator>;
std::string formatJSONParseError(const JSDocument&);
} // namespace mbgl

View File

@@ -4,7 +4,6 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/logging.hpp>
#include <iostream>
#include <atomic>
namespace mbgl {

View File

@@ -4,7 +4,10 @@
#include <mbgl/util/chrono.hpp>
#include <string>
#ifdef MBGL_TIMING
#include <sstream>
#endif
namespace mbgl {
namespace util {

View File

@@ -237,7 +237,7 @@ TEST(Map, SetStyleInvalidJSON) {
auto observer = Log::removeObserver();
auto flo = static_cast<FixtureLogObserver*>(observer.get());
EXPECT_EQ(1u, flo->count({ EventSeverity::Error, Event::ParseStyle, -1,
"Failed to parse style: 0 - Invalid value." }));
"Failed to parse style: Invalid value. at offset 0" }));
auto unchecked = flo->unchecked();
EXPECT_TRUE(unchecked.empty()) << unchecked;
}

View File

@@ -127,7 +127,7 @@ TEST(Source, LoadingCorrupt) {
test.styleObserver.sourceError = [&] (Source& source, std::exception_ptr error) {
EXPECT_EQ("source", source.getID());
EXPECT_EQ("0 - Invalid value.", util::toString(error));
EXPECT_EQ("Invalid value. at offset 0", util::toString(error));
test.end();
};