diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-14 16:07:21 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-16 13:27:15 -0700 |
commit | 900568cfb0b84a298395f4d84488fd9323552c63 (patch) | |
tree | e2c315656ca57a07ba48e38df5743fb05debb115 /include/mbgl/style/source.hpp | |
parent | 19158d9f01909bf566616524f23e0acb635562f7 (diff) | |
download | qtlocation-mapboxgl-900568cfb0b84a298395f4d84488fd9323552c63.tar.gz |
[core] Runtime source API: private impls
Diffstat (limited to 'include/mbgl/style/source.hpp')
-rw-r--r-- | include/mbgl/style/source.hpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp new file mode 100644 index 0000000000..92341066b1 --- /dev/null +++ b/include/mbgl/style/source.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include <mbgl/util/noncopyable.hpp> +#include <mbgl/style/types.hpp> + +#include <memory> +#include <string> + +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<VectorSource>("my-vector-source"); + */ +class Source : public mbgl::util::noncopyable { +public: + virtual ~Source(); + + // Check whether this source is of the given subtype. + template <class T> + bool is() const; + + // Dynamically cast this source to the given subtype. + template <class T> + T* as() { + return is<T>() ? reinterpret_cast<T*>(this) : nullptr; + } + + template <class T> + const T* as() const { + return is<T>() ? reinterpret_cast<const T*>(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<Source> copy(const std::string& id) const; + + // Private implementation + class Impl; + const std::unique_ptr<Impl> baseImpl; + +protected: + const SourceType type; + Source(SourceType, std::unique_ptr<Impl>); +}; + +} // namespace style +} // namespace mbgl |