diff options
Diffstat (limited to 'src/old/ringlist.cpp')
-rw-r--r-- | src/old/ringlist.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/old/ringlist.cpp b/src/old/ringlist.cpp new file mode 100644 index 0000000..9efbbc4 --- /dev/null +++ b/src/old/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 | |||
16 | RingList::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 | |||
26 | RingList::~RingList() | ||
27 | { | ||
28 | delete[] apData; | ||
29 | } | ||
30 | |||
31 | void *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 | |||
41 | void 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 | |||
60 | void RingList::insertBefore( void *pData, int nPos ) | ||
61 | { | ||
62 | // Not implemented right now, don't even try it! | ||
63 | } | ||
64 | |||
65 | int RingList::getSize() | ||
66 | { | ||
67 | return nDataLength; | ||
68 | } | ||
69 | |||
70 | bool RingList::isEmpty() | ||
71 | { | ||
72 | return nDataLength==0; | ||
73 | } | ||
74 | |||
75 | void RingList::deleteAt( int nIndex ) | ||
76 | { | ||
77 | // Also not implemented yet | ||
78 | } | ||
79 | |||
80 | void RingList::empty() | ||
81 | { | ||
82 | nFirstIndex = 0; | ||
83 | nDataLength = 0; | ||
84 | } | ||
85 | |||
86 | void 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 | |||
98 | void RingList::setAt( int nIndex, void *pData ) | ||
99 | { | ||
100 | apData[(nIndex+nFirstIndex)%nRealLength] = pData; | ||
101 | } | ||
102 | |||
103 | void *RingList::getPushBuf() | ||
104 | { | ||
105 | return pPushBuf; | ||
106 | } | ||