[core] Remove priority from the constructor
Make the constructor less verbose and set good defaults.
This commit is contained in:
@@ -54,12 +54,10 @@ public:
|
||||
|
||||
Resource(Kind kind_,
|
||||
std::string url_,
|
||||
Priority priority_ = Resource::Priority::Regular,
|
||||
optional<TileData> tileData_ = {},
|
||||
LoadingMethod loadingMethod_ = LoadingMethod::All)
|
||||
: kind(kind_),
|
||||
loadingMethod(loadingMethod_),
|
||||
priority(priority_),
|
||||
url(std::move(url_)),
|
||||
tileData(std::move(tileData_)) {
|
||||
}
|
||||
@@ -69,28 +67,26 @@ public:
|
||||
|
||||
bool hasLoadingMethod(LoadingMethod method);
|
||||
|
||||
static Resource style(const std::string& url, const Priority priority = Resource::Priority::Regular);
|
||||
static Resource source(const std::string& url, const Priority priority = Resource::Priority::Regular);
|
||||
static Resource style(const std::string& url);
|
||||
static Resource source(const std::string& url);
|
||||
static Resource tile(const std::string& urlTemplate,
|
||||
float pixelRatio,
|
||||
int32_t x,
|
||||
int32_t y,
|
||||
int8_t z,
|
||||
Tileset::Scheme scheme,
|
||||
const Priority priority = Resource::Priority::Regular,
|
||||
LoadingMethod = LoadingMethod::All);
|
||||
static Resource glyphs(const std::string& urlTemplate,
|
||||
const FontStack& fontStack,
|
||||
const std::pair<uint16_t, uint16_t>& glyphRange,
|
||||
const Priority priority = Resource::Priority::Regular);
|
||||
static Resource spriteImage(const std::string& base, float pixelRatio, const Priority priority = Resource::Priority::Regular);
|
||||
static Resource spriteJSON(const std::string& base, float pixelRatio, const Priority priority = Resource::Priority::Regular);
|
||||
static Resource image(const std::string& url, const Priority priority = Resource::Priority::Regular);
|
||||
const std::pair<uint16_t, uint16_t>& glyphRange);
|
||||
static Resource spriteImage(const std::string& base, float pixelRatio);
|
||||
static Resource spriteJSON(const std::string& base, float pixelRatio);
|
||||
static Resource image(const std::string& url);
|
||||
|
||||
Kind kind;
|
||||
LoadingMethod loadingMethod;
|
||||
Usage usage{ Usage::Online };
|
||||
Priority priority;
|
||||
Priority priority{ Priority::Regular };
|
||||
std::string url;
|
||||
|
||||
// Includes auxiliary data if this is a tile request.
|
||||
|
||||
@@ -39,49 +39,44 @@ static std::string getTileBBox(int32_t x, int32_t y, int8_t z) {
|
||||
util::toString(max.x) + "," + util::toString(max.y));
|
||||
}
|
||||
|
||||
Resource Resource::style(const std::string& url, const Priority priority) {
|
||||
Resource Resource::style(const std::string& url) {
|
||||
return Resource {
|
||||
Resource::Kind::Style,
|
||||
url,
|
||||
priority
|
||||
url
|
||||
};
|
||||
}
|
||||
|
||||
Resource Resource::source(const std::string& url, const Priority priority) {
|
||||
Resource Resource::source(const std::string& url) {
|
||||
return Resource {
|
||||
Resource::Kind::Source,
|
||||
url,
|
||||
priority
|
||||
url
|
||||
};
|
||||
}
|
||||
|
||||
Resource Resource::image(const std::string& url, const Priority priority) {
|
||||
Resource Resource::image(const std::string& url) {
|
||||
return Resource {
|
||||
Resource::Kind::Image,
|
||||
url,
|
||||
priority
|
||||
url
|
||||
};
|
||||
}
|
||||
|
||||
Resource Resource::spriteImage(const std::string& base, float pixelRatio, const Priority priority) {
|
||||
Resource Resource::spriteImage(const std::string& base, float pixelRatio) {
|
||||
util::URL url(base);
|
||||
return Resource{ Resource::Kind::SpriteImage,
|
||||
base.substr(0, url.path.first + url.path.second) +
|
||||
(pixelRatio > 1 ? "@2x" : "") + ".png" +
|
||||
base.substr(url.query.first, url.query.second),
|
||||
priority };
|
||||
base.substr(url.query.first, url.query.second)};
|
||||
}
|
||||
|
||||
Resource Resource::spriteJSON(const std::string& base, float pixelRatio, const Priority priority) {
|
||||
Resource Resource::spriteJSON(const std::string& base, float pixelRatio) {
|
||||
util::URL url(base);
|
||||
return Resource{ Resource::Kind::SpriteJSON,
|
||||
base.substr(0, url.path.first + url.path.second) +
|
||||
(pixelRatio > 1 ? "@2x" : "") + ".json" +
|
||||
base.substr(url.query.first, url.query.second),
|
||||
priority };
|
||||
base.substr(url.query.first, url.query.second)};
|
||||
}
|
||||
|
||||
Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontStack, const std::pair<uint16_t, uint16_t>& glyphRange, const Priority priority) {
|
||||
Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontStack, const std::pair<uint16_t, uint16_t>& glyphRange) {
|
||||
return Resource {
|
||||
Resource::Kind::Glyphs,
|
||||
util::replaceTokens(urlTemplate, [&](const std::string& token) -> optional<std::string> {
|
||||
@@ -92,8 +87,7 @@ Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontS
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}),
|
||||
priority
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -103,7 +97,6 @@ Resource Resource::tile(const std::string& urlTemplate,
|
||||
int32_t y,
|
||||
int8_t z,
|
||||
Tileset::Scheme scheme,
|
||||
const Priority priority,
|
||||
LoadingMethod loadingMethod) {
|
||||
bool supportsRatio = urlTemplate.find("{ratio}") != std::string::npos;
|
||||
if (scheme == Tileset::Scheme::TMS) {
|
||||
@@ -133,7 +126,6 @@ Resource Resource::tile(const std::string& urlTemplate,
|
||||
return {};
|
||||
}
|
||||
}),
|
||||
priority,
|
||||
Resource::TileData {
|
||||
urlTemplate,
|
||||
uint8_t(supportsRatio && pixelRatio > 1.0 ? 2 : 1),
|
||||
|
||||
@@ -23,7 +23,6 @@ TileLoader<T>::TileLoader(T& tile_,
|
||||
id.canonical.y,
|
||||
id.canonical.z,
|
||||
tileset.scheme,
|
||||
Resource::Priority::Regular,
|
||||
Resource::LoadingMethod::CacheOnly)),
|
||||
fileSource(parameters.fileSource) {
|
||||
assert(!request);
|
||||
|
||||
@@ -251,7 +251,7 @@ TEST(DefaultFileSource, OptionalNonExpired) {
|
||||
util::RunLoop loop;
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", Resource::Priority::Regular, {}, Resource::LoadingMethod::CacheOnly };
|
||||
const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", {}, Resource::LoadingMethod::CacheOnly };
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@@ -281,7 +281,7 @@ TEST(DefaultFileSource, OptionalExpired) {
|
||||
util::RunLoop loop;
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", Resource::Priority::Regular, {}, Resource::LoadingMethod::CacheOnly };
|
||||
const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", {}, Resource::LoadingMethod::CacheOnly };
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@@ -327,7 +327,7 @@ TEST(DefaultFileSource, OptionalNotFound) {
|
||||
util::RunLoop loop;
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", Resource::Priority::Regular, {}, Resource::LoadingMethod::CacheOnly };
|
||||
const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", {}, Resource::LoadingMethod::CacheOnly };
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(LowHighPriorityRequestsMany)) {
|
||||
|
||||
for (int num_reqs = 0; num_reqs < 20; num_reqs++) {
|
||||
if (num_reqs % 2 == 0) {
|
||||
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/load/" + std::to_string(num_reqs), Resource::Priority::Regular }, [&](Response) {
|
||||
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/load/" + std::to_string(num_reqs) }, [&](Response) {
|
||||
response_counter++;
|
||||
|
||||
if (response_counter <= 10) { // count the high priority requests that arrive late correctly
|
||||
@@ -491,7 +491,10 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(LowHighPriorityRequestsMany)) {
|
||||
collector.push_back(std::move(req));
|
||||
}
|
||||
else {
|
||||
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/load/" + std::to_string(num_reqs), Resource::Priority::Low }, [&](Response) {
|
||||
Resource resource = { Resource::Unknown, "http://127.0.0.1:3000/load/" + std::to_string(num_reqs) };
|
||||
resource.setPriority(Resource::Priority::Low);
|
||||
|
||||
std::unique_ptr<AsyncRequest> req = fs.request(std::move(resource), [&](Response) {
|
||||
response_counter++;
|
||||
|
||||
if (response_counter > 10) { // count the low priority requests that arrive late correctly
|
||||
|
||||
Reference in New Issue
Block a user