|
resonance 1.0.1
|
Ring buffer the movie stream reads its file through. More...
#include <acircbuff.h>
Public Member Functions | |
| ACircBuff (char *pBuff, int nSize) | |
| Take over a buffer of nSize bytes with both pointers at its start. | |
| int | Avail () |
| Report how many bytes can be written before the write pointer meets the read pointer. | |
| int | IsRoom (int nBytes) |
| Report whether nBytes fit in one contiguous write. | |
| void | WrapWriteIfOk () |
| Move the write pointer back to mBuff once it has reached mWrap, unless the read pointer is still at mBuff. | |
| char * | AdvanceRead (int nBytes) |
| Consume nBytes, wrapping the read pointer past mWrap. | |
| int | FullyRead (const char *pStart, int nBytes) const |
| Report whether the write pointer lies outside the nBytes starting at pStart. | |
| int | WillWriteWrap (int nBytes) const |
| Clamp nBytes to the space between the write pointer and mWrap. | |
| char * | AdvanceWrite (int nBytes) |
| Commit nBytes written at the write pointer. | |
| int | Write (const void *pSrc, int nBytes) |
| Copy nBytes into the buffer in one piece. | |
| int | Write (int nFile, int nBytes) |
| Read nBytes from a file into the buffer in one piece. | |
| void | Dump (const char *pszLabel) const |
| Log the pointers and the size under a label. | |
Public Attributes | |
| char * | mBuff |
| int | mBuffSize |
| char * | mWrite |
| char * | mRead |
| char * | mWrap |
Ring buffer the movie stream reads its file through.
The class is not polymorphic and emits no RTTI. Its name comes from the debugging symbols of the North American demo release. Its dump routine prints "circbuff:" and the member names pRead, pWrite, pWrap, pBuff, and buffsz. The movie stream's chunk error message calls the same object "pCircBuff". The buffer memory belongs to the caller, and the class never frees it.
Bytes are written at mWrite and consumed at mRead. mWrap marks the end of the usable region, and a pointer that reaches it wraps back to mBuff. A write pointer equal to the read pointer reports no free space rather than an empty buffer.
| ACircBuff::ACircBuff | ( | char * | pBuff, |
| int | nSize ) |
Take over a buffer of nSize bytes with both pointers at its start.
| pBuff | The buffer. |
| nSize | The buffer size in bytes. |
| int ACircBuff::Avail | ( | ) |
Report how many bytes can be written before the write pointer meets the read pointer.
One byte is always held back. A write pointer equal to the read pointer reports zero.
| int ACircBuff::IsRoom | ( | int | nBytes | ) |
Report whether nBytes fit in one contiguous write.
The routine has no caller.
| nBytes | The size to test. |
| void ACircBuff::WrapWriteIfOk | ( | ) |
Move the write pointer back to mBuff once it has reached mWrap, unless the read pointer is still at mBuff.
| char * ACircBuff::AdvanceRead | ( | int | nBytes | ) |
Consume nBytes, wrapping the read pointer past mWrap.
| nBytes | The number of bytes consumed. |
| int ACircBuff::FullyRead | ( | const char * | pStart, |
| int | nBytes ) const |
Report whether the write pointer lies outside the nBytes starting at pStart.
The range wraps past mWrap to mBuff.
| pStart | The start of the range. |
| nBytes | The length of the range. |
| int ACircBuff::WillWriteWrap | ( | int | nBytes | ) | const |
Clamp nBytes to the space between the write pointer and mWrap.
| nBytes | The size requested. |
| char * ACircBuff::AdvanceWrite | ( | int | nBytes | ) |
Commit nBytes written at the write pointer.
The write pointer wraps to mBuff once it reaches mWrap, unless the read pointer is still at mBuff.
| nBytes | The number of bytes written. |
| int ACircBuff::Write | ( | const void * | pSrc, |
| int | nBytes ) |
Copy nBytes into the buffer in one piece.
The routine has no caller.
The bytes go at the write pointer, or at mBuff when they do not fit before mWrap. Nothing is copied unless they fit short of the read pointer.
| pSrc | The bytes to copy. |
| nBytes | The number of bytes. |
| int ACircBuff::Write | ( | int | nFile, |
| int | nBytes ) |
Read nBytes from a file into the buffer in one piece.
The routine has no caller.
The placement rule is the one the other Write() uses. The count read() returns is ignored, and the write pointer advances by nBytes regardless.
| nFile | The file to read. |
| nBytes | The number of bytes. |
| void ACircBuff::Dump | ( | const char * | pszLabel | ) | const |
Log the pointers and the size under a label.
| pszLabel | The label printed first. |
| char* ACircBuff::mBuff |
Start of the buffer. +0x00
| int ACircBuff::mBuffSize |
Size of the buffer in bytes. +0x04
| char* ACircBuff::mWrite |
Where the next byte is written. +0x08
| char* ACircBuff::mRead |
Where the next byte is consumed. +0x0c
| char* ACircBuff::mWrap |
End of the usable region, mBuff plus mBuffSize. +0x10