diff --git a/src/common/Stack.hxx b/src/common/Stack.hxx index d1c3d487f..978738b22 100644 --- a/src/common/Stack.hxx +++ b/src/common/Stack.hxx @@ -15,57 +15,41 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. // // $Id$ -// -// Based on code from ScummVM - Scumm Interpreter -// Copyright (C) 2002-2004 The ScummVM project //============================================================================ #ifndef STACK_HXX #define STACK_HXX -#include +#include /** * Simple fixed size stack class. */ namespace Common { -template +template class FixedStack { - protected: - T _stack[MAX_SIZE]; - int _size; + private: + array _stack; + uInt32 _size; public: - FixedStack() : _size(0) { } + FixedStack() : _size(0) { } bool empty() const { return _size <= 0; } - bool full() const { return _size >= MAX_SIZE; } - void clear() { _size = 0; } - void push(const T& x) - { - assert(_size < MAX_SIZE); - _stack[_size++] = x; - } - T top() const - { - if(_size > 0) - return _stack[_size - 1]; - else - return 0; - } - T pop() - { - assert(_size > 0); - return std::move(_stack[--_size]); - } - int size() const { return _size; } - T operator [](int i) const - { - assert(0 <= i && i < MAX_SIZE); - return _stack[i]; - } + bool full() const { return _size >= CAPACITY; } + + T top() const { return _stack[_size - 1]; } + void push(const T& x) { _stack[_size++] = x; } + T pop() { return std::move(_stack[--_size]); } + uInt32 size() const { return _size; } + + T* begin() { return _stack.begin(); } + T* end() { return _stack.begin() + _size; } + + const T* cbegin() const { return _stack.begin(); } + const T* cend() const { return _stack.begin() + _size; } private: // Following constructors and assignment operators not supported diff --git a/src/gui/ComboDialog.cxx b/src/gui/ComboDialog.cxx index 4efa47417..e092f3871 100644 --- a/src/gui/ComboDialog.cxx +++ b/src/gui/ComboDialog.cxx @@ -71,14 +71,14 @@ ComboDialog::ComboDialog(GuiObject* boss, const GUI::Font& font, }; xpos = 10; - ADD_EVENT_POPUP(0, "Event 1: "); - ADD_EVENT_POPUP(1, "Event 2: "); - ADD_EVENT_POPUP(2, "Event 3: "); - ADD_EVENT_POPUP(3, "Event 4: "); - ADD_EVENT_POPUP(4, "Event 5: "); - ADD_EVENT_POPUP(5, "Event 6: "); - ADD_EVENT_POPUP(6, "Event 7: "); - ADD_EVENT_POPUP(7, "Event 8: "); + myEvents[0] = nullptr; ADD_EVENT_POPUP(0, "Event 1: "); + myEvents[1] = nullptr; ADD_EVENT_POPUP(1, "Event 2: "); + myEvents[2] = nullptr; ADD_EVENT_POPUP(2, "Event 3: "); + myEvents[3] = nullptr; ADD_EVENT_POPUP(3, "Event 4: "); + myEvents[4] = nullptr; ADD_EVENT_POPUP(4, "Event 5: "); + myEvents[5] = nullptr; ADD_EVENT_POPUP(5, "Event 6: "); + myEvents[6] = nullptr; ADD_EVENT_POPUP(6, "Event 7: "); + myEvents[7] = nullptr; ADD_EVENT_POPUP(7, "Event 8: "); // Add Defaults, OK and Cancel buttons ButtonWidget* b; @@ -88,9 +88,6 @@ ComboDialog::ComboDialog(GuiObject* boss, const GUI::Font& font, addOKCancelBGroup(wid, font); addToFocusList(wid); - - // NOTE: Coverity doesn't yet support lambdas, so it complains that 'myEvents' - // isn't initialized (when it obviously is with ADD_EVENT_POPUP) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 6fe2552c9..e9a092f4d 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -302,10 +302,10 @@ void Dialog::drawDialog() // Extra surfaces must be rendered afterwards, so they are drawn on top if(s.render()) { - for(int i = 0; i < mySurfaceStack.size(); ++i) + for(auto& surface: mySurfaceStack) { - mySurfaceStack[i]->setDirty(); - mySurfaceStack[i]->render(); + surface->setDirty(); + surface->render(); } } } diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index cbb3f371b..30a3ddeeb 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -103,11 +103,11 @@ void DialogContainer::draw(bool full) // Draw all the dialogs on the stack when we want a full refresh if(full) { - for(int i = 0; i < myDialogStack.size(); i++) + for(auto& dialog: myDialogStack) { - myDialogStack[i]->center(); - myDialogStack[i]->setDirty(); - myDialogStack[i]->drawDialog(); + dialog->center(); + dialog->setDirty(); + dialog->drawDialog(); } } else if(!myDialogStack.empty())