CRingBuffer Class Reference

#include <RingBuffer.h>

List of all members.

Public Member Functions

 CRingBuffer (void)
 CRingBuffer (int rsz, int dsz)
virtual ~CRingBuffer (void)
BOOL init (int ring_size, int data_size)
void free (void)
void clear (void)
void * get (void)
void * get (int pos)
void put (void *ptr)
void put (void *ptr, int pos)

Public Attributes

int state
BOOL enable

Protected Member Functions

void init_data (void)

Protected Attributes

void ** buf
int bufsz
int datasz
int spoint
int epoint
int datano

Detailed Description

Definition at line 22 of file RingBuffer.h.


Constructor & Destructor Documentation

CRingBuffer ( void   )  [inline]

Definition at line 25 of file RingBuffer.h.

References CRingBuffer::init_data().

00025 { init_data();}

Here is the call graph for this function:

CRingBuffer ( int  rsz,
int  dsz 
) [inline]

Definition at line 26 of file RingBuffer.h.

References CRingBuffer::init().

00026 { init(rsz, dsz);}

Here is the call graph for this function:

virtual ~CRingBuffer ( void   )  [inline, virtual]

Definition at line 27 of file RingBuffer.h.

References CRingBuffer::free().

00027 { free();}

Here is the call graph for this function:


Member Function Documentation

void clear ( void   ) 

Definition at line 79 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, CRingBuffer::datano, CRingBuffer::datasz, CRingBuffer::epoint, CRingBuffer::spoint, and CRingBuffer::state.

00080 {
00081     for (int i=0; i<bufsz; i++) {
00082         memset(buf[i], 0, datasz);
00083     }
00084     spoint  = 0;
00085     epoint  = 0;
00086     datano  = 0;
00087     state   = 0;
00088 
00089     return;
00090 }

void free ( void   ) 

Definition at line 62 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, CRingBuffer::init_data(), and jbxl::isNull().

Referenced by CRingBuffer::init(), and CRingBuffer::~CRingBuffer().

00063 {
00064     if (!isNull(buf)) {
00065         for (int i=0; i<bufsz; i++) {
00066             if (!isNull(buf[i])) {
00067                 ::free(buf[i]);
00068             }
00069         }
00070         ::free(buf);
00071     }    
00072     init_data();
00073 
00074     return;
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

void * get ( int  pos  ) 

Definition at line 110 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, and CRingBuffer::epoint.

00111 {
00112     pos = epoint + pos;
00113     if (pos<0) pos = bufsz + pos % bufsz;
00114     else       pos = pos % bufsz;
00115 
00116     return buf[pos];
00117 }

void * get ( void   ) 

Definition at line 94 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, CRingBuffer::datano, and CRingBuffer::spoint.

00095 {
00096     void* ptr = NULL;
00097 
00098     if (datano>0) {
00099         ptr = buf[spoint];
00100         spoint++;
00101         if (spoint==bufsz) spoint = 0;
00102         datano--;
00103     }
00104 
00105     return ptr;
00106 }

BOOL init ( int  ring_size,
int  data_size 
)

Definition at line 33 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, CRingBuffer::datasz, CRingBuffer::enable, FALSE, CRingBuffer::free(), CRingBuffer::init_data(), CRingBuffer::state, and TRUE.

Referenced by CRingBuffer::CRingBuffer().

00034 {
00035     init_data();
00036 
00037     buf = (void**)malloc(ring_size*sizeof(void*));
00038     if (buf==NULL) return FALSE;
00039     memset(buf, 0, ring_size*sizeof(void*));
00040     bufsz  = ring_size;
00041     datasz = data_size;
00042 
00043     BOOL ret = TRUE;
00044     for (int i=0; i<bufsz; i++) {
00045         buf[i] = (void*)malloc(datasz);
00046         if (buf[i]==NULL) {
00047             this->free();
00048             ret = FALSE;
00049             state = -1;
00050             break;
00051         }
00052         memset(buf[i], 0, datasz);
00053     }
00054 
00055     if (ret) enable = TRUE;
00056 
00057     return ret;
00058 }

Here is the call graph for this function:

Here is the caller graph for this function:

void init_data ( void   )  [protected]

Definition at line 19 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, CRingBuffer::datano, CRingBuffer::datasz, CRingBuffer::enable, CRingBuffer::epoint, FALSE, CRingBuffer::spoint, and CRingBuffer::state.

Referenced by CRingBuffer::CRingBuffer(), CRingBuffer::free(), and CRingBuffer::init().

00020 {
00021     buf     = NULL;
00022     bufsz   = 0;
00023     datasz  = 0;
00024     spoint  = 0;
00025     epoint  = 0;
00026     datano  = 0;
00027     state   = 0;
00028     enable  = FALSE;
00029 }

Here is the caller graph for this function:

void put ( void *  ptr,
int  pos 
)

Definition at line 133 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, CRingBuffer::datasz, and CRingBuffer::epoint.

00134 {
00135     pos = epoint + pos;
00136     if (pos<0) pos = bufsz + pos % bufsz;
00137     else       pos = pos % bufsz;
00138 
00139     memcpy(buf[pos], ptr, datasz);
00140 
00141     return;
00142 }

void put ( void *  ptr  ) 

Definition at line 121 of file RingBuffer.cpp.

References CRingBuffer::buf, CRingBuffer::bufsz, CRingBuffer::datano, CRingBuffer::datasz, and CRingBuffer::epoint.

00122 {
00123     memcpy(buf[epoint], ptr, datasz);
00124     epoint++;
00125     if (epoint==bufsz) epoint = 0;
00126     if (datano<bufsz)  datano++;
00127 
00128     return;
00129 }


Member Data Documentation

void** buf [protected]
int bufsz [protected]
int datano [protected]
int datasz [protected]
BOOL enable

Definition at line 40 of file RingBuffer.h.

Referenced by CRingBuffer::init(), and CRingBuffer::init_data().

int epoint [protected]
int spoint [protected]

Definition at line 34 of file RingBuffer.h.

Referenced by CRingBuffer::clear(), CRingBuffer::get(), and CRingBuffer::init_data().

int state

Definition at line 39 of file RingBuffer.h.

Referenced by CRingBuffer::clear(), CRingBuffer::init(), and CRingBuffer::init_data().


The documentation for this class was generated from the following files:

Generated on 15 Nov 2023 for JunkBox_Lib++ (for Windows) by  doxygen 1.6.1