From cdc6210bfe53ca05eae93e48e52a1ffed3a9b610 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 4 Feb 2002 22:41:27 +0000 Subject: replaced LinkedList with stl container --- src/Image.cc | 92 +++++++++++++++++++++++++++------------------------------- src/Image.hh | 14 ++++----- src/Toolbar.cc | 18 ++++++++---- src/Toolbar.hh | 5 +--- 4 files changed, 62 insertions(+), 67 deletions(-) diff --git a/src/Image.cc b/src/Image.cc index 611d307..ec0768a 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -25,7 +25,7 @@ // stupid macros needed to access some functions in version 2 of the GNU C // library -// $Id: Image.cc,v 1.3 2002/01/09 14:11:20 fluxgen Exp $ +// $Id: Image.cc,v 1.4 2002/02/04 22:41:27 fluxgen Exp $ #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -2188,8 +2188,6 @@ BImageControl::BImageControl(BaseDisplay *dpy, ScreenInfo *scrn, Bool _dither, throw static_cast(1); //throw error code 1 } - - cache = new LinkedList; } @@ -2218,8 +2216,7 @@ BImageControl::~BImageControl(void) { delete [] colors; } - if (cache->count()) { - int i, n = cache->count(); + if (cache.size() > 0) { fprintf(stderr, I18n::instance()-> getMessage( @@ -2229,48 +2226,44 @@ BImageControl::~BImageControl(void) { 0, 0, #endif // NLS "BImageContol::~BImageControl: pixmap cache - " - "releasing %d pixmaps\n"), n); + "releasing %d pixmaps\n"), cache.size()); - for (i = 0; i < n; i++) { - Cache *tmp = cache->first(); - XFreePixmap(basedisplay->getXDisplay(), tmp->pixmap); - cache->remove(tmp); - delete tmp; + CacheList::iterator it = cache.begin(); + CacheList::iterator it_end = cache.end(); + for (; it != it_end; ++it) { + XFreePixmap(basedisplay->getXDisplay(), (*it)->pixmap); + delete (*it); } #ifdef TIMEDCACHE if (timer) { - timer->stop(); delete timer; } #endif // TIMEDCACHE } - - delete cache; } Pixmap BImageControl::searchCache(unsigned int width, unsigned int height, unsigned long texture, BColor *c1, BColor *c2) { - if (cache->count()) { - LinkedListIterator it(cache); - - for (; it.current(); it++) { - if ((it.current()->width == width) && - (it.current()->height == height) && - (it.current()->texture == texture) && - (it.current()->pixel1 == c1->getPixel())) - if (texture & BImage::GRADIENT) { - if (it.current()->pixel2 == c2->getPixel()) { - it.current()->count++; - return it.current()->pixmap; - } - } else { - it.current()->count++; - return it.current()->pixmap; - } - } + CacheList::iterator it = cache.begin(); + CacheList::iterator it_end = cache.end(); + for (; it != it_end; ++it) { + if (((*it)->width == width) && + ((*it)->height == height) && + ((*it)->texture == texture) && + ((*it)->pixel1 == c1->getPixel())) { + if (texture & BImage::GRADIENT) { + if ((*it)->pixel2 == c2->getPixel()) { + (*it)->count++; + return (*it)->pixmap; + } + } else { + (*it)->count++; + return (*it)->pixmap; + } + } } return None; @@ -2303,9 +2296,9 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, else tmp->pixel2 = 0l; - cache->insert(tmp); + cache.push_back(tmp); - if ((unsigned) cache->count() > cache_max) { + if ((unsigned) cache.size() > cache_max) { #ifdef DEBUG fprintf(stderr, I18n::instance()-> @@ -2331,22 +2324,21 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, void BImageControl::removeImage(Pixmap pixmap) { if (pixmap) { - LinkedListIterator it(cache); - for (; it.current(); it++) { - if (it.current()->pixmap == pixmap) { - Cache *tmp = it.current(); - - if (tmp->count) { - tmp->count--; + CacheList::iterator it = cache.begin(); + CacheList::iterator it_end = cache.end(); + for (; it != it_end; ++it) { + if ((*it)->pixmap == pixmap) { + if ((*it)->count) { + (*it)->count--; #ifdef TIMEDCACHE - if (! timer) timeout(); + if (! timer) timeout(); #else // !TIMEDCACHE - if (! tmp->count) timeout(); + if (! (*it)->count) timeout(); #endif // TIMEDCACHE - } + } - return; + return; } } } @@ -2586,14 +2578,16 @@ void BImageControl::parseColor(BColor *color, char *c) { void BImageControl::timeout(void) { - LinkedListIterator it(cache); - for (; it.current(); it++) { - Cache *tmp = it.current(); + CacheList::iterator it = cache.begin(); + CacheList::iterator it_end = cache.end(); + for (; it != it_end; ++it) { + Cache *tmp = (*it); if (tmp->count <= 0) { XFreePixmap(basedisplay->getXDisplay(), tmp->pixmap); - cache->remove(tmp); + it = cache.erase(it); delete tmp; + if (it == it_end) break; } } } diff --git a/src/Image.hh b/src/Image.hh index 672c632..7f7c746 100644 --- a/src/Image.hh +++ b/src/Image.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Image.hh,v 1.3 2002/01/09 14:11:20 fluxgen Exp $ +// $Id: Image.hh,v 1.4 2002/02/04 22:41:27 fluxgen Exp $ #ifndef _IMAGE_HH_ #define _IMAGE_HH_ @@ -31,13 +31,9 @@ #include #include "Timer.hh" - -#ifndef _BASEDISPLAY_HH_ #include "BaseDisplay.hh" -#endif -#ifndef _LINKEDLIST_HH_ -#include "LinkedList.hh" -#endif + +#include class BImage; class BImageControl; @@ -182,7 +178,9 @@ private: unsigned long pixel1, pixel2, texture; } Cache; - LinkedList *cache; + typedef std::list CacheList; + + CacheList cache; protected: diff --git a/src/Toolbar.cc b/src/Toolbar.cc index 29e3685..2415506 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -503,18 +503,24 @@ void Toolbar::reconfigure(void) { if (!iconbar) { iconbar = new IconBar(screen, frame.window_label); if (screen->getIconCount()) { - LinkedListIterator it(screen->getIconList()); - for(; it.current(); it++) - addIcon(it.current()); + BScreen::Icons & l = screen->getIconList(); + BScreen::Icons::iterator it = l.begin(); + BScreen::Icons::iterator it_end = l.end(); + for(; it != it_end; ++it) { + addIcon(*it); + } } } else iconbar->reconfigure(); } else { if (iconbar) { - LinkedListIterator it(screen->getIconList()); - for (; it.current(); it++) - delIcon(it.current()); + BScreen::Icons & l = screen->getIconList(); + BScreen::Icons::iterator it = l.begin(); + BScreen::Icons::iterator it_end = l.end(); + for(; it != it_end; ++it) { + delIcon(*it); + } delete iconbar; iconbar = 0; } diff --git a/src/Toolbar.hh b/src/Toolbar.hh index 9982b90..4872500 100644 --- a/src/Toolbar.hh +++ b/src/Toolbar.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Toolbar.hh,v 1.5 2002/01/21 00:54:38 fluxgen Exp $ +// $Id: Toolbar.hh,v 1.6 2002/02/04 22:38:41 fluxgen Exp $ #ifndef _TOOLBAR_HH_ #define _TOOLBAR_HH_ @@ -28,9 +28,6 @@ #ifndef _BASEMENU_HH_ #include "Basemenu.hh" #endif -#ifndef _LINKEDLIST_HH_ -#include "LinkedList.hh" -#endif #ifndef _TIMER_HH_ #include "Timer.hh" #endif -- cgit v0.11.2