diff options
Diffstat (limited to 'src/array.h')
-rw-r--r-- | src/array.h | 78 |
1 files changed, 78 insertions, 0 deletions
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 | ||