Retire the Java-like List class.
This commit is contained in:
+13
-20
@@ -152,9 +152,7 @@ void FltkImgbuf::init (Type type, int width, int height, double gamma,
|
|||||||
|
|
||||||
// The list is only used for root buffers.
|
// The list is only used for root buffers.
|
||||||
if (isRoot())
|
if (isRoot())
|
||||||
scaledBuffers = new lout::container::typed::List <FltkImgbuf> (true);
|
scaledBuffers.emplace();
|
||||||
else
|
|
||||||
scaledBuffers = NULL;
|
|
||||||
|
|
||||||
if (!isRoot()) {
|
if (!isRoot()) {
|
||||||
// Scaling
|
// Scaling
|
||||||
@@ -172,12 +170,11 @@ FltkImgbuf::~FltkImgbuf ()
|
|||||||
|
|
||||||
if (!isRoot())
|
if (!isRoot())
|
||||||
root->detachScaledBuf (this);
|
root->detachScaledBuf (this);
|
||||||
|
else for( auto &sb: scaledBuffers.value() ) delete sb; // FIXME: Manual management
|
||||||
|
|
||||||
delete[] rawdata;
|
delete[] rawdata;
|
||||||
delete copiedRows;
|
delete copiedRows;
|
||||||
|
|
||||||
if (scaledBuffers)
|
|
||||||
delete scaledBuffers;
|
|
||||||
|
|
||||||
DBG_OBJ_DELETE ();
|
DBG_OBJ_DELETE ();
|
||||||
}
|
}
|
||||||
@@ -188,12 +185,12 @@ FltkImgbuf::~FltkImgbuf ()
|
|||||||
*/
|
*/
|
||||||
void FltkImgbuf::detachScaledBuf (FltkImgbuf *scaledBuf)
|
void FltkImgbuf::detachScaledBuf (FltkImgbuf *scaledBuf)
|
||||||
{
|
{
|
||||||
scaledBuffers->detachRef (scaledBuf);
|
scaledBuffers.value().remove( scaledBuf );
|
||||||
|
|
||||||
_MSG("FltkImgbuf[root %p]: scaled buffer %p is detached, %d left\n",
|
_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
|
// If the root buffer is not used anymore, but this is the last scaled
|
||||||
// buffer.
|
// buffer.
|
||||||
// See also: FltkImgbuf::unref().
|
// 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);
|
memcpy(rawdata + row * width * bpp, data, width * bpp);
|
||||||
|
|
||||||
// Update all the scaled buffers of this root image.
|
// Update all the scaled buffers of this root image.
|
||||||
for (Iterator <FltkImgbuf> it = scaledBuffers->iterator();
|
for( auto &sb: scaledBuffers.value() ) {
|
||||||
it.hasNext(); ) {
|
|
||||||
FltkImgbuf *sb = it.getNext ();
|
|
||||||
sb->scaleRow (row, data);
|
sb->scaleRow (row, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,8 +374,7 @@ void FltkImgbuf::copyRow (int row, const core::byte *data)
|
|||||||
void FltkImgbuf::newScan ()
|
void FltkImgbuf::newScan ()
|
||||||
{
|
{
|
||||||
if (isRoot()) {
|
if (isRoot()) {
|
||||||
for (Iterator<FltkImgbuf> it = scaledBuffers->iterator(); it.hasNext();){
|
for( auto &sb: scaledBuffers.value() ) {
|
||||||
FltkImgbuf *sb = it.getNext ();
|
|
||||||
sb->copiedRows->clear();
|
sb->copiedRows->clear();
|
||||||
|
|
||||||
DBG_IF_RTFL {
|
DBG_IF_RTFL {
|
||||||
@@ -412,8 +406,7 @@ core::Imgbuf* FltkImgbuf::getScaledBuf (int width, int height)
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator <FltkImgbuf> it = scaledBuffers->iterator(); it.hasNext(); ) {
|
for( auto &sb: scaledBuffers.value() ) {
|
||||||
FltkImgbuf *sb = it.getNext ();
|
|
||||||
if (sb->width == width && sb->height == height) {
|
if (sb->width == width && sb->height == height) {
|
||||||
sb->ref ();
|
sb->ref ();
|
||||||
return sb;
|
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.
|
// This size is not yet used, so a new buffer has to be created.
|
||||||
FltkImgbuf *sb = new FltkImgbuf (type, width, height, gamma, this);
|
FltkImgbuf *sb = new FltkImgbuf (type, width, height, gamma, this);
|
||||||
scaledBuffers->append (sb);
|
scaledBuffers.value().push_back (sb);
|
||||||
DBG_OBJ_ASSOC_CHILD (sb);
|
DBG_OBJ_ASSOC_CHILD (sb);
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
@@ -532,11 +525,11 @@ void FltkImgbuf::unref ()
|
|||||||
if (isRoot ()) {
|
if (isRoot ()) {
|
||||||
// Root buffer, it must be ensured that no scaled buffers are left.
|
// Root buffer, it must be ensured that no scaled buffers are left.
|
||||||
// See also FltkImgbuf::detachScaledBuf().
|
// See also FltkImgbuf::detachScaledBuf().
|
||||||
if (scaledBuffers->isEmpty () && deleteOnUnref) {
|
if (scaledBuffers.value().empty () && deleteOnUnref) {
|
||||||
delete this;
|
delete this;
|
||||||
} else {
|
} else {
|
||||||
_MSG("FltkImgbuf[root %p]: not deleted. numScaled=%d\n",
|
_MSG("FltkImgbuf[root %p]: not deleted. numScaled=%d\n",
|
||||||
this, scaledBuffers->size ());
|
this, scaledBuffers.value().size ());
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
// Scaled buffer buffer, simply delete it.
|
// Scaled buffer buffer, simply delete it.
|
||||||
@@ -547,7 +540,7 @@ void FltkImgbuf::unref ()
|
|||||||
bool FltkImgbuf::lastReference ()
|
bool FltkImgbuf::lastReference ()
|
||||||
{
|
{
|
||||||
return refCount == 1 &&
|
return refCount == 1 &&
|
||||||
(scaledBuffers == NULL || scaledBuffers->isEmpty ());
|
( scaledBuffers.has_value() == false || scaledBuffers.value().empty() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FltkImgbuf::setDeleteOnUnref (bool deleteOnUnref)
|
void FltkImgbuf::setDeleteOnUnref (bool deleteOnUnref)
|
||||||
@@ -559,7 +552,7 @@ void FltkImgbuf::setDeleteOnUnref (bool deleteOnUnref)
|
|||||||
bool FltkImgbuf::isReferred ()
|
bool FltkImgbuf::isReferred ()
|
||||||
{
|
{
|
||||||
return refCount != 0 ||
|
return refCount != 0 ||
|
||||||
(scaledBuffers != NULL && !scaledBuffers->isEmpty ());
|
(scaledBuffers.has_value() and not scaledBuffers.value().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,9 @@
|
|||||||
#ifndef __DW_FLTKIMGBUF_HH__
|
#ifndef __DW_FLTKIMGBUF_HH__
|
||||||
#define __DW_FLTKIMGBUF_HH__
|
#define __DW_FLTKIMGBUF_HH__
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#ifndef __INCLUDED_FROM_DW_FLTK_CORE_HH__
|
#ifndef __INCLUDED_FROM_DW_FLTK_CORE_HH__
|
||||||
# error Do not include this file directly, use "fltkcore.hh" instead.
|
# error Do not include this file directly, use "fltkcore.hh" instead.
|
||||||
#endif
|
#endif
|
||||||
@@ -21,7 +24,7 @@ private:
|
|||||||
FltkImgbuf *root;
|
FltkImgbuf *root;
|
||||||
int refCount;
|
int refCount;
|
||||||
bool deleteOnUnref;
|
bool deleteOnUnref;
|
||||||
lout::container::typed::List <FltkImgbuf> *scaledBuffers;
|
std::optional< std::list< FltkImgbuf * > > scaledBuffers;
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
Type type;
|
Type type;
|
||||||
|
|||||||
+4
-10
@@ -449,7 +449,6 @@ FltkPlatform::FltkPlatform ()
|
|||||||
idleFuncId = 0;
|
idleFuncId = 0;
|
||||||
|
|
||||||
view = NULL;
|
view = NULL;
|
||||||
resources = new container::typed::List <ui::FltkResource> (false);
|
|
||||||
|
|
||||||
resourceFactory.setPlatform (this);
|
resourceFactory.setPlatform (this);
|
||||||
}
|
}
|
||||||
@@ -458,7 +457,6 @@ FltkPlatform::~FltkPlatform ()
|
|||||||
{
|
{
|
||||||
if (idleFuncRunning)
|
if (idleFuncRunning)
|
||||||
Fl::remove_idle (generalStaticIdle, (void*)this);
|
Fl::remove_idle (generalStaticIdle, (void*)this);
|
||||||
delete resources;
|
|
||||||
|
|
||||||
DBG_OBJ_DELETE ();
|
DBG_OBJ_DELETE ();
|
||||||
}
|
}
|
||||||
@@ -476,9 +474,7 @@ void FltkPlatform::attachView (core::View *view)
|
|||||||
MSG_ERR("FltkPlatform::attachView: multiple views!\n");
|
MSG_ERR("FltkPlatform::attachView: multiple views!\n");
|
||||||
this->view = (FltkView*)view;
|
this->view = (FltkView*)view;
|
||||||
|
|
||||||
for (container::typed::Iterator <ui::FltkResource> it =
|
for( auto &resource: resources ) {
|
||||||
resources->iterator (); it.hasNext (); ) {
|
|
||||||
ui::FltkResource *resource = it.getNext ();
|
|
||||||
resource->attachView (this->view);
|
resource->attachView (this->view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,9 +486,7 @@ void FltkPlatform::detachView (core::View *view)
|
|||||||
MSG_ERR("FltkPlatform::detachView: this->view: %p view: %p\n",
|
MSG_ERR("FltkPlatform::detachView: this->view: %p view: %p\n",
|
||||||
(void *) this->view, (void *) view);
|
(void *) this->view, (void *) view);
|
||||||
|
|
||||||
for (container::typed::Iterator <ui::FltkResource> it =
|
for( auto &resource: resources ) {
|
||||||
resources->iterator (); it.hasNext (); ) {
|
|
||||||
ui::FltkResource *resource = it.getNext ();
|
|
||||||
resource->detachView ((FltkView*)view);
|
resource->detachView ((FltkView*)view);
|
||||||
}
|
}
|
||||||
this->view = NULL;
|
this->view = NULL;
|
||||||
@@ -699,13 +693,13 @@ core::ui::ResourceFactory *FltkPlatform::getResourceFactory ()
|
|||||||
|
|
||||||
void FltkPlatform::attachResource (ui::FltkResource *resource)
|
void FltkPlatform::attachResource (ui::FltkResource *resource)
|
||||||
{
|
{
|
||||||
resources->append (resource);
|
resources.push_back( resource );
|
||||||
resource->attachView (view);
|
resource->attachView (view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FltkPlatform::detachResource (ui::FltkResource *resource)
|
void FltkPlatform::detachResource (ui::FltkResource *resource)
|
||||||
{
|
{
|
||||||
resources->removeRef (resource);
|
resources.remove( resource );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace fltk
|
} // namespace fltk
|
||||||
|
|||||||
+1
-1
@@ -140,7 +140,7 @@ private:
|
|||||||
void generalIdle();
|
void generalIdle();
|
||||||
|
|
||||||
FltkView *view;
|
FltkView *view;
|
||||||
lout::container::typed::List <ui::FltkResource> *resources;
|
std::list <ui::FltkResource *> resources;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FltkPlatform ();
|
FltkPlatform ();
|
||||||
|
|||||||
@@ -292,154 +292,6 @@ Collection0::AbstractIterator* Vector::createIterator()
|
|||||||
return new VectorIterator(this);
|
return new VectorIterator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------
|
|
||||||
// List
|
|
||||||
// ------------
|
|
||||||
|
|
||||||
List::List(bool ownerOfObjects)
|
|
||||||
{
|
|
||||||
this->ownerOfObjects = ownerOfObjects;
|
|
||||||
first = last = NULL;
|
|
||||||
numElements = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
List::~List()
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
int List::size ()
|
|
||||||
{
|
|
||||||
return numElements;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool List::equals(const Object *other) const
|
|
||||||
{
|
|
||||||
List *otherList = (List*)other;
|
|
||||||
Node *node1 = first, *node2 = otherList->first;
|
|
||||||
while (node1 != NULL && node2 != NULL ) {
|
|
||||||
if (!node1->object->equals (node2->object))
|
|
||||||
return false;
|
|
||||||
node1 = node1->next;
|
|
||||||
node2 = node2->next;
|
|
||||||
}
|
|
||||||
return node1 == NULL && node2 == NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int List::hashValue()
|
|
||||||
{
|
|
||||||
int h = 0;
|
|
||||||
for (Node *node = first; node; node = node->next)
|
|
||||||
h = h ^ node->object->hashValue ();
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void List::clear()
|
|
||||||
{
|
|
||||||
while (first) {
|
|
||||||
if (ownerOfObjects && first->object)
|
|
||||||
delete first->object;
|
|
||||||
Node *next = first->next;
|
|
||||||
delete first;
|
|
||||||
first = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
last = NULL;
|
|
||||||
numElements = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void List::append(Object *element)
|
|
||||||
{
|
|
||||||
Node *newLast = new Node;
|
|
||||||
newLast->next = NULL;
|
|
||||||
newLast->object = element;
|
|
||||||
|
|
||||||
if (last) {
|
|
||||||
last->next = newLast;
|
|
||||||
last = newLast;
|
|
||||||
} else
|
|
||||||
first = last = newLast;
|
|
||||||
|
|
||||||
numElements++;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool List::insertBefore(object::Object *beforeThis, object::Object *neew)
|
|
||||||
{
|
|
||||||
Node *beforeCur, *cur;
|
|
||||||
|
|
||||||
for (beforeCur = NULL, cur = first; cur; beforeCur = cur, cur = cur->next) {
|
|
||||||
if (cur->object == beforeThis) {
|
|
||||||
Node *newNode = new Node;
|
|
||||||
newNode->next = cur;
|
|
||||||
newNode->object = neew;
|
|
||||||
|
|
||||||
if (beforeCur)
|
|
||||||
beforeCur->next = newNode;
|
|
||||||
else
|
|
||||||
first = newNode;
|
|
||||||
|
|
||||||
numElements++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool List::remove0(Object *element, bool compare, bool doNotDeleteAtAll)
|
|
||||||
{
|
|
||||||
Node *beforeCur, *cur;
|
|
||||||
|
|
||||||
for (beforeCur = NULL, cur = first; cur; beforeCur = cur, cur = cur->next) {
|
|
||||||
if (compare ?
|
|
||||||
(cur->object && element->equals(cur->object)) :
|
|
||||||
element == cur->object) {
|
|
||||||
if (beforeCur) {
|
|
||||||
beforeCur->next = cur->next;
|
|
||||||
if (cur->next == NULL)
|
|
||||||
last = beforeCur;
|
|
||||||
} else {
|
|
||||||
first = cur->next;
|
|
||||||
if (first == NULL)
|
|
||||||
last = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ownerOfObjects && cur->object && !doNotDeleteAtAll)
|
|
||||||
delete cur->object;
|
|
||||||
delete cur;
|
|
||||||
|
|
||||||
numElements--;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object *List::ListIterator::getNext()
|
|
||||||
{
|
|
||||||
Object *object;
|
|
||||||
|
|
||||||
if (current) {
|
|
||||||
object = current->object;
|
|
||||||
current = current->next;
|
|
||||||
} else
|
|
||||||
object = NULL;
|
|
||||||
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool List::ListIterator::hasNext()
|
|
||||||
{
|
|
||||||
return current != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection0::AbstractIterator* List::createIterator()
|
|
||||||
{
|
|
||||||
return new ListIterator(first);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------
|
// ---------------
|
||||||
// HashSet
|
// HashSet
|
||||||
// ---------------
|
// ---------------
|
||||||
|
|||||||
Reference in New Issue
Block a user