summaryrefslogtreecommitdiff
path: root/src/mbgl/text/glyph_pbf.hpp
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-07-15 12:02:58 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-07-17 21:00:34 +0300
commit234a6539311bca387a982ad1c6f51dde77d3c450 (patch)
tree6fb2fee309fc98edb4c6a8f3d0549c91548a21c1 /src/mbgl/text/glyph_pbf.hpp
parentdbf3edad8ae7a7cbaf7c109daa3f7f8c78c04c87 (diff)
downloadqtlocation-mapboxgl-234a6539311bca387a982ad1c6f51dde77d3c450.tar.gz
Use the observer pattern for GlyphPBF loading
This will make the code a lot more clear and it will also move how parsing is initiated to the GlyphPBF class, to be initiated after the request, like we do for other resources.
Diffstat (limited to 'src/mbgl/text/glyph_pbf.hpp')
-rw-r--r--src/mbgl/text/glyph_pbf.hpp47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp
index cc083e7f10..2aa2134d16 100644
--- a/src/mbgl/text/glyph_pbf.hpp
+++ b/src/mbgl/text/glyph_pbf.hpp
@@ -2,48 +2,53 @@
#define MBGL_TEXT_GLYPH_PBF
#include <mbgl/text/glyph.hpp>
+#include <mbgl/util/noncopyable.hpp>
-#include <functional>
#include <atomic>
+#include <functional>
#include <string>
namespace mbgl {
+class GlyphStore;
class FontStack;
class Request;
-class GlyphPBF {
+class GlyphPBF : private util::noncopyable {
public:
- using GlyphLoadedCallback = std::function<void(GlyphPBF*)>;
- using GlyphLoadingFailedCallback = std::function<void(const std::string&)>;
+ class Observer {
+ public:
+ virtual ~Observer() = default;
+
+ virtual void onGlyphPBFLoaded() = 0;
+ virtual void onGlyphPBFLoadingFailed(std::exception_ptr error) = 0;
+ };
- GlyphPBF(const std::string &glyphURL,
- const std::string &fontStack,
- GlyphRange glyphRange,
- const GlyphLoadedCallback& successCallback,
- const GlyphLoadingFailedCallback& failureCallback);
- ~GlyphPBF();
+ GlyphPBF(GlyphStore* store,
+ const std::string& fontStack,
+ const GlyphRange& glyphRange);
+ virtual ~GlyphPBF();
- void parse(FontStack &stack);
- bool isParsed() const;
+ bool isParsed() const {
+ return parsed;
+ };
- std::string getURL() const {
- return url;
- }
+ void setObserver(Observer* observer);
private:
- GlyphPBF(const GlyphPBF &) = delete;
- GlyphPBF(GlyphPBF &&) = delete;
- GlyphPBF &operator=(const GlyphPBF &) = delete;
- GlyphPBF &operator=(GlyphPBF &&) = delete;
+ void emitGlyphPBFLoaded();
+ void emitGlyphPBFLoadingFailed(const std::string& message);
+
+ void parse(GlyphStore* store, const std::string& fontStack, const std::string& url);
std::string data;
- std::string url;
std::atomic<bool> parsed;
Request* req = nullptr;
+
+ Observer* observer = nullptr;
};
-} // end namespace mbgl
+}
#endif