changed queue to array and abstracted a deque from it
authorPatrik Gornicz <Gornicz.P@gmail.com>
Wed, 2 Sep 2009 02:56:11 +0000 (22:56 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Wed, 2 Sep 2009 02:56:11 +0000 (22:56 -0400)
lib/include/bear/Array.h [moved from lib/include/bear/Queue.h with 89% similarity]
lib/include/bear/Deque.h [new file with mode: 0644]
physics/src/entityCreator.cpp

similarity index 89%
rename from lib/include/bear/Queue.h
rename to lib/include/bear/Array.h
index ba0e5cb..5b8d56d 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * File:   Queue.h
+ * File:   Array.h
  * Author: patrik
  *
  * Created on August 1, 2009, 7:12 PM
 #include "debug.h"
 #include "mathw.h"
 
-// HACK
-#ifndef NULL
-#define NULL 0
-#endif
-
 namespace bear
 {
   /// ***** Header Class *****
 
   template < class Item >
-  class Queue
+  class Array
   {
   public:
-     Queue();
-    ~Queue() {}
+    Array();
+    virtual ~Array() {}
 
     void init(unsigned int uiStartSize = 8, unsigned int uiSizeMultiplier = 2);
     void fini();
@@ -74,7 +69,7 @@ namespace bear
 } // namespace bear
 
 template < class Item >
-bear::Queue<Item>::Queue()
+bear::Array<Item>::Array()
     :   m_uiStartSize(0),
         m_uiSizeMultiplier(0),
         m_uiAllocated(0),
@@ -86,7 +81,7 @@ bear::Queue<Item>::Queue()
 }
 
 template < class Item >
-void bear::Queue<Item>::init
+void bear::Array<Item>::init
 (
   unsigned int uiStartSize,
   unsigned int uiSizeMultiplier
@@ -109,7 +104,7 @@ void bear::Queue<Item>::init
   m_pTail             = NULL;
 }
 template < class Item >
-void bear::Queue<Item>::fini()
+void bear::Array<Item>::fini()
 {
   m_uiStartSize       = 0;
   m_uiSizeMultiplier  = 0;
@@ -127,7 +122,7 @@ void bear::Queue<Item>::fini()
 }
 
 template < class Item >
-void bear::Queue<Item>::alloc(unsigned int uiSize)
+void bear::Array<Item>::alloc(unsigned int uiSize)
 {
   if(NULL == m_pArrayItems)
   {
@@ -144,7 +139,7 @@ void bear::Queue<Item>::alloc(unsigned int uiSize)
 }
 
 template < class Item >
-void bear::Queue<Item>::trim()
+void bear::Array<Item>::trim()
 {
   unsigned int uiSize = getLength();
   if(NULL == m_pArrayItems)
@@ -162,7 +157,7 @@ void bear::Queue<Item>::trim()
 }
 
 template < class Item >
-bool bear::Queue<Item>::isEmpty() const
+bool bear::Array<Item>::isEmpty() const
 {
   if ( NULL == m_pHead )
   {
@@ -177,7 +172,7 @@ bool bear::Queue<Item>::isEmpty() const
 }
 
 template < class Item >
-const Item& bear::Queue<Item>::getFront() const
+const Item& bear::Array<Item>::getFront() const
 {
   // This is very bad. Fix your code
   bear::DASSERT(!isEmpty());
@@ -189,7 +184,7 @@ const Item& bear::Queue<Item>::getFront() const
 }
 
 template < class Item >
-const Item& bear::Queue<Item>::getBack() const
+const Item& bear::Array<Item>::getBack() const
 {
   // This is very bad. Fix your code
   bear::DASSERT(!isEmpty());
@@ -201,7 +196,7 @@ const Item& bear::Queue<Item>::getBack() const
 }
 
 template < class Item >
-void bear::Queue<Item>::pushFront(const Item& i)
+void bear::Array<Item>::pushFront(const Item& i)
 {
   // Make sure we have the space to add an item
   allocWhenNeeded( getLength() + 1 );
@@ -220,7 +215,7 @@ void bear::Queue<Item>::pushFront(const Item& i)
 }
 
 template < class Item >
-void bear::Queue<Item>::pushBack(const Item& i)
+void bear::Array<Item>::pushBack(const Item& i)
 {
   // Make sure we have the space to add an item
   allocWhenNeeded( getLength() + 1 );
@@ -239,7 +234,7 @@ void bear::Queue<Item>::pushBack(const Item& i)
 }
 
 template < class Item >
-void bear::Queue<Item>::popFront()
+void bear::Array<Item>::popFront()
 {
   bear::DASSERT(!isEmpty());
 
@@ -255,7 +250,7 @@ void bear::Queue<Item>::popFront()
 }
 
 template < class Item >
-void bear::Queue<Item>::popBack()
+void bear::Array<Item>::popBack()
 {
   bear::DASSERT(!isEmpty());
 
@@ -272,7 +267,7 @@ void bear::Queue<Item>::popBack()
 
 
 template < class Item >
-unsigned int bear::Queue<Item>::getLength() const
+unsigned int bear::Array<Item>::getLength() const
 {
   if ( isEmpty() )
   {
@@ -285,7 +280,7 @@ unsigned int bear::Queue<Item>::getLength() const
 }
 
 template < class Item >
-void bear::Queue<Item>::allocFirstTime(unsigned int uiSize)
+void bear::Array<Item>::allocFirstTime(unsigned int uiSize)
 {
   // santiy checks
   bear::DASSERT(0 == m_uiAllocated);
@@ -303,7 +298,7 @@ void bear::Queue<Item>::allocFirstTime(unsigned int uiSize)
 }
 
 template < class Item >
-void bear::Queue<Item>::allocWhenNeeded(unsigned int uiSize)
+void bear::Array<Item>::allocWhenNeeded(unsigned int uiSize)
 {
   unsigned int uiSizeNeeded = (0 == m_uiAllocated) ? m_uiStartSize : m_uiAllocated;
 
@@ -322,7 +317,7 @@ void bear::Queue<Item>::allocWhenNeeded(unsigned int uiSize)
 }
 
 template < class Item >
-void bear::Queue<Item>::allocForce(unsigned int uiSize)
+void bear::Array<Item>::allocForce(unsigned int uiSize)
 {
   unsigned int    uiOldLength     = getLength();
 
@@ -371,7 +366,7 @@ void bear::Queue<Item>::allocForce(unsigned int uiSize)
 
 
 template < class Item >
-Item*    bear::Queue<Item>::getNextHead
+Item*    bear::Array<Item>::getNextHead
 (
   Item*           pHead,
   unsigned int    uiAllocated,
@@ -382,7 +377,7 @@ Item*    bear::Queue<Item>::getNextHead
 }
 
 template < class Item >
-Item*    bear::Queue<Item>::getPrevHead
+Item*    bear::Array<Item>::getPrevHead
 (
   Item*           pHead,
   unsigned int    uiAllocated,
@@ -393,7 +388,7 @@ Item*    bear::Queue<Item>::getPrevHead
 }
 
 template < class Item >
-Item*    bear::Queue<Item>::getNextTail
+Item*    bear::Array<Item>::getNextTail
 (
   Item*           pTail,
   unsigned int    uiAllocated,
@@ -404,7 +399,7 @@ Item*    bear::Queue<Item>::getNextTail
 }
 
 template < class Item >
-Item*    bear::Queue<Item>::getPrevTail
+Item*    bear::Array<Item>::getPrevTail
 (
   Item*           pTail,
   unsigned int    uiAllocated,
@@ -415,7 +410,7 @@ Item*    bear::Queue<Item>::getPrevTail
 }
 
 template < class Item >
-Item*    bear::Queue<Item>::withinBounds
+Item*    bear::Array<Item>::withinBounds
 (
   Item* pValue,
   Item* pMinBound,
diff --git a/lib/include/bear/Deque.h b/lib/include/bear/Deque.h
new file mode 100644 (file)
index 0000000..27c8886
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * File:   Deque.h
+ * Author: patrik
+ *
+ * Created on August 1, 2009, 7:12 PM
+ */
+
+#pragma once
+
+#include "debug.h"
+#include "mathw.h"
+#include "Array.h"
+
+namespace bear
+{
+  /// ***** Header Class *****
+
+  template < class Item >
+  class Deque : protected Array<Item>
+  {
+    typedef Array<Item> inherited;
+  public:
+    Deque() : inherited()   {}
+    virtual ~Deque()        {}
+
+    using inherited::init;
+    using inherited::fini;
+
+    using inherited::alloc;
+    using inherited::trim;
+
+    using inherited::isEmpty;
+
+    using inherited::getFront;
+    using inherited::getBack;
+
+    using inherited::pushFront;
+    using inherited::pushBack;
+
+    using inherited::popFront;
+    using inherited::popBack;
+  };
+
+} // namespace bear
index 3f749e7..79ac89b 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "entityCreator.h"
 
-#include <bear/Queue.h>
+#include <bear/Deque.h>
 
 #include "entityManager.h"
 #include "input/inputManager.h"
@@ -29,8 +29,8 @@
 
 /// ***** Private Variables *****
 
-typedef bear::Queue<Ball*>      queBall;
-typedef bear::Queue<Polygon*>   quePoly;
+typedef bear::Deque<Ball*>      queBall;
+typedef bear::Deque<Polygon*>   quePoly;
 
 static queBall s_startBalls;
 static queBall s_mouseBalls;