[core][android] Introduce mbgl::style::LayerTypeInfo

The `LayerTypeInfo` contains static meta data about certain layer type.

Each layer module should have a single immutable `LayerTypeInfo` instance
for the represented layer type. Both `LayerImpl` and `LayerFactory` from the
module always refer to the same `LayerTypeInfo` instance, so address of this
instance can be used as a layer module Id during the process life time.
This commit is contained in:
Mikhail Pozdnyakov
2018-11-15 15:47:25 +02:00
parent 73dcfe2d0d
commit 33818233cf
49 changed files with 256 additions and 323 deletions

View File

@@ -18,6 +18,21 @@ namespace style {
class LayerObserver;
class Filter;
/**
* @brief Holds static data for a certain layer type.
*/
struct LayerTypeInfo {
/**
* @brief contains the layer type as defined in the style specification;
*/
const char* type;
/**
* @brief contains \c SourceRequired if the corresponding layer type requires source;
* contains \c SourceNotRequired otherwise.
*/
const enum { SourceRequired, SourceNotRequired } source;
};
/**
* The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style
* Specification.
@@ -83,12 +98,16 @@ public:
// identical platform-native peers.
util::peer peer;
Layer(Immutable<Impl>);
const LayerTypeInfo* getTypeInfo() const noexcept;
protected:
virtual Mutable<Impl> mutableBaseImpl() const = 0;
LayerObserver* observer;
};
/**
* @brief The LayerFactory abstract class
*
@@ -97,8 +116,8 @@ protected:
class LayerFactory {
public:
virtual ~LayerFactory() = default;
/// Returns \c true if this factory can produce layers of the given type of the layers; returns \c false otherwise.
virtual bool supportsType(const std::string& type) const noexcept = 0;
/// Returns the layer type data.
virtual const LayerTypeInfo* getTypeInfo() const noexcept = 0;
/// Returns a new Layer instance on success call; returns `nulltptr` otherwise.
virtual std::unique_ptr<Layer> createLayer(const std::string& id, const conversion::Convertible& value) = 0;

View File

@@ -59,15 +59,11 @@ protected:
class BackgroundLayerFactory : public LayerFactory {
public:
BackgroundLayerFactory();
// LayerFactory overrides.
~BackgroundLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static BackgroundLayerFactory* get() noexcept;
private:
static BackgroundLayerFactory* instance;
};
} // namespace style

View File

@@ -107,15 +107,11 @@ protected:
class CircleLayerFactory : public LayerFactory {
public:
CircleLayerFactory();
// LayerFactory overrides.
~CircleLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static CircleLayerFactory* get() noexcept;
private:
static CircleLayerFactory* instance;
};
} // namespace style

View File

@@ -90,13 +90,9 @@ public:
CustomLayerFactory();
// LayerFactory overrides.
~CustomLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static CustomLayerFactory* get() noexcept;
private:
static CustomLayerFactory* instance;
};
} // namespace style

View File

@@ -83,15 +83,11 @@ protected:
class FillExtrusionLayerFactory : public LayerFactory {
public:
FillExtrusionLayerFactory();
// LayerFactory overrides.
~FillExtrusionLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static FillExtrusionLayerFactory* get() noexcept;
private:
static FillExtrusionLayerFactory* instance;
};
} // namespace style

View File

@@ -83,15 +83,11 @@ protected:
class FillLayerFactory : public LayerFactory {
public:
FillLayerFactory();
// LayerFactory overrides.
~FillLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static FillLayerFactory* get() noexcept;
private:
static FillLayerFactory* instance;
};
} // namespace style

View File

@@ -72,15 +72,11 @@ protected:
class HeatmapLayerFactory : public LayerFactory {
public:
HeatmapLayerFactory();
// LayerFactory overrides.
~HeatmapLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static HeatmapLayerFactory* get() noexcept;
private:
static HeatmapLayerFactory* instance;
};
} // namespace style

View File

@@ -77,15 +77,11 @@ protected:
class HillshadeLayerFactory : public LayerFactory {
public:
HillshadeLayerFactory();
// LayerFactory overrides.
~HillshadeLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static HillshadeLayerFactory* get() noexcept;
private:
static HillshadeLayerFactory* instance;
};
} // namespace style

View File

@@ -75,15 +75,11 @@ protected:
class <%- camelize(type) %>LayerFactory : public LayerFactory {
public:
<%- camelize(type) %>LayerFactory();
// LayerFactory overrides.
~<%- camelize(type) %>LayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static <%- camelize(type) %>LayerFactory* get() noexcept;
private:
static <%- camelize(type) %>LayerFactory* instance;
};
} // namespace style

View File

@@ -128,15 +128,11 @@ protected:
class LineLayerFactory : public LayerFactory {
public:
LineLayerFactory();
// LayerFactory overrides.
~LineLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static LineLayerFactory* get() noexcept;
private:
static LineLayerFactory* instance;
};
} // namespace style

View File

@@ -89,15 +89,11 @@ protected:
class RasterLayerFactory : public LayerFactory {
public:
RasterLayerFactory();
// LayerFactory overrides.
~RasterLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static RasterLayerFactory* get() noexcept;
private:
static RasterLayerFactory* instance;
};
} // namespace style

View File

@@ -277,15 +277,11 @@ protected:
class SymbolLayerFactory : public LayerFactory {
public:
SymbolLayerFactory();
// LayerFactory overrides.
~SymbolLayerFactory() override;
bool supportsType(const std::string& type) const noexcept final;
// LayerFactory overrides.
const LayerTypeInfo* getTypeInfo() const noexcept final;
std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final;
static SymbolLayerFactory* get() noexcept;
private:
static SymbolLayerFactory* instance;
};
} // namespace style