diff options
Diffstat (limited to 'src/mbgl/sprite/sprite_image_collection.cpp')
-rw-r--r-- | src/mbgl/sprite/sprite_image_collection.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/mbgl/sprite/sprite_image_collection.cpp b/src/mbgl/sprite/sprite_image_collection.cpp new file mode 100644 index 0000000000..787ba83db2 --- /dev/null +++ b/src/mbgl/sprite/sprite_image_collection.cpp @@ -0,0 +1,40 @@ +#include <mbgl/sprite/sprite_image_collection.hpp> +#include <mbgl/util/logging.hpp> + +namespace mbgl { + +void addSpriteImage(Images& images, const std::string& id, + std::unique_ptr<style::Image> image_, + std::function<void (style::Image&)> onAdded) { + + auto it = images.find(id); + if (it == images.end()) { + // Add new + it = images.emplace(id, std::move(image_)).first; + onAdded(*it->second.get()); + return; + } + + std::unique_ptr<style::Image>& image = it->second; + + // There is already a sprite with that name in our store. + if (image->getImage().size != image_->getImage().size) { + Log::Warning(Event::Sprite, "Can't change sprite dimensions for '%s'", id.c_str()); + } + + // Update existing + image = std::move(image_); + onAdded(*it->second.get()); +} + +void removeSpriteImage(Images& images, + const std::string& id, + std::function<void ()> onRemoved) { + if (images.erase(id) > 0) { + onRemoved(); + } +} + + + +} // namespace mbgl |