summaryrefslogtreecommitdiff
path: root/include/mbgl/storage/resource.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/storage/resource.hpp')
-rw-r--r--include/mbgl/storage/resource.hpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index 5d44f4869f..318fa389f4 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -4,6 +4,8 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/tileset.hpp>
+#include <mbgl/util/util.hpp>
+#include <mbgl/util/traits.hpp>
#include <string>
@@ -30,18 +32,28 @@ public:
int8_t z;
};
- enum Necessity : bool {
- Optional = false,
- Required = true,
+ enum class LoadingMethod : uint8_t {
+ None = 0b00,
+ Cache = 0b01,
+ Network = 0b10,
+
+ CacheOnly = Cache,
+ NetworkOnly = Network,
+ All = Cache | Network,
};
- Resource(Kind kind_, std::string url_, optional<TileData> tileData_ = {}, Necessity necessity_ = Required)
+ Resource(Kind kind_,
+ std::string url_,
+ optional<TileData> tileData_ = {},
+ LoadingMethod loadingMethod_ = LoadingMethod::All)
: kind(kind_),
- necessity(necessity_),
+ loadingMethod(loadingMethod_),
url(std::move(url_)),
tileData(std::move(tileData_)) {
}
+ bool hasLoadingMethod(LoadingMethod method);
+
static Resource style(const std::string& url);
static Resource source(const std::string& url);
static Resource tile(const std::string& urlTemplate,
@@ -50,7 +62,7 @@ public:
int32_t y,
int8_t z,
Tileset::Scheme scheme,
- Necessity = Required);
+ LoadingMethod = LoadingMethod::All);
static Resource glyphs(const std::string& urlTemplate,
const FontStack& fontStack,
const std::pair<uint16_t, uint16_t>& glyphRange);
@@ -59,7 +71,7 @@ public:
static Resource image(const std::string& url);
Kind kind;
- Necessity necessity;
+ LoadingMethod loadingMethod;
std::string url;
// Includes auxiliary data if this is a tile request.
@@ -71,4 +83,21 @@ public:
std::shared_ptr<const std::string> priorData;
};
+
+MBGL_CONSTEXPR Resource::LoadingMethod operator|(Resource::LoadingMethod a, Resource::LoadingMethod b) {
+ return Resource::LoadingMethod(mbgl::underlying_type(a) | mbgl::underlying_type(b));
+}
+
+MBGL_CONSTEXPR Resource::LoadingMethod& operator|=(Resource::LoadingMethod& a, Resource::LoadingMethod b) {
+ return (a = a | b);
+}
+
+MBGL_CONSTEXPR Resource::LoadingMethod operator&(Resource::LoadingMethod a, Resource::LoadingMethod b) {
+ return Resource::LoadingMethod(mbgl::underlying_type(a) & mbgl::underlying_type(b));
+}
+
+inline bool Resource::hasLoadingMethod(Resource::LoadingMethod method) {
+ return (loadingMethod & method) != Resource::LoadingMethod::None;
+}
+
} // namespace mbgl