whitespace edits
[blender-staging.git] / source / gameengine / SceneGraph / SG_QList.h
index 4a254ac36a4747ba3f5aff00b0467652cc5205ae..eb404b1a5a5cef89623735b8b0cc381b9dd9869a 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+
+/** \file SG_QList.h
+ *  \ingroup bgesg
+ */
 #ifndef __SG_QLIST
 #define __SG_QLIST
 
@@ -49,20 +54,24 @@ public:
                T*                      m_current;
        public:
                typedef iterator<T> _myT;
-               iterator(SG_QList& head) : m_head(head), m_current(NULL) {}
+               iterator(SG_QList& head, SG_QList* current=NULL) : m_head(head) { m_current = (T*)current; }
                ~iterator() {}
 
                void begin()
                {
                        m_current = (T*)m_head.QPeek();
-                       if (m_current == (T*)m_head.Self())
-                       {
-                               m_current = NULL;
-                       }
+               }
+               void back()
+               {
+                       m_current = (T*)m_head.QBack();
                }
                bool end()
                {
-                       return (NULL == m_current);
+                       return (m_current == (T*)m_head.Self());
+               }
+               bool add_back(T* item)
+               {
+                       return m_current->QAddBack(item);
                }
                T* operator*()
                {
@@ -70,78 +79,90 @@ public:
                }
                _myT& operator++()
                {
-                       assert(m_current);
                        m_current = (T*)m_current->QPeek();
-                       if (m_current == (T*)m_head.Self())
-                       {
-                               m_current = NULL;
-                       }
+                       return *this;
+               }
+               _myT& operator--()
+               {
+                       // no check on NULL! make sure you don't try to increment beyond end
+                       m_current = (T*)m_current->QBack();
                        return *this;
                }
        };
 
        SG_QList() : SG_DList()
-    { 
-        m_fqlink = m_bqlink = this; 
-    }
+       {
+               m_fqlink = m_bqlink = this;
+       }
        SG_QList(const SG_QList& other) : SG_DList()
        {
-        m_fqlink = m_bqlink = this; 
+               m_fqlink = m_bqlink = this;
        }
-    virtual ~SG_QList() 
-    {
+       virtual ~SG_QList()
+       {
                QDelink();
-    }
+       }
 
-    inline bool QEmpty()               // Check for empty queue
-    {     
-        return ( m_fqlink == this ); 
-    }
-    bool QAddBack( SG_QList *item )  // Add to the back
-    {
+       inline bool QEmpty()               // Check for empty queue
+       {
+               return ( m_fqlink == this );
+       }
+       bool QAddBack( SG_QList *item )  // Add to the back
+       {
                if (!item->QEmpty())
                        return false;
-        item->m_bqlink = m_bqlink;
-        item->m_fqlink = this;
-        m_bqlink->m_fqlink = item;
-        m_bqlink = item;
+               item->m_bqlink = m_bqlink;
+               item->m_fqlink = this;
+               m_bqlink->m_fqlink = item;
+               m_bqlink = item;
                return true;
-    }
-    bool QAddFront( SG_QList *item )  // Add to the back
-    {
+       }
+       bool QAddFront( SG_QList *item )  // Add to the back
+       {
                if (!item->Empty())
                        return false;
-        item->m_fqlink = m_fqlink;
-        item->m_bqlink = this;
-        m_fqlink->m_bqlink = item;
-        m_fqlink = item;
+               item->m_fqlink = m_fqlink;
+               item->m_bqlink = this;
+               m_fqlink->m_bqlink = item;
+               m_fqlink = item;
                return true;
-    }
-    SG_QList *QRemove()           // Remove from the front
-    {
-        if (QEmpty()) 
-        {
-            return NULL;
-        }
-        SG_QList* item = m_fqlink;
-        m_fqlink = item->m_fqlink;
-        m_fqlink->m_bqlink = this;
-        item->m_fqlink = item->m_bqlink = item;
-        return item;
-    }
-    void QDelink()             // Remove from the middle
-    {
-               if (!QEmpty())
+       }
+       SG_QList *QRemove()           // Remove from the front
+       {
+               if (QEmpty())
                {
-                       m_bqlink->m_fqlink = m_fqlink;
-                       m_fqlink->m_bqlink = m_bqlink;
-                       m_fqlink = m_bqlink = this;
+                       return NULL;
                }
-    }
-    inline SG_QList *QPeek()                   // Look at front without removing
-    { 
-        return m_fqlink; 
-    }  
+               SG_QList* item = m_fqlink;
+               m_fqlink = item->m_fqlink;
+               m_fqlink->m_bqlink = this;
+               item->m_fqlink = item->m_bqlink = item;
+               return item;
+       }
+       bool QDelink()             // Remove from the middle
+       {
+               if (QEmpty())
+                       return false;
+               m_bqlink->m_fqlink = m_fqlink;
+               m_fqlink->m_bqlink = m_bqlink;
+               m_fqlink = m_bqlink = this;
+               return true;
+       }
+       inline SG_QList *QPeek()                        // Look at front without removing
+       {
+               return m_fqlink;
+       }
+       inline SG_QList *QBack()                        // Look at front without removing
+       {
+               return m_bqlink;
+       }
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+public:
+       void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_QList"); }
+       void operator delete( void *mem ) { MEM_freeN(mem); }
+#endif
 };
 
 #endif //__SG_QLIST