summaryrefslogtreecommitdiff
path: root/test/src/mbgl/test/stub_style_observer.hpp
blob: 45af1edf9db696e7af08cabac0fd50dac05a898e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once

#include <mbgl/style/style_observer.hpp>

namespace mbgl {

/**
 * An implementation of StyleObserver that forwards all methods to dynamically-settable lambas.
 */
class StubStyleObserver : public StyleObserver {
public:
    void onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) override {
        if (glyphsLoaded) glyphsLoaded(fontStack, glyphRange);
    }

    void onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) override {
        if (glyphsError) glyphsError(fontStack, glyphRange, error);
    }

    void onSpriteLoaded() override {
        if (spriteLoaded) spriteLoaded();
    }

    void onSpriteError(std::exception_ptr error) override {
        if (spriteError) spriteError(error);
    }

    void onSourceLoaded(Source& source) override {
        if (sourceLoaded) sourceLoaded(source);
    }

    void onSourceError(Source& source, std::exception_ptr error) override {
        if (sourceError) sourceError(source, error);
    }

    void onTileLoaded(Source& source, const OverscaledTileID& tileID, bool isNewTile) override {
        if (tileLoaded) tileLoaded(source, tileID, isNewTile);
    }

    void
    onTileError(Source& source, const OverscaledTileID& tileID, std::exception_ptr error) override {
        if (tileError) tileError(source, tileID, error);
    }

    void onResourceLoaded() override {
        if (resourceLoaded) resourceLoaded();
    };

    void onResourceError(std::exception_ptr error) override {
        if (resourceError) resourceError(error);
    };

    std::function<void (const FontStack&, const GlyphRange&)> glyphsLoaded;
    std::function<void (const FontStack&, const GlyphRange&, std::exception_ptr)> glyphsError;
    std::function<void ()> spriteLoaded;
    std::function<void (std::exception_ptr)> spriteError;
    std::function<void (Source&)> sourceLoaded;
    std::function<void (Source&, std::exception_ptr)> sourceError;
    std::function<void (Source&, const OverscaledTileID&, bool isNewTile)> tileLoaded;
    std::function<void (Source&, const OverscaledTileID&, std::exception_ptr)> tileError;
    std::function<void ()> resourceLoaded;
    std::function<void (std::exception_ptr)> resourceError;
};

} // namespace mbgl