Commit 96b59dd2 authored by hybrid's avatar hybrid

Some const fixes from CaptainPants. Warning fix in PPM loader.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@999 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 71b4579b
......@@ -676,7 +676,7 @@ public:
{
IGUIElement* e = 0;
core::list<IGUIElement*>::Iterator it = Children.begin();
core::list<IGUIElement*>::ConstIterator it = Children.begin();
for (; it != Children.end(); ++it)
{
if ((*it)->getID() == id)
......@@ -727,7 +727,7 @@ public:
if (wanted==-2)
wanted = 1073741824; // maximum s32
core::list<IGUIElement*>::Iterator it = Children.begin();
core::list<IGUIElement*>::ConstIterator it = Children.begin();
s32 closestOrder, currentOrder;
......
......@@ -81,7 +81,7 @@ namespace irr
//! You will not have to drop the pointer to the loaded texture, because
//! the name of the method does not start with 'create'. The texture
//! is stored somewhere by the driver.
void grab() { ++ReferenceCounter; }
void grab() const { ++ReferenceCounter; }
//! Drops the object. Decrements the reference counter by one.
//! Returns true, if the object was deleted.
......@@ -109,7 +109,7 @@ namespace irr
//! You will not have to drop the pointer to the loaded texture, because
//! the name of the method does not start with 'create'. The texture
//! is stored somewhere by the driver.
bool drop()
bool drop() const
{
_IRR_DEBUG_BREAK_IF(ReferenceCounter <= 0) // someone is doing bad reference counting.
......@@ -149,7 +149,7 @@ namespace irr
private:
s32 ReferenceCounter;
mutable s32 ReferenceCounter;
const c8* DebugName;
};
......
......@@ -29,66 +29,105 @@ private:
};
public:
class ConstIterator;
//! List iterator.
class Iterator
{
public:
Iterator() : Current(0) {}
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 ++() { 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) const { 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:
Iterator(SKListNode* begin) : Current(begin) {}
SKListNode* Current;
friend class list<T>;
};
Iterator operator+(s32 num) const
class ConstIterator
{
Iterator tmp = *this;
public:
if (num >= 0)
while (num-- && tmp.Current != 0) ++tmp;
else
while (num++ && tmp.Current != 0) --tmp;
ConstIterator() : Current(0) {}
return tmp;
}
ConstIterator& operator ++() { Current = Current->Next; return *this; }
ConstIterator& operator --() { Current = Current->Prev; return *this; }
ConstIterator operator ++(s32) { Iterator tmp = *this; Current = Current->Next; return tmp; }
ConstIterator operator --(s32) { Iterator tmp = *this; Current = Current->Prev; return tmp; }
Iterator& operator+=(s32 num)
ConstIterator& operator +=(s32 num)
{
if (num >= 0)
while (num-- && this->Current != 0) ++(*this);
if(num > 0)
{
while(num-- && this->Current != 0) ++(*this);
}
else
while (num++ && this->Current != 0) --(*this);
{
while(num++ && this->Current != 0) --(*this);
}
return *this;
}
Iterator operator-(s32 num) const { return (*this)+(-num); }
Iterator operator-=(s32 num) const { (*this)+=(-num); return *this; }
ConstIterator operator + (s32 num) const { ConstIterator tmp = *this; return tmp += num; }
ConstIterator& operator -=(s32 num) const { return (*this)+=(-num); }
ConstIterator 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; }
bool operator ==(const Iterator& other) const { return Current == other.Current; }
bool operator !=(const Iterator& other) const { return Current != other.Current; }
T& operator *() { return Current->Element; };
const T & operator * () { return Current->Element; }
const T * operator ->() { return &Current->Element; }
ConstIterator & operator =(const Iterator & iterator) { Current = iterator.Current; return *this; }
private:
ConstIterator(SKListNode* begin) : Current(begin) {}
Iterator(SKListNode* begin) : Current(begin) {};
SKListNode* Current;
friend class list<T>;
SKListNode* Current;
};
//! constructor
list()
: Root(0), Last(0), Size(0) {}
: First(0), Last(0), Size(0) {}
//! copy constructor
list(const list<T>& other) : Root(0), Last(0), Size(0)
list(const list<T>& other) : First(0), Last(0), Size(0)
{
*this = other;
}
......@@ -101,13 +140,17 @@ public:
}
//! Assignment operator
void operator=(const list<T>& other)
{
if(&other == this)
{
return;
}
clear();
SKListNode* node = other.Root;
SKListNode* node = other.First;
while(node)
{
push_back(node->Element);
......@@ -130,15 +173,14 @@ public:
//! iterators of this list will be invalid.
void clear()
{
SKListNode* node = Root;
while(node)
while(First)
{
SKListNode* next = node->Next;
delete node;
node = next;
SKListNode * next = First->Next;
delete First;
First = next;
}
Root = 0;
//First = 0; handled by loop
Last = 0;
Size = 0;
}
......@@ -149,7 +191,7 @@ public:
//! \return Returns true if the list is empty and false if not.
bool empty() const
{
return (Root == 0);
return (First == 0);
}
......@@ -163,8 +205,8 @@ public:
++Size;
if (Root == 0)
Root = node;
if (First == 0)
First = node;
node->Prev = Last;
......@@ -184,49 +226,73 @@ public:
++Size;
if (Root == 0)
if (First == 0)
{
Last = node;
Root = node;
First = node;
}
else
{
node->Next = Root;
Root->Prev = node;
Root = node;
node->Next = First;
First->Prev = node;
First = node;
}
}
//! Gets begin node.
//! \return Returns a list iterator pointing to the begin of the list.
Iterator begin()
{
return Iterator(First);
}
//! Gets begin node.
//! \return Returns a list iterator pointing to the begin of the list.
Iterator begin() const
ConstIterator begin() const
{
return Iterator(Root);
return ConstIterator(First);
}
//! Gets end node.
//! \return Returns a list iterator pointing to null.
Iterator end() const
Iterator end()
{
return Iterator(0);
}
//! Gets end node.
//! \return Returns a list iterator pointing to null.
ConstIterator end() const
{
return ConstIterator(0);
}
//! Gets last element.
//! \return Returns a list iterator pointing to the end of the list.
Iterator getLast() const
Iterator getLast()
{
return Iterator(Last);
}
//! Gets last element.
//! \return Returns a list iterator pointing to the end 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(Iterator& it, const T& element)
void insert_after(const Iterator& it, const T& element)
{
SKListNode* node = new SKListNode;
node->Element = element;
......@@ -249,7 +315,7 @@ public:
//! \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(Iterator& it, const T& element)
void insert_before(const Iterator& it, const T& element)
{
SKListNode* node = new SKListNode;
node->Element = element;
......@@ -263,8 +329,8 @@ public:
it.Current->Prev = node;
++Size;
if (it.Current == Root)
Root = node;
if (it.Current == First)
First = node;
}
......@@ -273,20 +339,29 @@ public:
//! \return Returns 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 == Root)
Root = it.Current->Next;
if(it.Current == First)
{
First = it.Current->Next;
}
else
{
it.Current->Prev->Next = it.Current->Next;
}
if (it.Current == Last)
if(it.Current == Last)
{
Last = it.Current->Prev;
if (it.Current->Next)
}
else
{
it.Current->Next->Prev = it.Current->Prev;
if (it.Current->Prev)
it.Current->Prev->Next = it.Current->Next;
}
delete it.Current;
it.Current = 0;
......@@ -297,7 +372,7 @@ public:
private:
SKListNode* Root;
SKListNode* First;
SKListNode* Last;
u32 Size;
......
......@@ -88,7 +88,7 @@ void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node
{
Node->updateAbsolutePosition();
core::list<ISceneNode*>::Iterator it = Node->getChildren().begin();
core::list<ISceneNode*>::ConstIterator it = Node->getChildren().begin();
for (; it != Node->getChildren().end(); ++it)
{
helper_updateAbsolutePositionOfAllChildren( (*it) );
......
......@@ -462,7 +462,7 @@ void CColladaFileLoader::readNodeSection(io::IXMLReaderUTF8* reader, scene::ISce
if (node && newnode)
{
// move children from dummy to new node
core::list<ISceneNode*>::Iterator it = node->getChildren().begin();
core::list<ISceneNode*>::ConstIterator it = node->getChildren().begin();
for (; it != node->getChildren().end(); it = node->getChildren().begin())
(*it)->setParent(newnode);
......
......@@ -827,7 +827,7 @@ void CGUIEnvironment::writeGUIElement(io::IXMLWriter* writer, IGUIElement* node)
// write children
core::list<IGUIElement*>::Iterator it = node->getChildren().begin();
core::list<IGUIElement*>::ConstIterator it = node->getChildren().begin();
for (; it != node->getChildren().end(); ++it)
{
if (!(*it)->isSubElement())
......
......@@ -34,7 +34,7 @@ CGUIToolBar::CGUIToolBar(IGUIEnvironment* environment, IGUIElement* parent, s32
parentwidth = Parent->getAbsolutePosition().getWidth();
const core::list<IGUIElement*>& children = parent->getChildren();
core::list<IGUIElement*>::Iterator it = children.begin();
core::list<IGUIElement*>::ConstIterator it = children.begin();
for (; it != children.end(); ++it)
{
core::rect<s32> r = (*it)->getAbsolutePosition();
......
......@@ -78,14 +78,14 @@ IImage* CImageLoaderPPM::loadImage(io::IReadFile* file) const
const u32 bytesize = size/8+(size & 3)?1:0;
if (binary)
{
if (file->getSize()-file->getPos() < bytesize)
if (file->getSize()-file->getPos() < (long)bytesize)
return 0;
data = new u8[bytesize];
file->read(data, bytesize);
}
else
{
if (file->getSize()-file->getPos() < 2*size) // optimistic test
if (file->getSize()-file->getPos() < (long)(2*size)) // optimistic test
return 0;
data = new u8[bytesize];
memset(data, 0, bytesize);
......@@ -116,7 +116,7 @@ IImage* CImageLoaderPPM::loadImage(io::IReadFile* file) const
{
if (binary)
{
if (file->getSize()-file->getPos() < size)
if (file->getSize()-file->getPos() < (long)size)
return 0;
data = new u8[size];
file->read(data, size);
......@@ -135,7 +135,7 @@ IImage* CImageLoaderPPM::loadImage(io::IReadFile* file) const
}
else
{
if (file->getSize()-file->getPos() < 2*size) // optimistic test
if (file->getSize()-file->getPos() < (long)(2*size)) // optimistic test
return 0;
image = new CImage(ECF_A8R8G8B8, core::dimension2d<s32>(width, height));
if (image)
......@@ -158,7 +158,7 @@ IImage* CImageLoaderPPM::loadImage(io::IReadFile* file) const
const u32 bytesize = 3*size;
if (binary)
{
if (file->getSize()-file->getPos() < bytesize)
if (file->getSize()-file->getPos() < (long)bytesize)
return 0;
data = new u8[bytesize];
file->read(data, bytesize);
......@@ -177,7 +177,7 @@ IImage* CImageLoaderPPM::loadImage(io::IReadFile* file) const
}
else
{
if (file->getSize()-file->getPos() < 2*bytesize) // optimistic test
if (file->getSize()-file->getPos() < (long)(2*bytesize)) // optimistic test
return 0;
image = new CImage(ECF_A8R8G8B8, core::dimension2d<s32>(width, height));
if (image)
......
......@@ -532,7 +532,7 @@ void CParticleSystemSceneNode::serializeAttributes(io::IAttributes* out, io::SAt
E_PARTICLE_AFFECTOR_TYPE atype = EPAT_NONE;
for (core::list<IParticleAffector*>::Iterator it = AffectorList.begin();
for (core::list<IParticleAffector*>::ConstIterator it = AffectorList.begin();
it != AffectorList.end(); ++it)
{
atype = (*it)->getType();
......
......@@ -82,7 +82,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root,
const core::list<ISceneNode*>& children = root->getChildren();
core::list<ISceneNode*>::Iterator it = children.begin();
core::list<ISceneNode*>::ConstIterator it = children.begin();
for (; it != children.end(); ++it)
{
ISceneNode* current = *it;
......
......@@ -1502,7 +1502,7 @@ ISceneNode* CSceneManager::getSceneNodeFromName(const char* name, ISceneNode* st
ISceneNode* node = 0;
const core::list<ISceneNode*>& list = start->getChildren();
core::list<ISceneNode*>::Iterator it = list.begin();
core::list<ISceneNode*>::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
node = getSceneNodeFromName(name, *it);
......@@ -1526,7 +1526,7 @@ ISceneNode* CSceneManager::getSceneNodeFromId(s32 id, ISceneNode* start)
ISceneNode* node = 0;
const core::list<ISceneNode*>& list = start->getChildren();
core::list<ISceneNode*>::Iterator it = list.begin();
core::list<ISceneNode*>::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
node = getSceneNodeFromId(id, *it);
......@@ -1550,7 +1550,7 @@ ISceneNode* CSceneManager::getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, IS
ISceneNode* node = 0;
const core::list<ISceneNode*>& list = start->getChildren();
core::list<ISceneNode*>::Iterator it = list.begin();
core::list<ISceneNode*>::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
node = getSceneNodeFromType(type, *it);
......@@ -1571,7 +1571,7 @@ void CSceneManager::getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array<sce
outNodes.push_back(start);
const core::list<ISceneNode*>& list = start->getChildren();
core::list<ISceneNode*>::Iterator it = list.begin();
core::list<ISceneNode*>::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
......@@ -2067,7 +2067,7 @@ void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISc
writer->writeElement(animatorElement);
writer->writeLineBreak();
core::list<ISceneNodeAnimator*>::Iterator it = node->getAnimators().begin();
core::list<ISceneNodeAnimator*>::ConstIterator it = node->getAnimators().begin();
for (; it != node->getAnimators().end(); ++it)
{
attr->clear();
......@@ -2107,7 +2107,7 @@ void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISc
// write children
core::list<ISceneNode*>::Iterator it = node->getChildren().begin();
core::list<ISceneNode*>::ConstIterator it = node->getChildren().begin();
for (; it != node->getChildren().end(); ++it)
writeSceneNode(writer, (*it), userDataSerializer);
......
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