summaryrefslogtreecommitdiff
path: root/src/stable/ringbuffer.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-05-03 06:30:36 +0000
committerMike Buland <eichlan@xagasoft.com>2012-05-03 06:30:36 +0000
commitdf6a899ad6c9a1c792582ef1a3b838c7eb6d330c (patch)
treeff9e17d0fd00585bc1e329a63c20f90d155b4ea8 /src/stable/ringbuffer.h
parent343bffafecd4329ce5ae6625fc6b2c1ea9759f36 (diff)
downloadlibbu++-df6a899ad6c9a1c792582ef1a3b838c7eb6d330c.tar.gz
libbu++-df6a899ad6c9a1c792582ef1a3b838c7eb6d330c.tar.bz2
libbu++-df6a899ad6c9a1c792582ef1a3b838c7eb6d330c.tar.xz
libbu++-df6a899ad6c9a1c792582ef1a3b838c7eb6d330c.zip
Rearranging some stuff.
Diffstat (limited to 'src/stable/ringbuffer.h')
-rw-r--r--src/stable/ringbuffer.h35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/stable/ringbuffer.h b/src/stable/ringbuffer.h
index d4b5993..79c5a15 100644
--- a/src/stable/ringbuffer.h
+++ b/src/stable/ringbuffer.h
@@ -67,16 +67,15 @@ namespace Bu
67 iStart = 0; 67 iStart = 0;
68 iEnd = 1; 68 iEnd = 1;
69 va.construct( &aData[0], v ); 69 va.construct( &aData[0], v );
70 return;
70 } 71 }
71 else if( iStart == iEnd ) 72 else if( iStart == iEnd )
72 { 73 {
73 throw ExceptionBase("Hey, it's full!"); 74 // The ringbuffer is full
74 } 75 dequeue();
75 else
76 {
77 va.construct( &aData[iEnd], v );
78 iEnd = (iEnd+1)%iCapacity;
79 } 76 }
77 va.construct( &aData[iEnd], v );
78 iEnd = (iEnd+1)%iCapacity;
80 } 79 }
81 80
82 value dequeue() 81 value dequeue()
@@ -104,6 +103,16 @@ namespace Bu
104 return aData[(iIndex+iStart)%iCapacity]; 103 return aData[(iIndex+iStart)%iCapacity];
105 } 104 }
106 105
106 value &first()
107 {
108 return aData[iStart];
109 }
110
111 value &last()
112 {
113 return aData[(iEnd-1+iCapacity)%iCapacity];
114 }
115
107 int getSize() 116 int getSize()
108 { 117 {
109 if( iStart < 0 ) 118 if( iStart < 0 )
@@ -201,6 +210,20 @@ namespace Bu
201 return core->get( 0 ); 210 return core->get( 0 );
202 } 211 }
203 212
213 virtual value &first()
214 {
215 _hardCopy();
216
217 return core->first();
218 }
219
220 virtual value &last()
221 {
222 _hardCopy();
223
224 return core->last();
225 }
226
204 value &operator[]( int iIndex ) 227 value &operator[]( int iIndex )
205 { 228 {
206 _hardCopy(); 229 _hardCopy();