sipxportlib  Version 3.3
CircularBuffer.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2015 SIPez LLC. All rights reserved.
3 //
4 // $$
6 #pragma once
7 #ifndef _CircularBuffer_h_
8 #define _CircularBuffer_h_
9 
10 // SYSTEM INCLUDES
11 
12 // APPLICATION INCLUDES
13 #include <os/OsMutex.h>
14 
15 // DEFINES
16 // MACROS
17 // EXTERNAL FUNCTIONS
18 // EXTERNAL VARIABLES
19 // CONSTANTS
20 // STRUCTS
21 // TYPEDEFS
22 // FORWARD DECLARATIONS
23 
24 //: Circular linked array of buffer data
25 // TBD
27 {
28 /* //////////////////////////// PUBLIC //////////////////////////////////// */
29 public:
30  typedef char ElementType;
31 /* ============================ CREATORS ================================== */
33 
34 
36  CircularBuffer(unsigned long capacity = 0);
44 
46 
47 /* ============================ MANIPULATORS ============================== */
49 
50 
51  void initialize(unsigned long capacity);
52  bool write(const ElementType * buffer, unsigned long bufferSize, unsigned long * newSize = 0,
53  unsigned long * previousSize = 0);
54  bool fill(ElementType value, unsigned long count, unsigned long * newSize = 0,
55  unsigned long * previousSize = 0);
56  unsigned long extract(ElementType * buffer, unsigned long bufferSize);
58 
59 /* ============================ ACCESSORS ================================= */
61 
62  unsigned long getSize();
64 
65 /* ============================ INQUIRY =================================== */
67 
68 
69 
70 /* //////////////////////////// PROTECTED ///////////////////////////////// */
71 
72 /* //////////////////////////// PRIVATE /////////////////////////////////// */
73 private:
74  const unsigned char mItemSize;
75  unsigned long mCapacity;
76  unsigned long mCount;
77  OsMutex mMutex;
78  ElementType * mBufferBegin;
79  ElementType * mBufferEnd;
80  ElementType * mHead;
81  ElementType * mTail;
82 
83  void pushBack(ElementType sample);
84  void free();
85  void eraseBegin(unsigned long count);
86 };
87 
88 /* ============================ INLINE METHODS ============================ */
89 #endif // _CircularBuffer_h_
90 
unsigned long extract(ElementType *buffer, unsigned long bufferSize)
Definition: CircularBuffer.cpp:185
unsigned long getSize()
Definition: CircularBuffer.cpp:232
void initialize(unsigned long capacity)
Definition: CircularBuffer.cpp:51
Definition: CircularBuffer.h:26
char ElementType
Definition: CircularBuffer.h:30
CircularBuffer(unsigned long capacity=0)
Default constructor.
Definition: CircularBuffer.cpp:30
bool write(const ElementType *buffer, unsigned long bufferSize, unsigned long *newSize=0, unsigned long *previousSize=0)
Definition: CircularBuffer.cpp:72
bool fill(ElementType value, unsigned long count, unsigned long *newSize=0, unsigned long *previousSize=0)
Definition: CircularBuffer.cpp:136
~CircularBuffer()
Definition: CircularBuffer.cpp:43