aboutsummaryrefslogtreecommitdiff
path: root/src/ringlist.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
committerMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
commitf7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54 (patch)
tree53cec4864776e07950e3c72f2a990a1017d08045 /src/ringlist.h
downloadlibbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.gz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.bz2
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.xz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.zip
libbu++ is finally laid out the way it should be, trunk, branches, and tags.
Diffstat (limited to '')
-rw-r--r--src/ringlist.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/ringlist.h b/src/ringlist.h
new file mode 100644
index 0000000..1a4d3a9
--- /dev/null
+++ b/src/ringlist.h
@@ -0,0 +1,112 @@
1#ifndef RINGLIST_H
2#define RINGLIST_H
3
4#include "list.h"
5
6/**
7 * A RingList or Ring Buffer implementation. This is a list that never grows in
8 * size once it is created, but instead once it is full new items added to the
9 * RingList replace the oldest items and the zero-index is virtually shifted.
10 * Since no data is actually moved when zero-index moves, this is very
11 * efficient.
12 * <br>
13 * The items removed are not actually deleted by the RingList, so instead they
14 * are first moved into a temporary "Push Buffer" that can be accessed so that
15 * elements pushed off the edge of the RingList can be accessed for cleanup.
16 *@author Mike Buland
17 */
18class RingList : public List
19{
20public:
21 /**
22 * Construct a RingList with a fixed initial size. This size never changes
23 * unless setSize is called later during normal operation.
24 *@param nInitSize The number of elements to allocate.
25 */
26 RingList( int nInitSize );
27
28 /**
29 * Clean up the data structures, but not the contained elements.
30 */
31 ~RingList();
32
33 /**
34 * Get an element at the specified index.
35 *@param nIndex The index of the element to retreive.
36 *@returns A pointer to the requested element, or NULL if the element is
37 * not found or not initialized yet.
38 */
39 void *getAt( int nIndex );
40
41 /**
42 * Append an element to the end of the list, overwriting the begining if
43 * necesarry.
44 *@param pData The pointer to append to the RingList.
45 */
46 void append( void *pData );
47
48 /**
49 * Insert an element before another in the RingList, pushing all after it
50 * down the list.
51 *@param pData The data to insert.
52 *@param nPos The position that new the element should occupy in the list.
53 */
54 void insertBefore( void *pData, int nPos = 0 );
55
56 /**
57 * Get the size of the array.
58 */
59 int getSize();
60
61 /**
62 * Is the RingList empty?
63 *@returns True if it is empty, false otherwise.
64 */
65 bool isEmpty();
66
67 /**
68 * Delete an element in the list, moving all later elements down one index.
69 *@param nIndex The index of the element to delete.
70 */
71 void deleteAt( int nIndex );
72
73 /**
74 * Remove all elements from the RingList.
75 */
76 void empty();
77
78 /**
79 * Set a new size for the RingList. Be careful with this one, if shrinking
80 * this may quietly create a memory leak.
81 *@param nNewSize The new size to set the RingList to.
82 *@todo Either fix this memory leak somehow or remove this function.
83 */
84 void setSize( int nNewSize );
85
86 /**
87 * Set a specific element to a new value.
88 *@param nIndex The zero-based index to change the value of.
89 *@param pData The data to put at the location specified by nIndex.
90 */
91 void setAt( int nIndex, void *pData );
92
93 /**
94 * Retrieve the contents of the push buffer. This is the data that is
95 * pushed off the end of the array if you append data and the list is full.
96 * This should be checked after every append operation to be sure there
97 * isn't anything that needs deleting.
98 *@returns The last value pushed off the RingList, or NULL if nothing was
99 * pushed off.
100 */
101 void *getPushBuf();
102
103private:
104 int nFirstIndex; /**< The index to be translated as zero. */
105 int nRealLength; /**< The Amount of storage space available. */
106 int nDataLength; /**< The number of elements filled in. */
107 void **apData; /**< The actual data storage. */
108 void *pPushBuf; /**< The push buffer. */
109
110};
111
112#endif