/*
- * 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();
} // namespace bear
template < class Item >
-bear::Queue<Item>::Queue()
+bear::Array<Item>::Array()
: m_uiStartSize(0),
m_uiSizeMultiplier(0),
m_uiAllocated(0),
}
template < class Item >
-void bear::Queue<Item>::init
+void bear::Array<Item>::init
(
unsigned int uiStartSize,
unsigned int uiSizeMultiplier
m_pTail = NULL;
}
template < class Item >
-void bear::Queue<Item>::fini()
+void bear::Array<Item>::fini()
{
m_uiStartSize = 0;
m_uiSizeMultiplier = 0;
}
template < class Item >
-void bear::Queue<Item>::alloc(unsigned int uiSize)
+void bear::Array<Item>::alloc(unsigned int uiSize)
{
if(NULL == m_pArrayItems)
{
}
template < class Item >
-void bear::Queue<Item>::trim()
+void bear::Array<Item>::trim()
{
unsigned int uiSize = getLength();
if(NULL == m_pArrayItems)
}
template < class Item >
-bool bear::Queue<Item>::isEmpty() const
+bool bear::Array<Item>::isEmpty() const
{
if ( NULL == m_pHead )
{
}
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());
}
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());
}
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 );
}
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 );
}
template < class Item >
-void bear::Queue<Item>::popFront()
+void bear::Array<Item>::popFront()
{
bear::DASSERT(!isEmpty());
}
template < class Item >
-void bear::Queue<Item>::popBack()
+void bear::Array<Item>::popBack()
{
bear::DASSERT(!isEmpty());
template < class Item >
-unsigned int bear::Queue<Item>::getLength() const
+unsigned int bear::Array<Item>::getLength() const
{
if ( isEmpty() )
{
}
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);
}
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;
}
template < class Item >
-void bear::Queue<Item>::allocForce(unsigned int uiSize)
+void bear::Array<Item>::allocForce(unsigned int uiSize)
{
unsigned int uiOldLength = getLength();
template < class Item >
-Item* bear::Queue<Item>::getNextHead
+Item* bear::Array<Item>::getNextHead
(
Item* pHead,
unsigned int uiAllocated,
}
template < class Item >
-Item* bear::Queue<Item>::getPrevHead
+Item* bear::Array<Item>::getPrevHead
(
Item* pHead,
unsigned int uiAllocated,
}
template < class Item >
-Item* bear::Queue<Item>::getNextTail
+Item* bear::Array<Item>::getNextTail
(
Item* pTail,
unsigned int uiAllocated,
}
template < class Item >
-Item* bear::Queue<Item>::getPrevTail
+Item* bear::Array<Item>::getPrevTail
(
Item* pTail,
unsigned int uiAllocated,
}
template < class Item >
-Item* bear::Queue<Item>::withinBounds
+Item* bear::Array<Item>::withinBounds
(
Item* pValue,
Item* pMinBound,
--- /dev/null
+/*
+ * 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