From 4a80d1d594cd9211f8a2dca8b694dd43619c0fc98f28a258ed03315067053095 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 6 Aug 2025 03:31:51 -0400 Subject: [PATCH] STL-list for another Java list case. --- dw/image.cc | 18 ++++++------------ dw/image.hh | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/dw/image.cc b/dw/image.cc index d365ded..1fcdbb3 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -33,41 +33,35 @@ using namespace lout; ImageMapsList::ImageMap::ImageMap () { - shapesAndLinks = new container::typed::List (true); defaultLink = -1; } ImageMapsList::ImageMap::~ImageMap () { - delete shapesAndLinks; } void ImageMapsList::ImageMap::draw (core::View *view,core::style::Style *style, int x, int y) { - container::typed::Iterator it; - - for (it = shapesAndLinks->iterator (); it.hasNext (); ) { - ShapeAndLink *shapeAndLink = it.getNext (); - + for( auto &shapeAndLink: shapesAndLinks ) + { shapeAndLink->shape->draw(view, style, x, y); } } void ImageMapsList::ImageMap::add (core::Shape *shape, int link) { - ShapeAndLink *shapeAndLink = new ShapeAndLink (); + auto shapeAndLink = std::make_unique< ShapeAndLink >(); shapeAndLink->shape = shape; shapeAndLink->link = link; - shapesAndLinks->append (shapeAndLink); + shapesAndLinks.push_back( std::move( shapeAndLink ) ); } int ImageMapsList::ImageMap::link (int x, int y) { container::typed::Iterator it; int link = defaultLink; - for (it = shapesAndLinks->iterator (); it.hasNext (); ) { - ShapeAndLink *shapeAndLink = it.getNext (); - + for ( auto &shapeAndLink: shapesAndLinks ) + { if (shapeAndLink->shape->isPointWithin (x, y)) { link = shapeAndLink->link; break; diff --git a/dw/image.hh b/dw/image.hh index 2d4868f..d85918d 100644 --- a/dw/image.hh +++ b/dw/image.hh @@ -33,7 +33,7 @@ private: ~ShapeAndLink () { if (shape) delete shape; }; }; - lout::container::typed::List *shapesAndLinks; + std::list< std::unique_ptr< ShapeAndLink > > shapesAndLinks; int defaultLink; public: ImageMap ();