Commit 1a876af3 authored by cutealien's avatar cutealien

Allow getting a ConstIterator from a non-const core:list


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3061 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 6eb1fa1e
Changes in 1.7 Changes in 1.7
- Allow getting a ConstIterator from a non-const core:list
- Add swap functions to irrMath and to the core classes.
- Deprecate map::isEmpty() and replace it with map::empty() to make it similar to other base classes.
- Allow to set the logging level already in SIrrlichtCreationParameters.
- Add clearSystemMessages to devices (implemented only for Linux and Win32 so far). - Add clearSystemMessages to devices (implemented only for Linux and Win32 so far).
- Fix incorrect cursorpos for resizable windows on Windows Vista (found and patched by buffer) - Fix incorrect cursorpos for resizable windows on Windows Vista (found and patched by buffer)
......
...@@ -75,7 +75,7 @@ public: ...@@ -75,7 +75,7 @@ public:
T * operator ->() { return &Current->Element; } T * operator ->() { return &Current->Element; }
private: private:
Iterator(SKListNode* begin) : Current(begin) {} explicit Iterator(SKListNode* begin) : Current(begin) {}
SKListNode* Current; SKListNode* Current;
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
public: public:
ConstIterator() : Current(0) {} ConstIterator() : Current(0) {}
ConstIterator(const Iterator& iter) : Current(iter.Current) {}
ConstIterator& operator ++() { Current = Current->Next; return *this; } ConstIterator& operator ++() { Current = Current->Next; return *this; }
ConstIterator& operator --() { Current = Current->Prev; return *this; } ConstIterator& operator --() { Current = Current->Prev; return *this; }
...@@ -122,7 +123,7 @@ public: ...@@ -122,7 +123,7 @@ public:
ConstIterator & operator =(const Iterator & iterator) { Current = iterator.Current; return *this; } ConstIterator & operator =(const Iterator & iterator) { Current = iterator.Current; return *this; }
private: private:
ConstIterator(SKListNode* begin) : Current(begin) {} explicit ConstIterator(SKListNode* begin) : Current(begin) {}
SKListNode* Current; SKListNode* Current;
......
...@@ -8,13 +8,13 @@ using namespace core; ...@@ -8,13 +8,13 @@ using namespace core;
// list has no operator== currently so we have to check manually // list has no operator== currently so we have to check manually
// TODO: Add an operator== to core::list and the kick this function out // TODO: Add an operator== to core::list and the kick this function out
template <typename T> template <typename T>
static bool compareLists(core::list<T> & a, core::list<T> & b) static bool compareLists(const core::list<T> & a, const core::list<T> & b)
{ {
if ( a.size() != b.size() ) if ( a.size() != b.size() )
return false; return false;
// can't test allocator because we have no access to it here // can't test allocator because we have no access to it here
typename core::list<T>::Iterator iterA = a.begin(); // TODO: why can't we use ConstIterator here? Strange... this has to work! typename core::list<T>::ConstIterator iterA = a.begin();
typename core::list<T>::Iterator iterB = b.begin(); typename core::list<T>::ConstIterator iterB = b.begin();
for ( ; iterA != a.end(); ++iterA, ++iterB ) for ( ; iterA != a.end(); ++iterA, ++iterB )
{ {
if ( (*iterA) != (*iterB) ) if ( (*iterA) != (*iterB) )
...@@ -23,6 +23,17 @@ static bool compareLists(core::list<T> & a, core::list<T> & b) ...@@ -23,6 +23,17 @@ static bool compareLists(core::list<T> & a, core::list<T> & b)
return true; return true;
} }
// Make sure that we can get a const iterator from a non-const list
template <typename T>
static void constIteratorCompileTest(core::list<T> & a)
{
typename core::list<T>::ConstIterator iterA = a.begin();
while (iterA != a.end() )
{
++iterA;
}
}
static bool testSwap() static bool testSwap()
{ {
bool result = true; bool result = true;
...@@ -52,6 +63,9 @@ bool testIrrList(void) ...@@ -52,6 +63,9 @@ bool testIrrList(void)
{ {
bool success = true; bool success = true;
core::list<int> compileThisList;
constIteratorCompileTest(compileThisList);
success &= testSwap(); success &= testSwap();
if(success) if(success)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment