Retire the Java-like List class.

This commit is contained in:
2026-05-05 17:15:56 -04:00
parent 91b559e8a6
commit dc5b173788
5 changed files with 22 additions and 180 deletions
+13 -20
View File
@@ -152,9 +152,7 @@ void FltkImgbuf::init (Type type, int width, int height, double gamma,
// The list is only used for root buffers.
if (isRoot())
scaledBuffers = new lout::container::typed::List <FltkImgbuf> (true);
else
scaledBuffers = NULL;
scaledBuffers.emplace();
if (!isRoot()) {
// Scaling
@@ -172,12 +170,11 @@ FltkImgbuf::~FltkImgbuf ()
if (!isRoot())
root->detachScaledBuf (this);
else for( auto &sb: scaledBuffers.value() ) delete sb; // FIXME: Manual management
delete[] rawdata;
delete copiedRows;
if (scaledBuffers)
delete scaledBuffers;
DBG_OBJ_DELETE ();
}
@@ -188,12 +185,12 @@ FltkImgbuf::~FltkImgbuf ()
*/
void FltkImgbuf::detachScaledBuf (FltkImgbuf *scaledBuf)
{
scaledBuffers->detachRef (scaledBuf);
scaledBuffers.value().remove( scaledBuf );
_MSG("FltkImgbuf[root %p]: scaled buffer %p is detached, %d left\n",
this, scaledBuf, scaledBuffers->size ());
this, scaledBuf, scaledBuffers.value().size());
if (refCount == 0 && scaledBuffers->isEmpty () && deleteOnUnref)
if (refCount == 0 && scaledBuffers.value().empty () && deleteOnUnref)
// If the root buffer is not used anymore, but this is the last scaled
// buffer.
// See also: FltkImgbuf::unref().
@@ -368,9 +365,7 @@ void FltkImgbuf::copyRow (int row, const core::byte *data)
memcpy(rawdata + row * width * bpp, data, width * bpp);
// Update all the scaled buffers of this root image.
for (Iterator <FltkImgbuf> it = scaledBuffers->iterator();
it.hasNext(); ) {
FltkImgbuf *sb = it.getNext ();
for( auto &sb: scaledBuffers.value() ) {
sb->scaleRow (row, data);
}
}
@@ -379,8 +374,7 @@ void FltkImgbuf::copyRow (int row, const core::byte *data)
void FltkImgbuf::newScan ()
{
if (isRoot()) {
for (Iterator<FltkImgbuf> it = scaledBuffers->iterator(); it.hasNext();){
FltkImgbuf *sb = it.getNext ();
for( auto &sb: scaledBuffers.value() ) {
sb->copiedRows->clear();
DBG_IF_RTFL {
@@ -412,8 +406,7 @@ core::Imgbuf* FltkImgbuf::getScaledBuf (int width, int height)
return this;
}
for (Iterator <FltkImgbuf> it = scaledBuffers->iterator(); it.hasNext(); ) {
FltkImgbuf *sb = it.getNext ();
for( auto &sb: scaledBuffers.value() ) {
if (sb->width == width && sb->height == height) {
sb->ref ();
return sb;
@@ -432,7 +425,7 @@ core::Imgbuf* FltkImgbuf::getScaledBuf (int width, int height)
// This size is not yet used, so a new buffer has to be created.
FltkImgbuf *sb = new FltkImgbuf (type, width, height, gamma, this);
scaledBuffers->append (sb);
scaledBuffers.value().push_back (sb);
DBG_OBJ_ASSOC_CHILD (sb);
return sb;
@@ -532,11 +525,11 @@ void FltkImgbuf::unref ()
if (isRoot ()) {
// Root buffer, it must be ensured that no scaled buffers are left.
// See also FltkImgbuf::detachScaledBuf().
if (scaledBuffers->isEmpty () && deleteOnUnref) {
if (scaledBuffers.value().empty () && deleteOnUnref) {
delete this;
} else {
_MSG("FltkImgbuf[root %p]: not deleted. numScaled=%d\n",
this, scaledBuffers->size ());
this, scaledBuffers.value().size ());
}
} else
// Scaled buffer buffer, simply delete it.
@@ -547,7 +540,7 @@ void FltkImgbuf::unref ()
bool FltkImgbuf::lastReference ()
{
return refCount == 1 &&
(scaledBuffers == NULL || scaledBuffers->isEmpty ());
( scaledBuffers.has_value() == false || scaledBuffers.value().empty() );
}
void FltkImgbuf::setDeleteOnUnref (bool deleteOnUnref)
@@ -559,7 +552,7 @@ void FltkImgbuf::setDeleteOnUnref (bool deleteOnUnref)
bool FltkImgbuf::isReferred ()
{
return refCount != 0 ||
(scaledBuffers != NULL && !scaledBuffers->isEmpty ());
(scaledBuffers.has_value() and not scaledBuffers.value().empty());
}
+4 -1
View File
@@ -1,6 +1,9 @@
#ifndef __DW_FLTKIMGBUF_HH__
#define __DW_FLTKIMGBUF_HH__
#include <optional>
#include <list>
#ifndef __INCLUDED_FROM_DW_FLTK_CORE_HH__
# error Do not include this file directly, use "fltkcore.hh" instead.
#endif
@@ -21,7 +24,7 @@ private:
FltkImgbuf *root;
int refCount;
bool deleteOnUnref;
lout::container::typed::List <FltkImgbuf> *scaledBuffers;
std::optional< std::list< FltkImgbuf * > > scaledBuffers;
int width, height;
Type type;
+4 -10
View File
@@ -449,7 +449,6 @@ FltkPlatform::FltkPlatform ()
idleFuncId = 0;
view = NULL;
resources = new container::typed::List <ui::FltkResource> (false);
resourceFactory.setPlatform (this);
}
@@ -458,7 +457,6 @@ FltkPlatform::~FltkPlatform ()
{
if (idleFuncRunning)
Fl::remove_idle (generalStaticIdle, (void*)this);
delete resources;
DBG_OBJ_DELETE ();
}
@@ -476,9 +474,7 @@ void FltkPlatform::attachView (core::View *view)
MSG_ERR("FltkPlatform::attachView: multiple views!\n");
this->view = (FltkView*)view;
for (container::typed::Iterator <ui::FltkResource> it =
resources->iterator (); it.hasNext (); ) {
ui::FltkResource *resource = it.getNext ();
for( auto &resource: resources ) {
resource->attachView (this->view);
}
}
@@ -490,9 +486,7 @@ void FltkPlatform::detachView (core::View *view)
MSG_ERR("FltkPlatform::detachView: this->view: %p view: %p\n",
(void *) this->view, (void *) view);
for (container::typed::Iterator <ui::FltkResource> it =
resources->iterator (); it.hasNext (); ) {
ui::FltkResource *resource = it.getNext ();
for( auto &resource: resources ) {
resource->detachView ((FltkView*)view);
}
this->view = NULL;
@@ -699,13 +693,13 @@ core::ui::ResourceFactory *FltkPlatform::getResourceFactory ()
void FltkPlatform::attachResource (ui::FltkResource *resource)
{
resources->append (resource);
resources.push_back( resource );
resource->attachView (view);
}
void FltkPlatform::detachResource (ui::FltkResource *resource)
{
resources->removeRef (resource);
resources.remove( resource );
}
} // namespace fltk
+1 -1
View File
@@ -140,7 +140,7 @@ private:
void generalIdle();
FltkView *view;
lout::container::typed::List <ui::FltkResource> *resources;
std::list <ui::FltkResource *> resources;
public:
FltkPlatform ();