Skip to content

Commit

Permalink
Add const layer visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Nov 30, 2023
1 parent fefd7cc commit 9309682
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 2 deletions.
2 changes: 2 additions & 0 deletions modules/core/inc/tactile/core/map/layer/group_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TACTILE_CORE_API GroupLayer final : public ILayer {

void accept(ILayerVisitor& visitor) override;

void accept(IConstLayerVisitor& visitor) const override;

void set_persistent_id(Maybe<int32> id) override;

void set_opacity(float opacity) override;
Expand Down
9 changes: 8 additions & 1 deletion modules/core/inc/tactile/core/map/layer/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace tactile {

class ILayerVisitor;
class IConstLayerVisitor;

/**
* \interface ILayer
Expand All @@ -29,6 +30,11 @@ class TACTILE_CORE_API ILayer : public IMetaContext {
*/
virtual void accept(ILayerVisitor& visitor) = 0;

/**
* \copydoc accept(ILayerVisitor&)
*/
virtual void accept(IConstLayerVisitor& visitor) const = 0;

/**
* \brief Sets the associated identifier used in save files.
*
Expand Down Expand Up @@ -78,7 +84,8 @@ class TACTILE_CORE_API ILayer : public IMetaContext {
* \brief Creates a clone of the layer.
*
* \note The layer clone may not be identical to the source layer, the only guarantee
* is that the layer clone is logically equivalent.
* is that the layer clone is logically equivalent. For example, associated
* identifiers are not cloned.
*
* \return the new layer.
*/
Expand Down
29 changes: 29 additions & 0 deletions modules/core/inc/tactile/core/map/layer/layer_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,33 @@ class TACTILE_CORE_API ILayerVisitor {
{}
};

/**
* \brief Visitor type used to inspect const layers.
*/
class TACTILE_CORE_API IConstLayerVisitor {
public:
TACTILE_INTERFACE_CLASS(IConstLayerVisitor);

/**
* \brief Visits a tile layer.
*
* \param layer the visited layer.
*/
virtual void visit([[maybe_unused]] const TileLayer& layer) {}

/**
* \brief Visits an object layer.
*
* \param layer the visited layer.
*/
virtual void visit([[maybe_unused]] const ObjectLayer& layer) {}

/**
* \brief Visits a group layer.
*
* \param layer the visited layer.
*/
virtual void visit([[maybe_unused]] const GroupLayer& layer) {}
};

} // namespace tactile
4 changes: 3 additions & 1 deletion modules/core/inc/tactile/core/map/layer/object_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class TACTILE_CORE_API ObjectLayer final : public ILayer {

void accept(ILayerVisitor& visitor) override;

void accept(IConstLayerVisitor& visitor) const override;

/**
* \brief Adds an object to the layer.
*
* \note An existing object in the layer with the specified ID will be overwritten.
*
* \param id the ID to associate with the object.
* \param id the ID of the object.
* \param object the object to add.
*/
void add_object(ObjectID id, Shared<Object> object);
Expand Down
2 changes: 2 additions & 0 deletions modules/core/inc/tactile/core/map/layer/tile_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class TACTILE_CORE_API TileLayer final : public ILayer {

void accept(ILayerVisitor& visitor) override;

void accept(IConstLayerVisitor& visitor) const override;

/**
* \brief Changes the size of the layer.
*
Expand Down
5 changes: 5 additions & 0 deletions modules/core/src/tactile/core/map/layer/group_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ void GroupLayer::accept(ILayerVisitor& visitor)
visitor.visit(*this);
}

void GroupLayer::accept(IConstLayerVisitor& visitor) const
{
visitor.visit(*this);
}

void GroupLayer::set_persistent_id(const Maybe<int32> id)
{
mDelegate.set_persistent_id(id);
Expand Down
5 changes: 5 additions & 0 deletions modules/core/src/tactile/core/map/layer/object_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ void ObjectLayer::accept(ILayerVisitor& visitor)
visitor.visit(*this);
}

void ObjectLayer::accept(IConstLayerVisitor& visitor) const
{
visitor.visit(*this);
}

void ObjectLayer::add_object(const ObjectID id, Shared<Object> object)
{
mObjects[id] = std::move(object);
Expand Down
5 changes: 5 additions & 0 deletions modules/core/src/tactile/core/map/layer/tile_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ void TileLayer::accept(ILayerVisitor& visitor)
visitor.visit(*this);
}

void TileLayer::accept(IConstLayerVisitor& visitor) const
{
visitor.visit(*this);
}

void TileLayer::resize(const usize row_count, const usize col_count)
{
if (row_count < 1) {
Expand Down

0 comments on commit 9309682

Please sign in to comment.