From c4176c4dc172e8b30536a4eb90ae6f6f80f75436 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 5 Sep 2007 16:20:48 +0000 Subject: This commit has part of an Array class, I'm just not sure I really need it right now. Unfortunately it doesn't compile right now, if you want to build this version, just delete array. On the other hand, Bu::List now has enqueue/dequeue functions. --- src/array.cpp | 2 ++ src/array.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/list.h | 15 ++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/array.cpp create mode 100644 src/array.h (limited to 'src') diff --git a/src/array.cpp b/src/array.cpp new file mode 100644 index 0000000..f80a99c --- /dev/null +++ b/src/array.cpp @@ -0,0 +1,2 @@ +#include "bu/array.h" + diff --git a/src/array.h b/src/array.h new file mode 100644 index 0000000..cd0d7da --- /dev/null +++ b/src/array.h @@ -0,0 +1,78 @@ +#ifndef BU_ARRAY_H +#define BU_ARRAY_H + +#include +#include "bu/exceptionbase.h" + +namespace Bu +{ + /** + * Array type container, just like a normal array only flexible and keeps + * track of your memory for you. + * + *@param value (typename) The type of data to store in your list + *@param valuealloc (typename) Memory Allocator for your value type + *@param linkalloc (typename) Memory Allocator for the list links. + */ + template > + class Array + { + private: + typedef class Array MyType; + + public: + Array() : + pData( NULL ), + iSize( 0 ), + iCapacity( 0 ) + { + } + + Array( const MyType &src ) : + pData( NULL ), + iSize( 0 ), + iCapacity( 0 ) + { + // for( Link *pCur = src.pFirst; pCur; pCur = pCur->pNext ) + // { + // append( *pCur->pValue ); + // } + } + + ~Array() + { + clear(); + } + + /** + * Clear the data from the list. + */ + void clear() + { + } + + operator + + /** + * Get the current size of the list. + *@returns (int) The current size of the list. + */ + int getSize() const + { + return iSize; + } + + int getCapacity() const + { + return iCapacity; + } + + private: + valuealloc va; + value *pData; + int iSize; + int iCapacity; + }; +} + +#endif diff --git a/src/list.h b/src/list.h index 839494d..ec0c195 100644 --- a/src/list.h +++ b/src/list.h @@ -91,6 +91,21 @@ namespace Bu nSize = 0; } + void enqueue( const value &v ) + { + append( v ); + } + + value dequeue() + { + value v = *pFirst->pValue; + + erase( begin() ); + + return v; + } + + /** * Append a value to the list. *@param v (const value_type &) The value to append. -- cgit v1.2.3