#pragma once #include #include #include #include namespace mbgl { namespace style { /** * The runtime representation of a [source](https://www.mapbox.com/mapbox-gl-style-spec/#sources) from the Mapbox Style * Specification. * * `Source` is an abstract base class; concrete derived classes are provided for each source type. `Source` contains * functionality that is common to all layer types: * * * Runtime type information: type predicates and casting * * Accessors for properties common to all source types: ID, etc. * * Cloning and copying * * All other functionality lives in the derived classes. To instantiate a source, create an instance of the desired * type, passing the ID: * * auto vectorSource = std::make_unique("my-vector-source"); */ class Source : public mbgl::util::noncopyable { public: virtual ~Source(); // Check whether this source is of the given subtype. template bool is() const; // Dynamically cast this source to the given subtype. template T* as() { return is() ? reinterpret_cast(this) : nullptr; } template const T* as() const { return is() ? reinterpret_cast(this) : nullptr; } const std::string& getID() const; // Create a new source with the specified `id`. All other properties // are copied from this source. std::unique_ptr copy(const std::string& id) const; // Private implementation class Impl; const std::unique_ptr baseImpl; protected: const SourceType type; Source(SourceType, std::unique_ptr); }; } // namespace style } // namespace mbgl