diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-09-05 16:20:48 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-09-05 16:20:48 +0000 |
commit | c4176c4dc172e8b30536a4eb90ae6f6f80f75436 (patch) | |
tree | fc49547f3c48ecb400fd9c972ee745beef7e0216 | |
parent | a3cb276a2b048ce94b04e95b3ac87f323e075712 (diff) | |
download | libbu++-c4176c4dc172e8b30536a4eb90ae6f6f80f75436.tar.gz libbu++-c4176c4dc172e8b30536a4eb90ae6f6f80f75436.tar.bz2 libbu++-c4176c4dc172e8b30536a4eb90ae6f6f80f75436.tar.xz libbu++-c4176c4dc172e8b30536a4eb90ae6f6f80f75436.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/array.cpp | 2 | ||||
-rw-r--r-- | src/array.h | 78 | ||||
-rw-r--r-- | src/list.h | 15 |
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 | |||
7 | namespace 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 | ||
@@ -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. |