1 | #pragma once |
2 | |
3 | #include <mbgl/util/noncopyable.hpp> |
4 | #include <mbgl/util/optional.hpp> |
5 | #include <mbgl/util/unique_any.hpp> |
6 | #include <mbgl/util/immutable.hpp> |
7 | #include <mbgl/style/types.hpp> |
8 | |
9 | #include <memory> |
10 | #include <string> |
11 | |
12 | namespace mbgl { |
13 | |
14 | class FileSource; |
15 | |
16 | namespace style { |
17 | |
18 | class VectorSource; |
19 | class RasterSource; |
20 | class RasterDEMSource; |
21 | class GeoJSONSource; |
22 | class SourceObserver; |
23 | |
24 | /** |
25 | * The runtime representation of a [source](https://www.mapbox.com/mapbox-gl-style-spec/#sources) from the Mapbox Style |
26 | * Specification. |
27 | * |
28 | * `Source` is an abstract base class; concrete derived classes are provided for each source type. `Source` contains |
29 | * functionality that is common to all layer types: |
30 | * |
31 | * * Runtime type information: type predicates and casting |
32 | * * Accessors for properties common to all source types: ID, etc. |
33 | * * Cloning and copying |
34 | * |
35 | * All other functionality lives in the derived classes. To instantiate a source, create an instance of the desired |
36 | * type, passing the ID: |
37 | * |
38 | * auto vectorSource = std::make_unique<VectorSource>("my-vector-source"); |
39 | */ |
40 | class Source : public mbgl::util::noncopyable { |
41 | public: |
42 | virtual ~Source(); |
43 | |
44 | // Check whether this source is of the given subtype. |
45 | template <class T> |
46 | bool is() const; |
47 | |
48 | // Dynamically cast this source to the given subtype. |
49 | template <class T> |
50 | T* as() { |
51 | return is<T>() ? reinterpret_cast<T*>(this) : nullptr; |
52 | } |
53 | |
54 | template <class T> |
55 | const T* as() const { |
56 | return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; |
57 | } |
58 | |
59 | SourceType getType() const; |
60 | std::string getID() const; |
61 | optional<std::string> getAttribution() const; |
62 | |
63 | // Private implementation |
64 | class Impl; |
65 | Immutable<Impl> baseImpl; |
66 | |
67 | Source(Immutable<Impl>); |
68 | |
69 | void setObserver(SourceObserver*); |
70 | SourceObserver* observer = nullptr; |
71 | |
72 | virtual void loadDescription(FileSource&) = 0; |
73 | void dumpDebugLogs() const; |
74 | |
75 | bool loaded = false; |
76 | |
77 | // For use in SDK bindings, which store a reference to a platform-native peer |
78 | // object here, so that separately-obtained references to this object share |
79 | // identical platform-native peers. |
80 | util::unique_any peer; |
81 | }; |
82 | |
83 | } // namespace style |
84 | } // namespace mbgl |
85 | |