#include "LinkedList.h"
#include "Timer.h"
+#include <algorithm>
+
// X error handler to handle any and all X errors while the application is
// running
static Bool internal_error = False;
timerList = new LinkedList<BTimer>;
- screenInfoList = new LinkedList<ScreenInfo>;
- for (int i = 0; i < number_of_screens; i++) {
- ScreenInfo *screeninfo = new ScreenInfo(*this, i);
- screenInfoList->insert(screeninfo);
- }
+ screenInfoList.reserve(ScreenCount(display));
+ for (int i = 0; i < number_of_screens; i++)
+ screenInfoList.push_back(new ScreenInfo(*this, i));
#ifndef NOCLOBBER
NumLockMask = ScrollLockMask = 0;
BaseDisplay::~BaseDisplay(void) {
- while (screenInfoList->count()) {
- ScreenInfo *si = screenInfoList->first();
-
- screenInfoList->remove(si);
- delete si;
- }
-
- delete screenInfoList;
+ std::for_each(screenInfoList.begin(), screenInfoList.end(),
+ PointerAssassin());
// we don't create the BTimers, we don't delete them
while (timerList->count())
#include "LinkedList.h"
#include "Timer.h"
#include "Geometry.h"
+#include "Util.h"
+#include <vector>
#define AttribShaded (1l << 0)
#define AttribMaxHoriz (1l << 1)
Bool _startup, _shutdown;
Display *display;
- LinkedList<ScreenInfo> *screenInfoList;
+
+ typedef std::vector<ScreenInfo*> ScreenInfoList;
+ ScreenInfoList screenInfoList;
+
LinkedList<BTimer> *timerList;
char *display_name, *application_name;
#endif // NEWWMSPEC
- inline ScreenInfo *getScreenInfo(int s)
- { return (ScreenInfo *) screenInfoList->find(s); }
+ inline ScreenInfo *getScreenInfo(int s) {
+ ASSERT(s < screenInfoList.size());
+ return screenInfoList[s];
+ }
inline const Bool &hasShapeExtensions(void) const
{ return shape.extensions; }
getVisual()->c_class);
exit(1);
}
-
- cache = new LinkedList<Cache>;
}
delete [] colors;
}
- if (cache->count()) {
- int i, n = cache->count();
+ if (!cache.empty()) {
+ int i, n = cache.size();
fprintf(stderr, i18n->getMessage(ImageSet, ImagePixmapRelease,
"BImageContol::~BImageControl: pixmap cache - "
"releasing %d pixmaps\n"), n);
for (i = 0; i < n; i++) {
- Cache *tmp = cache->first();
+ Cache *tmp = cache.front();
XFreePixmap(basedisplay.getXDisplay(), tmp->pixmap);
- cache->remove(tmp);
+ cache.remove(tmp);
delete tmp;
}
}
#endif // TIMEDCACHE
}
-
- delete cache;
}
Pixmap BImageControl::searchCache(unsigned int width, unsigned int height,
unsigned long texture,
BColor *c1, BColor *c2) {
- if (cache->count()) {
- LinkedListIterator<Cache> it(cache);
+ if (!cache.empty()) {
- for (Cache *tmp = it.current(); tmp; it++, tmp = it.current()) {
+ CacheList::iterator it;
+ for (it = cache.begin(); it != cache.end(); ++it) {
+ Cache *tmp = *it;
if ((tmp->width == width) && (tmp->height == height) &&
(tmp->texture == texture) && (tmp->pixel1 == c1->getPixel()))
- if (texture & BImage_Gradient) {
- if (tmp->pixel2 == c2->getPixel()) {
- tmp->count++;
- return tmp->pixmap;
- }
- } else {
+ if (texture & BImage_Gradient) {
+ if (tmp->pixel2 == c2->getPixel()) {
tmp->count++;
return tmp->pixmap;
}
+ } else {
+ tmp->count++;
+ return tmp->pixmap;
}
+ }
}
return None;
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->getMessage(ImageSet, ImagePixmapCacheLarge,
"BImageControl::renderImage: cache is large, "
void BImageControl::removeImage(Pixmap pixmap) {
if (pixmap) {
- LinkedListIterator<Cache> it(cache);
- for (Cache *tmp = it.current(); tmp; it++, tmp = it.current()) {
+ CacheList::iterator it;
+ for (it = cache.begin(); it != cache.end(); ++it) {
+ Cache *tmp = *it;
if (tmp->pixmap == pixmap) {
if (tmp->count) {
tmp->count--;
void BImageControl::timeout(void) {
- LinkedListIterator<Cache> it(cache);
- for (Cache *tmp = it.current(); tmp; it++, tmp = it.current()) {
+ CacheList::iterator it;
+ for (it = cache.begin(); it != cache.end(); ) {
+ Cache *tmp = *it;
+ ++it; // move on to the next item before this one is removed
if (tmp->count <= 0) {
XFreePixmap(basedisplay.getXDisplay(), tmp->pixmap);
- cache->remove(tmp);
+ cache.remove(tmp);
delete tmp;
- }
+ }
}
}