An implementation of a circular array allowing direct write and read.
CircularArray.h@0:28766f5a758e, 2014-02-11 (annotated)
- Committer:
- GLemasson
- Date:
- Tue Feb 11 18:41:26 2014 +0000
- Revision:
- 0:28766f5a758e
- Child:
- 1:5036a532fe62
An implementation of a circular array allowing drirect read and write
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GLemasson | 0:28766f5a758e | 1 | |
GLemasson | 0:28766f5a758e | 2 | #ifndef _CIRCULAR_ARRAY_H_ |
GLemasson | 0:28766f5a758e | 3 | #define _CIRCULAR_ARRAY_H_ |
GLemasson | 0:28766f5a758e | 4 | |
GLemasson | 0:28766f5a758e | 5 | template<typename T> class CircularArray |
GLemasson | 0:28766f5a758e | 6 | { |
GLemasson | 0:28766f5a758e | 7 | private: |
GLemasson | 0:28766f5a758e | 8 | unsigned int m_capacity; |
GLemasson | 0:28766f5a758e | 9 | volatile unsigned int w; |
GLemasson | 0:28766f5a758e | 10 | volatile unsigned int r; |
GLemasson | 0:28766f5a758e | 11 | volatile bool m_full; |
GLemasson | 0:28766f5a758e | 12 | volatile bool m_empty; |
GLemasson | 0:28766f5a758e | 13 | volatile T * data; |
GLemasson | 0:28766f5a758e | 14 | |
GLemasson | 0:28766f5a758e | 15 | public: |
GLemasson | 0:28766f5a758e | 16 | CircularArray(unsigned int capacity); |
GLemasson | 0:28766f5a758e | 17 | ~CircularArray(); |
GLemasson | 0:28766f5a758e | 18 | T * getWritePointer(); |
GLemasson | 0:28766f5a758e | 19 | T * getReadPointer(T * buffer=0,unsigned int num=0); |
GLemasson | 0:28766f5a758e | 20 | void writeElements(unsigned int num); |
GLemasson | 0:28766f5a758e | 21 | void readElements(unsigned int num); |
GLemasson | 0:28766f5a758e | 22 | unsigned int fillCapacity(); |
GLemasson | 0:28766f5a758e | 23 | unsigned int freeSpace(); |
GLemasson | 0:28766f5a758e | 24 | unsigned int size(); |
GLemasson | 0:28766f5a758e | 25 | unsigned int readable(); |
GLemasson | 0:28766f5a758e | 26 | bool full(); |
GLemasson | 0:28766f5a758e | 27 | bool empty(); |
GLemasson | 0:28766f5a758e | 28 | }; |
GLemasson | 0:28766f5a758e | 29 | |
GLemasson | 0:28766f5a758e | 30 | #endif |