Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Replace if/else with evaluator template  #8758

Closed

Description

@tobrun

Follow up from #8709 (comment), we should cleanup the Android binding code to avoid if-else checking:

        std::string sourceLayerId;
        if (layer.is<FillLayer>()) {
            sourceLayerId = layer.as<FillLayer>()->getSourceLayer();
        } else if (layer.is<LineLayer>()) {
            sourceLayerId = layer.as<LineLayer>()->getSourceLayer();
        } else if (layer.is<SymbolLayer>()) {
            sourceLayerId = layer.as<SymbolLayer>()->getSourceLayer();
        } else if (layer.is<CircleLayer>()) {
            sourceLayerId = layer.as<CircleLayer>()->getSourceLayer();
        } else {
            mbgl::Log::Warning(mbgl::Event::JNI, "Layer doesn't support source layer");
        }

This can be replaced with the following template:

struct Evaluator {
    std::string operator()(mbgl::style::BackgroundLayer&) { return {}; }
    std::string operator()(mbgl::style::RasterLayer&) { return {}; }
    std::string operator()(mbgl::style::CustomLayer&) { return {}; }

    template <class VectorLayer>
    std::string operator()(VectorLayer& layer) {
        return layer.getSourceLayer();
    }
};
// ...
std::string sourceLayerId = layer.accept(Evaluator());

cc @ivovandongen

Activity

  1. added
    Android
    on Apr 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidrefactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions