aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/array.cpp2
-rw-r--r--src/array.h78
-rw-r--r--src/list.h15
3 files changed, 95 insertions, 0 deletions
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 @@
1#include "bu/array.h"
2
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 @@
1#ifndef BU_ARRAY_H
2#define BU_ARRAY_H
3
4#include <memory>
5#include "bu/exceptionbase.h"
6
7namespace Bu
8{
9 /**
10 * Array type container, just like a normal array only flexible and keeps
11 * track of your memory for you.
12 *
13 *@param value (typename) The type of data to store in your list
14 *@param valuealloc (typename) Memory Allocator for your value type
15 *@param linkalloc (typename) Memory Allocator for the list links.
16 */
17 template<typename value, int inc=10, typename valuealloc=std::allocator<value> >
18 class Array
19 {
20 private:
21 typedef class Array<value, inc, valuealloc> MyType;
22
23 public:
24 Array() :
25 pData( NULL ),
26 iSize( 0 ),
27 iCapacity( 0 )
28 {
29 }
30
31 Array( const MyType &src ) :
32 pData( NULL ),
33 iSize( 0 ),
34 iCapacity( 0 )
35 {
36 // for( Link *pCur = src.pFirst; pCur; pCur = pCur->pNext )
37 // {
38 // append( *pCur->pValue );
39 // }
40 }
41
42 ~Array()
43 {
44 clear();
45 }
46
47 /**
48 * Clear the data from the list.
49 */
50 void clear()
51 {
52 }
53
54 operator
55
56 /**
57 * Get the current size of the list.
58 *@returns (int) The current size of the list.
59 */
60 int getSize() const
61 {
62 return iSize;
63 }
64
65 int getCapacity() const
66 {
67 return iCapacity;
68 }
69
70 private:
71 valuealloc va;
72 value *pData;
73 int iSize;
74 int iCapacity;
75 };
76}
77
78#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
91 nSize = 0; 91 nSize = 0;
92 } 92 }
93 93
94 void enqueue( const value &v )
95 {
96 append( v );
97 }
98
99 value dequeue()
100 {
101 value v = *pFirst->pValue;
102
103 erase( begin() );
104
105 return v;
106 }
107
108
94 /** 109 /**
95 * Append a value to the list. 110 * Append a value to the list.
96 *@param v (const value_type &) The value to append. 111 *@param v (const value_type &) The value to append.