Remove core::list and replace uses with std::list (#105)

This commit is contained in:
paradust7 2022-05-21 15:00:32 -07:00 committed by GitHub
parent 3e81f38098
commit 128cf1696c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 200 additions and 694 deletions

@ -6,7 +6,6 @@
#define __I_GUI_ELEMENT_H_INCLUDED__ #define __I_GUI_ELEMENT_H_INCLUDED__
#include "IReferenceCounted.h" #include "IReferenceCounted.h"
#include "irrList.h"
#include "rect.h" #include "rect.h"
#include "irrString.h" #include "irrString.h"
#include "IEventReceiver.h" #include "IEventReceiver.h"
@ -14,6 +13,10 @@
#include "EGUIAlignment.h" #include "EGUIAlignment.h"
#include "IAttributes.h" #include "IAttributes.h"
#include "IGUIEnvironment.h" #include "IGUIEnvironment.h"
#include <cassert>
#include <algorithm>
#include <list>
#include <vector>
namespace irr namespace irr
{ {
@ -50,12 +53,9 @@ public:
//! Destructor //! Destructor
virtual ~IGUIElement() virtual ~IGUIElement()
{ {
// delete all children for (auto child : Children) {
core::list<IGUIElement*>::Iterator it = Children.begin(); child->Parent = nullptr;
for (; it != Children.end(); ++it) child->drop();
{
(*it)->Parent = 0;
(*it)->drop();
} }
} }
@ -239,10 +239,9 @@ public:
recalculateAbsolutePosition(false); recalculateAbsolutePosition(false);
// update all children // update all children
core::list<IGUIElement*>::Iterator it = Children.begin(); for (auto child : Children)
for (; it != Children.end(); ++it)
{ {
(*it)->updateAbsolutePosition(); child->updateAbsolutePosition();
} }
} }
@ -263,20 +262,19 @@ public:
{ {
IGUIElement* target = 0; IGUIElement* target = 0;
// we have to search from back to front, because later children
// might be drawn over the top of earlier ones.
core::list<IGUIElement*>::ConstIterator it = Children.getLast();
if (isVisible()) if (isVisible())
{ {
while(it != Children.end()) // we have to search from back to front, because later children
// might be drawn over the top of earlier ones.
auto it = Children.rbegin();
auto ie = Children.rend();
while (it != ie)
{ {
target = (*it)->getElementFromPoint(point); target = (*it)->getElementFromPoint(point);
if (target) if (target)
return target; return target;
--it; ++it;
} }
} }
@ -308,17 +306,19 @@ public:
//! Removes a child. //! Removes a child.
virtual void removeChild(IGUIElement* child) virtual void removeChild(IGUIElement* child)
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); assert(child->Parent == this);
for (; it != Children.end(); ++it) Children.erase(child->ParentPos);
if ((*it) == child) child->Parent = nullptr;
{ child->drop();
(*it)->Parent = 0;
(*it)->drop();
Children.erase(it);
return;
}
} }
//! Removes all children.
virtual void removeAllChildren() {
while (!Children.empty()) {
auto child = Children.back();
child->remove();
}
}
//! Removes this element from its parent. //! Removes this element from its parent.
virtual void remove() virtual void remove()
@ -333,9 +333,8 @@ public:
{ {
if ( isVisible() ) if ( isVisible() )
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); for (auto child : Children)
for (; it != Children.end(); ++it) child->draw();
(*it)->draw();
} }
} }
@ -345,9 +344,8 @@ public:
{ {
if ( isVisible() ) if ( isVisible() )
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); for (auto child : Children)
for (; it != Children.end(); ++it) child->OnPostRender( timeMs );
(*it)->OnPostRender( timeMs );
} }
} }
@ -555,20 +553,15 @@ public:
//! Brings a child to front //! Brings a child to front
/** \return True if successful, false if not. */ /** \return True if successful, false if not. */
virtual bool bringToFront(IGUIElement* element) virtual bool bringToFront(IGUIElement* child)
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); if (child->Parent != this)
for (; it != Children.end(); ++it) return false;
{ if (std::next(child->ParentPos) == Children.end()) // already there
if (element == (*it)) return true;
{ Children.erase(child->ParentPos);
Children.erase(it); child->ParentPos = Children.insert(Children.end(), child);
Children.push_back(element); return true;
return true;
}
}
return false;
} }
@ -576,24 +569,17 @@ public:
/** \return True if successful, false if not. */ /** \return True if successful, false if not. */
virtual bool sendToBack(IGUIElement* child) virtual bool sendToBack(IGUIElement* child)
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); if (child->Parent != this)
if (child == (*it)) // already there return false;
if (child->ParentPos == Children.begin()) // already there
return true; return true;
for (; it != Children.end(); ++it) Children.erase(child->ParentPos);
{ child->ParentPos = Children.insert(Children.begin(), child);
if (child == (*it)) return true;
{
Children.erase(it);
Children.push_front(child);
return true;
}
}
return false;
} }
//! Returns list with children of this element //! Returns list with children of this element
virtual const core::list<IGUIElement*>& getChildren() const virtual const std::list<IGUIElement*>& getChildren() const
{ {
return Children; return Children;
} }
@ -610,14 +596,13 @@ public:
{ {
IGUIElement* e = 0; IGUIElement* e = 0;
core::list<IGUIElement*>::ConstIterator it = Children.begin(); for (auto child : Children)
for (; it != Children.end(); ++it)
{ {
if ((*it)->getID() == id) if (child->getID() == id)
return (*it); return child;
if (searchchildren) if (searchchildren)
e = (*it)->getElementFromId(id, true); e = child->getElementFromId(id, true);
if (e) if (e)
return e; return e;
@ -663,7 +648,7 @@ public:
if (wanted==-2) if (wanted==-2)
wanted = 1073741824; // maximum s32 wanted = 1073741824; // maximum s32
core::list<IGUIElement*>::ConstIterator it = Children.begin(); auto it = Children.begin();
s32 closestOrder, currentOrder; s32 closestOrder, currentOrder;
@ -806,10 +791,40 @@ protected:
child->remove(); // remove from old parent child->remove(); // remove from old parent
child->LastParentRect = getAbsolutePosition(); child->LastParentRect = getAbsolutePosition();
child->Parent = this; child->Parent = this;
Children.push_back(child); child->ParentPos = Children.insert(Children.end(), child);
} }
} }
#ifndef NDEBUG
template<typename Iterator>
static size_t _fastSetChecksum(Iterator begin, Iterator end) {
std::hash<typename Iterator::value_type> hasher;
size_t checksum = 0;
for (Iterator it = begin; it != end; ++it) {
size_t h = hasher(*it);
checksum ^= 966073049 + (h * 3432918353) + ((h >> 16) * 461845907);
}
return checksum;
}
#endif
// Reorder children [from, to) to the order given by `neworder`
void reorderChildren(
std::list<IGUIElement*>::iterator from,
std::list<IGUIElement*>::iterator to,
const std::vector<IGUIElement*> &neworder)
{
assert(_fastSetChecksum(from, to) == _fastSetChecksum(neworder.begin(), neworder.end()));
for (auto e : neworder)
{
*from = e;
e->ParentPos = from;
++from;
}
assert(from == to);
}
// not virtual because needed in constructor // not virtual because needed in constructor
void recalculateAbsolutePosition(bool recursive) void recalculateAbsolutePosition(bool recursive)
{ {
@ -931,10 +946,9 @@ protected:
if ( recursive ) if ( recursive )
{ {
// update all children // update all children
core::list<IGUIElement*>::Iterator it = Children.begin(); for (auto child : Children)
for (; it != Children.end(); ++it)
{ {
(*it)->recalculateAbsolutePosition(recursive); child->recalculateAbsolutePosition(recursive);
} }
} }
} }
@ -942,11 +956,14 @@ protected:
protected: protected:
//! List of all children of this element //! List of all children of this element
core::list<IGUIElement*> Children; std::list<IGUIElement*> Children;
//! Pointer to the parent //! Pointer to the parent
IGUIElement* Parent; IGUIElement* Parent;
//! Our position in the parent list. Only valid when Parent != nullptr
std::list<IGUIElement*>::iterator ParentPos;
//! relative rect of element //! relative rect of element
core::rect<s32> RelativeRect; core::rect<s32> RelativeRect;

@ -13,8 +13,8 @@
#include "irrString.h" #include "irrString.h"
#include "aabbox3d.h" #include "aabbox3d.h"
#include "matrix4.h" #include "matrix4.h"
#include "irrList.h"
#include "IAttributes.h" #include "IAttributes.h"
#include <list>
namespace irr namespace irr
{ {
@ -24,7 +24,7 @@ namespace scene
class ISceneManager; class ISceneManager;
//! Typedef for list of scene nodes //! Typedef for list of scene nodes
typedef core::list<ISceneNode*> ISceneNodeList; typedef std::list<ISceneNode*> ISceneNodeList;
//! Scene node interface. //! Scene node interface.
/** A scene node is a node in the hierarchical scene graph. Every scene /** A scene node is a node in the hierarchical scene graph. Every scene
@ -81,7 +81,7 @@ namespace scene
{ {
if (IsVisible) if (IsVisible)
{ {
ISceneNodeList::Iterator it = Children.begin(); ISceneNodeList::iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
(*it)->OnRegisterSceneNode(); (*it)->OnRegisterSceneNode();
} }
@ -103,7 +103,7 @@ namespace scene
// perform the post render process on all children // perform the post render process on all children
ISceneNodeList::Iterator it = Children.begin(); ISceneNodeList::iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
(*it)->OnAnimate(timeMs); (*it)->OnAnimate(timeMs);
} }
@ -289,7 +289,7 @@ namespace scene
e.g. because it couldn't be found in the children list. */ e.g. because it couldn't be found in the children list. */
virtual bool removeChild(ISceneNode* child) virtual bool removeChild(ISceneNode* child)
{ {
ISceneNodeList::Iterator it = Children.begin(); ISceneNodeList::iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
if ((*it) == child) if ((*it) == child)
{ {
@ -309,7 +309,7 @@ namespace scene
*/ */
virtual void removeAll() virtual void removeAll()
{ {
ISceneNodeList::Iterator it = Children.begin(); ISceneNodeList::iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
{ {
(*it)->Parent = 0; (*it)->Parent = 0;
@ -519,7 +519,7 @@ namespace scene
//! Returns a const reference to the list of all children. //! Returns a const reference to the list of all children.
/** \return The list of all children of this node. */ /** \return The list of all children of this node. */
const core::list<ISceneNode*>& getChildren() const const std::list<ISceneNode*>& getChildren() const
{ {
return Children; return Children;
} }
@ -611,7 +611,7 @@ namespace scene
// clone children // clone children
ISceneNodeList::Iterator it = toCopyFrom->Children.begin(); ISceneNodeList::iterator it = toCopyFrom->Children.begin();
for (; it != toCopyFrom->Children.end(); ++it) for (; it != toCopyFrom->Children.end(); ++it)
(*it)->clone(this, newManager); (*it)->clone(this, newManager);
} }
@ -622,7 +622,7 @@ namespace scene
{ {
SceneManager = newManager; SceneManager = newManager;
ISceneNodeList::Iterator it = Children.begin(); ISceneNodeList::iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
(*it)->setSceneManager(newManager); (*it)->setSceneManager(newManager);
} }
@ -646,7 +646,7 @@ namespace scene
ISceneNode* Parent; ISceneNode* Parent;
//! List of all children of this node //! List of all children of this node
core::list<ISceneNode*> Children; std::list<ISceneNode*> Children;
//! Pointer to the scene manager //! Pointer to the scene manager
ISceneManager* SceneManager; ISceneManager* SceneManager;

@ -1,414 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __IRR_LIST_H_INCLUDED__
#define __IRR_LIST_H_INCLUDED__
#include "irrTypes.h"
#include "irrAllocator.h"
#include "irrMath.h"
namespace irr
{
namespace core
{
//! Doubly linked list template.
template <class T>
class list
{
private:
//! List element node with pointer to previous and next element in the list.
struct SKListNode
{
SKListNode(const T& e) : Next(0), Prev(0), Element(e) {}
SKListNode* Next;
SKListNode* Prev;
T Element;
};
public:
class ConstIterator;
//! List iterator.
class Iterator
{
public:
Iterator() : Current(0) {}
Iterator& operator ++() { Current = Current->Next; return *this; }
Iterator& operator --() { Current = Current->Prev; return *this; }
Iterator operator ++(s32) { Iterator tmp = *this; Current = Current->Next; return tmp; }
Iterator operator --(s32) { Iterator tmp = *this; Current = Current->Prev; return tmp; }
Iterator& operator +=(s32 num)
{
if(num > 0)
{
while (num-- && this->Current != 0) ++(*this);
}
else
{
while(num++ && this->Current != 0) --(*this);
}
return *this;
}
Iterator operator + (s32 num) const { Iterator tmp = *this; return tmp += num; }
Iterator& operator -=(s32 num) { return (*this)+=(-num); }
Iterator operator - (s32 num) const { return (*this)+ (-num); }
bool operator ==(const Iterator& other) const { return Current == other.Current; }
bool operator !=(const Iterator& other) const { return Current != other.Current; }
bool operator ==(const ConstIterator& other) const { return Current == other.Current; }
bool operator !=(const ConstIterator& other) const { return Current != other.Current; }
T & operator * () { return Current->Element; }
T * operator ->() { return &Current->Element; }
private:
explicit Iterator(SKListNode* begin) : Current(begin) {}
SKListNode* Current;
friend class list<T>;
friend class ConstIterator;
};
//! List iterator for const access.
class ConstIterator
{
public:
ConstIterator() : Current(0) {}
ConstIterator(const Iterator& iter) : Current(iter.Current) {}
ConstIterator& operator ++() { Current = Current->Next; return *this; }
ConstIterator& operator --() { Current = Current->Prev; return *this; }
ConstIterator operator ++(s32) { ConstIterator tmp = *this; Current = Current->Next; return tmp; }
ConstIterator operator --(s32) { ConstIterator tmp = *this; Current = Current->Prev; return tmp; }
ConstIterator& operator +=(s32 num)
{
if(num > 0)
{
while(num-- && this->Current != 0) ++(*this);
}
else
{
while(num++ && this->Current != 0) --(*this);
}
return *this;
}
ConstIterator operator + (s32 num) const { ConstIterator tmp = *this; return tmp += num; }
ConstIterator& operator -=(s32 num) { return (*this)+=(-num); }
ConstIterator operator - (s32 num) const { return (*this)+ (-num); }
bool operator ==(const ConstIterator& other) const { return Current == other.Current; }
bool operator !=(const ConstIterator& other) const { return Current != other.Current; }
bool operator ==(const Iterator& other) const { return Current == other.Current; }
bool operator !=(const Iterator& other) const { return Current != other.Current; }
const T & operator * () { return Current->Element; }
const T * operator ->() { return &Current->Element; }
ConstIterator & operator =(const Iterator & iterator) { Current = iterator.Current; return *this; }
private:
explicit ConstIterator(SKListNode* begin) : Current(begin) {}
SKListNode* Current;
friend class Iterator;
friend class list<T>;
};
//! Default constructor for empty list.
list()
: First(0), Last(0), Size(0) {}
//! Copy constructor.
list(const list<T>& other) : First(0), Last(0), Size(0)
{
*this = other;
}
//! Destructor
~list()
{
clear();
}
//! Assignment operator
void operator=(const list<T>& other)
{
if(&other == this)
{
return;
}
clear();
SKListNode* node = other.First;
while(node)
{
push_back(node->Element);
node = node->Next;
}
}
//! Returns amount of elements in list.
/** \return Amount of elements in the list. */
u32 size() const
{
return Size;
}
u32 getSize() const
{
return Size;
}
//! Clears the list, deletes all elements in the list.
/** All existing iterators of this list will be invalid. */
void clear()
{
while(First)
{
SKListNode * next = First->Next;
allocator.destruct(First);
allocator.deallocate(First);
First = next;
}
//First = 0; handled by loop
Last = 0;
Size = 0;
}
//! Checks for empty list.
/** \return True if the list is empty and false if not. */
bool empty() const
{
return (First == 0);
}
//! Adds an element at the end of the list.
/** \param element Element to add to the list. */
void push_back(const T& element)
{
SKListNode* node = allocator.allocate(1);
allocator.construct(node, element);
++Size;
if (First == 0)
First = node;
node->Prev = Last;
if (Last != 0)
Last->Next = node;
Last = node;
}
//! Adds an element at the begin of the list.
/** \param element: Element to add to the list. */
void push_front(const T& element)
{
SKListNode* node = allocator.allocate(1);
allocator.construct(node, element);
++Size;
if (First == 0)
{
Last = node;
First = node;
}
else
{
node->Next = First;
First->Prev = node;
First = node;
}
}
//! Gets first node.
/** \return A list iterator pointing to the beginning of the list. */
Iterator begin()
{
return Iterator(First);
}
//! Gets first node.
/** \return A const list iterator pointing to the beginning of the list. */
ConstIterator begin() const
{
return ConstIterator(First);
}
//! Gets end node.
/** \return List iterator pointing to null. */
Iterator end()
{
return Iterator(0);
}
//! Gets end node.
/** \return Const list iterator pointing to null. */
ConstIterator end() const
{
return ConstIterator(0);
}
//! Gets last element.
/** \return List iterator pointing to the last element of the list. */
Iterator getLast()
{
return Iterator(Last);
}
//! Gets last element.
/** \return Const list iterator pointing to the last element of the list. */
ConstIterator getLast() const
{
return ConstIterator(Last);
}
//! Inserts an element after an element.
/** \param it Iterator pointing to element after which the new element
should be inserted.
\param element The new element to be inserted into the list.
*/
void insert_after(const Iterator& it, const T& element)
{
SKListNode* node = allocator.allocate(1);
allocator.construct(node, element);
node->Next = it.Current->Next;
if (it.Current->Next)
it.Current->Next->Prev = node;
node->Prev = it.Current;
it.Current->Next = node;
++Size;
if (it.Current == Last)
Last = node;
}
//! Inserts an element before an element.
/** \param it Iterator pointing to element before which the new element
should be inserted.
\param element The new element to be inserted into the list.
*/
void insert_before(const Iterator& it, const T& element)
{
SKListNode* node = allocator.allocate(1);
allocator.construct(node, element);
node->Prev = it.Current->Prev;
if (it.Current->Prev)
it.Current->Prev->Next = node;
node->Next = it.Current;
it.Current->Prev = node;
++Size;
if (it.Current == First)
First = node;
}
//! Erases an element.
/** \param it Iterator pointing to the element which shall be erased.
\return Iterator pointing to next element. */
Iterator erase(Iterator& it)
{
// suggest changing this to a const Iterator& and
// working around line: it.Current = 0 (possibly with a mutable, or just let it be garbage?)
Iterator returnIterator(it);
++returnIterator;
if(it.Current == First)
{
First = it.Current->Next;
}
else
{
it.Current->Prev->Next = it.Current->Next;
}
if(it.Current == Last)
{
Last = it.Current->Prev;
}
else
{
it.Current->Next->Prev = it.Current->Prev;
}
allocator.destruct(it.Current);
allocator.deallocate(it.Current);
it.Current = 0;
--Size;
return returnIterator;
}
//! Swap the content of this list container with the content of another list
/** Afterward this object will contain the content of the other object and the other
object will contain the content of this object. Iterators will afterward be valid for
the swapped object.
\param other Swap content with this object */
void swap(list<T>& other)
{
core::swap(First, other.First);
core::swap(Last, other.Last);
core::swap(Size, other.Size);
core::swap(allocator, other.allocator); // memory is still released by the same allocator used for allocation
}
typedef T value_type;
typedef u32 size_type;
private:
SKListNode* First;
SKListNode* Last;
u32 Size;
irrAllocator<SKListNode> allocator;
};
} // end namespace core
}// end namespace irr
#endif

@ -111,7 +111,6 @@
#include "IRandomizer.h" #include "IRandomizer.h"
#include "IRenderTarget.h" #include "IRenderTarget.h"
#include "IrrlichtDevice.h" #include "IrrlichtDevice.h"
#include "irrList.h"
#include "irrMath.h" #include "irrMath.h"
#include "irrString.h" #include "irrString.h"
#include "irrTypes.h" #include "irrTypes.h"

@ -71,7 +71,7 @@ void CBoneSceneNode::OnAnimate(u32 timeMs)
//updateAbsolutePosition(); //updateAbsolutePosition();
// perform the post render process on all children // perform the post render process on all children
ISceneNodeList::Iterator it = Children.begin(); ISceneNodeList::iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
(*it)->OnAnimate(timeMs); (*it)->OnAnimate(timeMs);
} }
@ -82,7 +82,7 @@ void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node
{ {
Node->updateAbsolutePosition(); Node->updateAbsolutePosition();
ISceneNodeList::ConstIterator it = Node->getChildren().begin(); ISceneNodeList::const_iterator it = Node->getChildren().begin();
for (; it != Node->getChildren().end(); ++it) for (; it != Node->getChildren().end(); ++it)
{ {
helper_updateAbsolutePositionOfAllChildren( (*it) ); helper_updateAbsolutePositionOfAllChildren( (*it) );

@ -16,7 +16,7 @@
#include "CMemoryFile.h" #include "CMemoryFile.h"
#include "CLimitReadFile.h" #include "CLimitReadFile.h"
#include "CWriteFile.h" #include "CWriteFile.h"
#include "irrList.h" #include <list>
#if defined (__STRICT_ANSI__) #if defined (__STRICT_ANSI__)
#error Compiling with __STRICT_ANSI__ not supported. g++ does set this when compiling with -std=c++11 or -std=c++0x. Use instead -std=gnu++11 or -std=gnu++0x. Or use -U__STRICT_ANSI__ to disable strict ansi. #error Compiling with __STRICT_ANSI__ not supported. g++ does set this when compiling with -std=c++11 or -std=c++0x. Use instead -std=gnu++11 or -std=gnu++0x. Or use -U__STRICT_ANSI__ to disable strict ansi.
@ -714,11 +714,10 @@ path CFileSystem::getRelativeFilename(const path& filename, const path& director
io::path path1, file, ext; io::path path1, file, ext;
core::splitFilename(getAbsolutePath(filename), &path1, &file, &ext); core::splitFilename(getAbsolutePath(filename), &path1, &file, &ext);
io::path path2(getAbsolutePath(directory)); io::path path2(getAbsolutePath(directory));
core::list<io::path> list1, list2; std::list<io::path> list1, list2;
path1.split(list1, _IRR_TEXT("/\\"), 2); path1.split(list1, _IRR_TEXT("/\\"), 2);
path2.split(list2, _IRR_TEXT("/\\"), 2); path2.split(list2, _IRR_TEXT("/\\"), 2);
u32 i=0; std::list<io::path>::const_iterator it1,it2;
core::list<io::path>::ConstIterator it1,it2;
it1=list1.begin(); it1=list1.begin();
it2=list2.begin(); it2=list2.begin();
@ -742,19 +741,19 @@ path CFileSystem::getRelativeFilename(const path& filename, const path& director
#endif #endif
for (; i<list1.size() && i<list2.size() for (; it1 != list1.end() && it2 != list2.end()
#if defined (_IRR_WINDOWS_API_) #if defined (_IRR_WINDOWS_API_)
&& (io::path(*it1).make_lower()==io::path(*it2).make_lower()) && (io::path(*it1).make_lower()==io::path(*it2).make_lower())
#else #else
&& (*it1==*it2) && (*it1==*it2)
#endif #endif
; ++i) ;)
{ {
++it1; ++it1;
++it2; ++it2;
} }
path1=_IRR_TEXT(""); path1=_IRR_TEXT("");
for (; i<list2.size(); ++i) for (; it2 != list2.end(); ++it2)
path1 += _IRR_TEXT("../"); path1 += _IRR_TEXT("../");
while (it1 != list1.end()) while (it1 != list1.end())
{ {

@ -387,11 +387,7 @@ void CGUIEnvironment::clear()
HoveredNoSubelement = 0; HoveredNoSubelement = 0;
} }
// get the root's children in case the root changes in future getRootGUIElement()->removeAllChildren();
const core::list<IGUIElement*>& children = getRootGUIElement()->getChildren();
while (!children.empty())
(*children.getLast())->remove();
} }

@ -57,17 +57,12 @@ bool CGUIModalScreen::isVisible() const
} }
// any child visible? // any child visible?
bool visible = false; for (const auto& child : Children)
core::list<IGUIElement*>::ConstIterator it = Children.begin();
for (; it != Children.end(); ++it)
{ {
if ( (*it)->isVisible() ) if ( child->isVisible() )
{ return true;
visible = true;
break;
}
} }
return visible; return false;
} }
bool CGUIModalScreen::isPointInside(const core::position2d<s32>& point) const bool CGUIModalScreen::isPointInside(const core::position2d<s32>& point) const
@ -98,7 +93,7 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
if ( !canTakeFocus(event.GUIEvent.Caller)) if ( !canTakeFocus(event.GUIEvent.Caller))
{ {
if ( !Children.empty() ) if ( !Children.empty() )
Environment->setFocus(*(Children.begin())); Environment->setFocus(Children.front());
else else
Environment->setFocus(this); Environment->setFocus(this);
} }
@ -110,7 +105,7 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
if ( isMyChild(event.GUIEvent.Caller) ) if ( isMyChild(event.GUIEvent.Caller) )
{ {
if ( !Children.empty() ) if ( !Children.empty() )
Environment->setFocus(*(Children.begin())); Environment->setFocus(Children.front());
else else
Environment->setFocus(this); Environment->setFocus(this);
} }
@ -171,15 +166,14 @@ void CGUIModalScreen::draw()
u32 now = os::Timer::getTime(); u32 now = os::Timer::getTime();
if (BlinkMode && now - MouseDownTime < 300 && (now / 70)%2) if (BlinkMode && now - MouseDownTime < 300 && (now / 70)%2)
{ {
core::list<IGUIElement*>::Iterator it = Children.begin();
core::rect<s32> r; core::rect<s32> r;
video::SColor c = Environment->getSkin()->getColor(gui::EGDC_3D_HIGH_LIGHT); video::SColor c = Environment->getSkin()->getColor(gui::EGDC_3D_HIGH_LIGHT);
for (; it != Children.end(); ++it) for (auto child : Children)
{ {
if ((*it)->isVisible()) if (child->isVisible())
{ {
r = (*it)->getAbsolutePosition(); r = child->getAbsolutePosition();
r.LowerRightCorner.X += 1; r.LowerRightCorner.X += 1;
r.LowerRightCorner.Y += 1; r.LowerRightCorner.Y += 1;
r.UpperLeftCorner.X -= 1; r.UpperLeftCorner.X -= 1;

@ -34,11 +34,8 @@ CGUIToolBar::CGUIToolBar(IGUIEnvironment* environment, IGUIElement* parent, s32
parentwidth = Parent->getAbsolutePosition().getWidth(); parentwidth = Parent->getAbsolutePosition().getWidth();
s32 parentheight = Parent->getAbsolutePosition().getHeight(); s32 parentheight = Parent->getAbsolutePosition().getHeight();
const core::list<IGUIElement*>& children = parent->getChildren(); for (const auto& e : parent->getChildren())
core::list<IGUIElement*>::ConstIterator it = children.begin();
for (; it != children.end(); ++it)
{ {
const IGUIElement* e = *it;
if ( e->hasType(EGUIET_CONTEXT_MENU) if ( e->hasType(EGUIET_CONTEXT_MENU)
|| e->hasType(EGUIET_MENU) || e->hasType(EGUIET_MENU)
|| e->hasType(EGUIET_TOOL_BAR) ) || e->hasType(EGUIET_TOOL_BAR) )

@ -66,11 +66,10 @@ void CGUITreeViewNode::setIcon( const wchar_t* icon )
void CGUITreeViewNode::clearChildren() void CGUITreeViewNode::clearChildren()
{ {
core::list<CGUITreeViewNode*>::Iterator it; for (auto child : Children)
for( it = Children.begin(); it != Children.end(); it++ )
{ {
( *it )->drop(); child->Parent = nullptr;
child->drop();
} }
Children.clear(); Children.clear();
} }
@ -83,9 +82,8 @@ IGUITreeViewNode* CGUITreeViewNode::addChildBack(
void* data /*= 0*/, void* data /*= 0*/,
IReferenceCounted* data2 /*= 0*/ ) IReferenceCounted* data2 /*= 0*/ )
{ {
CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this ); auto newChild = new CGUITreeViewNode( Owner, this );
newChild->ParentPos = Children.insert(Children.end(), newChild);
Children.push_back( newChild );
newChild->Text = text; newChild->Text = text;
newChild->Icon = icon; newChild->Icon = icon;
newChild->ImageIndex = imageIndex; newChild->ImageIndex = imageIndex;
@ -107,9 +105,8 @@ IGUITreeViewNode* CGUITreeViewNode::addChildFront(
void* data /*= 0*/, void* data /*= 0*/,
IReferenceCounted* data2 /*= 0*/ ) IReferenceCounted* data2 /*= 0*/ )
{ {
CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this ); auto newChild = new CGUITreeViewNode( Owner, this );
newChild->ParentPos = Children.insert(Children.begin(), newChild);
Children.push_front( newChild );
newChild->Text = text; newChild->Text = text;
newChild->Icon = icon; newChild->Icon = icon;
newChild->ImageIndex = imageIndex; newChild->ImageIndex = imageIndex;
@ -124,7 +121,7 @@ IGUITreeViewNode* CGUITreeViewNode::addChildFront(
} }
IGUITreeViewNode* CGUITreeViewNode::insertChildAfter( IGUITreeViewNode* CGUITreeViewNode::insertChildAfter(
IGUITreeViewNode* other, IGUITreeViewNode* iother,
const wchar_t* text, const wchar_t* text,
const wchar_t* icon /*= 0*/, const wchar_t* icon /*= 0*/,
s32 imageIndex /*= -1*/, s32 imageIndex /*= -1*/,
@ -132,33 +129,27 @@ IGUITreeViewNode* CGUITreeViewNode::insertChildAfter(
void* data /*= 0*/, void* data /*= 0*/,
IReferenceCounted* data2/* = 0*/ ) IReferenceCounted* data2/* = 0*/ )
{ {
core::list<CGUITreeViewNode*>::Iterator itOther; // This cast is needed to access the ParentPos member of `other`.
CGUITreeViewNode* newChild = 0; // The abstraction was already broken, because Children is a list of
// CGUITreeViewNode, not IGUITreeViewNode. The existing code was
for( itOther = Children.begin(); itOther != Children.end(); itOther++ ) // implicitly casting through pointer comparison.
{ auto other = static_cast<CGUITreeViewNode*>(iother);
if( other == *itOther ) assert(other->Parent == this);
{ auto newChild = new CGUITreeViewNode( Owner, this );
newChild = new CGUITreeViewNode( Owner, this ); newChild->ParentPos = Children.insert(std::next(other->ParentPos), newChild);
newChild->Text = text; newChild->Text = text;
newChild->Icon = icon; newChild->Icon = icon;
newChild->ImageIndex = imageIndex; newChild->ImageIndex = imageIndex;
newChild->SelectedImageIndex = selectedImageIndex; newChild->SelectedImageIndex = selectedImageIndex;
newChild->Data = data; newChild->Data = data;
newChild->Data2 = data2; newChild->Data2 = data2;
if( data2 ) if( data2 )
{ data2->grab();
data2->grab();
}
Children.insert_after( itOther, newChild );
break;
}
}
return newChild; return newChild;
} }
IGUITreeViewNode* CGUITreeViewNode::insertChildBefore( IGUITreeViewNode* CGUITreeViewNode::insertChildBefore(
IGUITreeViewNode* other, IGUITreeViewNode* iother,
const wchar_t* text, const wchar_t* text,
const wchar_t* icon /*= 0*/, const wchar_t* icon /*= 0*/,
s32 imageIndex /*= -1*/, s32 imageIndex /*= -1*/,
@ -166,28 +157,18 @@ IGUITreeViewNode* CGUITreeViewNode::insertChildBefore(
void* data /*= 0*/, void* data /*= 0*/,
IReferenceCounted* data2/* = 0*/ ) IReferenceCounted* data2/* = 0*/ )
{ {
core::list<CGUITreeViewNode*>::Iterator itOther; auto other = static_cast<CGUITreeViewNode*>(iother);
CGUITreeViewNode* newChild = 0; assert(other->Parent == this);
auto newChild = new CGUITreeViewNode( Owner, this );
for( itOther = Children.begin(); itOther != Children.end(); itOther++ ) newChild->ParentPos = Children.insert(other->ParentPos, newChild);
{ newChild->Text = text;
if( other == *itOther ) newChild->Icon = icon;
{ newChild->ImageIndex = imageIndex;
newChild = new CGUITreeViewNode( Owner, this ); newChild->SelectedImageIndex = selectedImageIndex;
newChild->Text = text; newChild->Data = data;
newChild->Icon = icon; newChild->Data2 = data2;
newChild->ImageIndex = imageIndex; if( data2 )
newChild->SelectedImageIndex = selectedImageIndex; data2->grab();
newChild->Data = data;
newChild->Data2 = data2;
if( data2 )
{
data2->grab();
}
Children.insert_before( itOther, newChild );
break;
}
}
return newChild; return newChild;
} }
@ -199,7 +180,7 @@ IGUITreeViewNode* CGUITreeViewNode::getFirstChild() const
} }
else else
{ {
return *( Children.begin() ); return Children.front();
} }
} }
@ -211,54 +192,25 @@ IGUITreeViewNode* CGUITreeViewNode::getLastChild() const
} }
else else
{ {
return *( Children.getLast() ); return Children.back();
} }
} }
IGUITreeViewNode* CGUITreeViewNode::getPrevSibling() const IGUITreeViewNode* CGUITreeViewNode::getPrevSibling() const
{ {
core::list<CGUITreeViewNode*>::Iterator itThis; if (!Parent || ParentPos == Parent->Children.begin())
core::list<CGUITreeViewNode*>::Iterator itOther; return nullptr;
CGUITreeViewNode* other = 0; return *std::prev(ParentPos);
if( Parent )
{
for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ )
{
if( this == *itThis )
{
if( itThis != Parent->Children.begin() )
{
other = *itOther;
}
break;
}
itOther = itThis;
}
}
return other;
} }
IGUITreeViewNode* CGUITreeViewNode::getNextSibling() const IGUITreeViewNode* CGUITreeViewNode::getNextSibling() const
{ {
core::list<CGUITreeViewNode*>::Iterator itThis; if (!Parent)
CGUITreeViewNode* other = 0; return nullptr;
auto nextIt = std::next(ParentPos);
if( Parent ) if (nextIt == Parent->Children.end())
{ return nullptr;
for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ ) return *nextIt;
{
if( this == *itThis )
{
if( itThis != Parent->Children.getLast() )
{
other = *( ++itThis );
}
break;
}
}
}
return other;
} }
IGUITreeViewNode* CGUITreeViewNode::getNextVisible() const IGUITreeViewNode* CGUITreeViewNode::getNextVisible() const
@ -286,73 +238,40 @@ IGUITreeViewNode* CGUITreeViewNode::getNextVisible() const
return next; return next;
} }
bool CGUITreeViewNode::deleteChild( IGUITreeViewNode* child ) bool CGUITreeViewNode::deleteChild( IGUITreeViewNode* ichild )
{ {
core::list<CGUITreeViewNode*>::Iterator itChild; auto child = static_cast<CGUITreeViewNode*>(ichild);
bool deleted = false; assert(child->Parent == this);
Children.erase(child->ParentPos);
for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) child->Parent = nullptr;
{ child->drop();
if( child == *itChild ) return true;
{
child->drop();
Children.erase( itChild );
deleted = true;
break;
}
}
return deleted;
} }
bool CGUITreeViewNode::moveChildUp( IGUITreeViewNode* child ) bool CGUITreeViewNode::moveChildUp( IGUITreeViewNode* ichild )
{ {
core::list<CGUITreeViewNode*>::Iterator itChild; auto child = static_cast<CGUITreeViewNode*>(ichild);
core::list<CGUITreeViewNode*>::Iterator itOther; assert(child->Parent == this);
CGUITreeViewNode* nodeTmp; if (child->ParentPos == Children.begin())
bool moved = false; return false;
auto curPos = child->ParentPos;
for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) auto prevPos = std::prev(child->ParentPos);
{ std::swap(*curPos, *prevPos);
if( child == *itChild ) std::swap((*curPos)->ParentPos, (*prevPos)->ParentPos);
{ return true;
if( itChild != Children.begin() )
{
nodeTmp = *itChild;
*itChild = *itOther;
*itOther = nodeTmp;
moved = true;
}
break;
}
itOther = itChild;
}
return moved;
} }
bool CGUITreeViewNode::moveChildDown( IGUITreeViewNode* child ) bool CGUITreeViewNode::moveChildDown( IGUITreeViewNode* ichild )
{ {
core::list<CGUITreeViewNode*>::Iterator itChild; auto child = static_cast<CGUITreeViewNode*>(ichild);
core::list<CGUITreeViewNode*>::Iterator itOther; assert(child->Parent == this);
CGUITreeViewNode* nodeTmp; auto nextPos = std::next(child->ParentPos);
bool moved = false; if (nextPos == Children.end())
return false;
for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) auto curPos = child->ParentPos;
{ std::swap(*curPos, *nextPos);
if( child == *itChild ) std::swap((*curPos)->ParentPos, (*nextPos)->ParentPos);
{ return true;
if( itChild != Children.getLast() )
{
itOther = itChild;
++itOther;
nodeTmp = *itChild;
*itChild = *itOther;
*itOther = nodeTmp;
moved = true;
}
break;
}
}
return moved;
} }
void CGUITreeViewNode::setExpanded( bool expanded ) void CGUITreeViewNode::setExpanded( bool expanded )

@ -5,7 +5,6 @@
#define __C_GUI_TREE_VIEW_H_INCLUDED__ #define __C_GUI_TREE_VIEW_H_INCLUDED__
#include "IGUITreeView.h" #include "IGUITreeView.h"
#include "irrList.h"
namespace irr namespace irr
@ -93,7 +92,7 @@ namespace gui
//! returns the child item count //! returns the child item count
virtual u32 getChildCount() const _IRR_OVERRIDE_ virtual u32 getChildCount() const _IRR_OVERRIDE_
{ return Children.getSize(); } { return Children.size(); }
//! removes all children (recursive) from this node //! removes all children (recursive) from this node
virtual void clearChildren() _IRR_OVERRIDE_; virtual void clearChildren() _IRR_OVERRIDE_;
@ -231,7 +230,10 @@ namespace gui
void* Data; void* Data;
IReferenceCounted* Data2; IReferenceCounted* Data2;
bool Expanded; bool Expanded;
core::list<CGUITreeViewNode*> Children; std::list<CGUITreeViewNode*> Children;
// Position of this node in Parent->Children.
// Only valid when Parent != NULL
std::list<CGUITreeViewNode*>::iterator ParentPos;
}; };

@ -14,7 +14,6 @@
#include "CIrrDeviceOSX.h" #include "CIrrDeviceOSX.h"
#include "IEventReceiver.h" #include "IEventReceiver.h"
#include "irrList.h"
#include "os.h" #include "os.h"
#include "CTimer.h" #include "CTimer.h"
#include "irrString.h" #include "irrString.h"

@ -8,7 +8,6 @@
#include "CIrrDeviceSDL.h" #include "CIrrDeviceSDL.h"
#include "IEventReceiver.h" #include "IEventReceiver.h"
#include "irrList.h"
#include "os.h" #include "os.h"
#include "CTimer.h" #include "CTimer.h"
#include "irrString.h" #include "irrString.h"

@ -12,7 +12,6 @@
#include "CIrrDeviceWin32.h" #include "CIrrDeviceWin32.h"
#include "IEventReceiver.h" #include "IEventReceiver.h"
#include "irrList.h"
#include "os.h" #include "os.h"
#include "CTimer.h" #include "CTimer.h"

@ -855,7 +855,7 @@ ISceneNode* CSceneManager::getSceneNodeFromName(const char* name, ISceneNode* st
ISceneNode* node = 0; ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren(); const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin(); ISceneNodeList::const_iterator it = list.begin();
for (; it!=list.end(); ++it) for (; it!=list.end(); ++it)
{ {
node = getSceneNodeFromName(name, *it); node = getSceneNodeFromName(name, *it);
@ -879,7 +879,7 @@ ISceneNode* CSceneManager::getSceneNodeFromId(s32 id, ISceneNode* start)
ISceneNode* node = 0; ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren(); const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin(); ISceneNodeList::const_iterator it = list.begin();
for (; it!=list.end(); ++it) for (; it!=list.end(); ++it)
{ {
node = getSceneNodeFromId(id, *it); node = getSceneNodeFromId(id, *it);
@ -903,7 +903,7 @@ ISceneNode* CSceneManager::getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, IS
ISceneNode* node = 0; ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren(); const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin(); ISceneNodeList::const_iterator it = list.begin();
for (; it!=list.end(); ++it) for (; it!=list.end(); ++it)
{ {
node = getSceneNodeFromType(type, *it); node = getSceneNodeFromType(type, *it);
@ -925,7 +925,7 @@ void CSceneManager::getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array<sce
outNodes.push_back(start); outNodes.push_back(start);
const ISceneNodeList& list = start->getChildren(); const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin(); ISceneNodeList::const_iterator it = list.begin();
for (; it!=list.end(); ++it) for (; it!=list.end(); ++it)
{ {