summaryrefslogtreecommitdiff
path: root/src/ringlist.cpp
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.cpp
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 'src/ringlist.cpp')
-rw-r--r--src/ringlist.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/ringlist.cpp b/src/ringlist.cpp
new file mode 100644
index 0000000..9efbbc4
--- /dev/null
+++ b/src/ringlist.cpp
@@ -0,0 +1,106 @@
1//
2// C++ Implementation: ringlist
3//
4// Description:
5//
6//
7// Author: Mike Buland <eichlan@yf-soft.com>, (C) 2005
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <stdlib.h>
13
14#include "ringlist.h"
15
16RingList::RingList( int nInitSize )
17 : List()
18{
19 nFirstIndex = 0;
20 nRealLength = nInitSize;
21 nDataLength = 0;
22 apData = new void*[nInitSize];
23 pPushBuf = NULL;
24}
25
26RingList::~RingList()
27{
28 delete[] apData;
29}
30
31void *RingList::getAt( int nIndex )
32{
33 if( nIndex < 0 || nIndex >= nDataLength )
34 {
35 return NULL;
36 }
37
38 return apData[(nFirstIndex+nIndex)%nRealLength];
39}
40
41void RingList::append( void *pData )
42{
43 int nIndex = (nFirstIndex+nDataLength)%nRealLength;
44
45 pPushBuf = apData[nIndex];
46 apData[nIndex] = pData;
47
48 if( nDataLength == nRealLength )
49 {
50 nFirstIndex = (nFirstIndex+1)%nRealLength;
51 }
52 else
53 {
54 nDataLength++;
55 // We really didn't need it this time...
56 pPushBuf = NULL;
57 }
58}
59
60void RingList::insertBefore( void *pData, int nPos )
61{
62 // Not implemented right now, don't even try it!
63}
64
65int RingList::getSize()
66{
67 return nDataLength;
68}
69
70bool RingList::isEmpty()
71{
72 return nDataLength==0;
73}
74
75void RingList::deleteAt( int nIndex )
76{
77 // Also not implemented yet
78}
79
80void RingList::empty()
81{
82 nFirstIndex = 0;
83 nDataLength = 0;
84}
85
86void RingList::setSize( int nNewSize )
87{
88 if( apData )
89 {
90 delete[] apData;
91 }
92 nFirstIndex = 0;
93 nRealLength = nNewSize;
94 nDataLength = 0;
95 apData = new void*[nNewSize];
96}
97
98void RingList::setAt( int nIndex, void *pData )
99{
100 apData[(nIndex+nFirstIndex)%nRealLength] = pData;
101}
102
103void *RingList::getPushBuf()
104{
105 return pPushBuf;
106}