#include <CSeg.h>
Inheritance diagram for AxPipe::CSeg:
Public Member Functions | |
CSeg (size_t cbBuf=0, void *pvBuf=NULL, bool fReadOnly=false) | |
Default, and full-function, ctor for non-owned data (not deleted on destruction). | |
CSeg (size_t cbBuf, const void *pvBuf) | |
For constant data, and thus set ReadOnly true; Non-owned data (not deleted). | |
CSeg (const void *pvBuf, size_t cbLen, size_t cbGrowBuf=0) | |
Construct an owned buffer with a copy of provided data, possibly also in a larger buffer. | |
virtual | ~CSeg () |
Delete buffer if owned, Release() parent, if child and delete critical section. | |
unsigned char * | Ptr () |
Get the raw buffer pointer. | |
const unsigned char * | PtrRd () |
Get a read-only pointer to the valid data in the buffer, using m_cbOff. | |
unsigned char * | PtrWr () |
Get a writeable pointer to the valid data. | |
void * | PtrRelease () |
Get an independent free buffer with valid data and also Release(). | |
size_t | Size (void) |
Get the number of useable bytes in the buffer. | |
size_t | Len (void) |
Get the length of valid data in bytes in the segment. | |
CSeg * | Len (size_t cbLen) |
Set the length of valid data in bytes in the segment. | |
CSeg * | Writeable () |
Get a definitely writeable CSeg *, possibly a copy. | |
CSeg * | Drop (size_t cbOff) |
Drop cbOff bytes at the start of the buffer. | |
CSeg * | AddRef () |
Increment the reference count of this object. | |
int | Release () |
Decrement the reference count of this object. | |
int | Type () |
Get the type, an opaque user-defined non-zero integer. | |
CSeg * | SetType (int iType) |
Set the type, an opaque user-defined non-zero integer. | |
CSeg * | Clone () |
Make a clone of ourself. | |
virtual void * | RTClassId () |
Run-Time version of our type identification. | |
Static Public Member Functions | |
bool | IsSeg (CSeg *pSeg) |
Check if a segment pointer is valid reference to standard data. | |
void * | ClassId () |
Run-time type identifcation. | |
Private Member Functions | |
void | Init (size_t cbBuf, void *pvBuf, bool fReadOnly, int iType) |
Constructor helper, init's a CSeg appropriately. | |
CSeg & | operator= (CSeg &rhs) |
Make a dependent copy of the original. | |
Private Attributes | |
volatile LONG | m_iRefCnt |
Reference count. volatile due to InterlockedXXX req's. | |
CRITICAL_SECTION | m_CritSect |
This object may be shared among threads, thus needs this. | |
void * | m_pvBuf |
The raw data buffer pointer. Never changed once set. | |
size_t | m_cbBuf |
The raw data buffer size - not the same as how much valid data. | |
CSeg * | m_pMom |
Owning object, if this is a child. | |
bool | m_fOwnPtr |
True if this CSeg owns and manages the data buffer. | |
bool | m_fReadOnly |
True if this is a read-only object. | |
int | m_iType |
Opaque type indicator, free to use. Do note usage in AxPipe::eSegType. | |
size_t | m_cbOff |
Current offset from start of raw buffer to valid data. | |
size_t | m_cbLen |
Current number of valid bytes of raw data, starting at CSeg::m_cbOff. |
Objects of this kind *must* not be instantiated by any other means than 'new'. No arrays, no static, and no automatic. When the reference count falls to zero, they are deleted automagically.
You must *never* reference a pointer after a call to Release(). You must *never* 'delete' a pointer manually. Let Release() do it.
The default is that these objects are read-write. You can determine this by attempting to get a PtrWr(). If you get NULL, you must copy. You set them read-only by specifying this in the constructor.
A CSeg consists of a buffer, referenced by a pointer. The buffer may be owned by the CSeg object, or not. If it is, it'll be deleted when the last reference to the object is Released() 'd.
Not all of the buffer may consist valid data, the start in the buffer may be adjusted by an internally maintained offset, and the length of valid data by an internally maintained length of valid data starting from the offset.
General rule of usage: Always allocate with new - never create static or automatic CSeg objects, only through CAutoSeg When you pass a copy elsewhere, especially if it is potentially a different thread, call AddRef(). When you're done with your instance, call Release(). Never perform a 'delete' on a CSeg *. Never reference a CSeg after passing it anywhere without a prior AddRef() call!
CSeg's are thread safe in two ways. The reference count, m_iRefCnt, is only read and written using the InterlockedIncrement()/InterlockedDecrement() API which are inherently thread safe. In other functions, references to values that may be written at other times than object construction and initialization, a critical section is used as necessary to ensure thread safeness.
Definition at line 72 of file CSeg.h.
|
Default, and full-function, ctor for non-owned data (not deleted on destruction).
Definition at line 84 of file CSeg.cpp. Referenced by Writeable(). |
|
For constant data, and thus set ReadOnly true; Non-owned data (not deleted).
|
|
Construct an owned buffer with a copy of provided data, possibly also in a larger buffer.
|
|
Delete buffer if owned, Release() parent, if child and delete critical section. Never allocate a CSeg as auto or static. Note that the destructor does nothing - Release() does all the work, including delete this; Here we don't need a critical section, as the destructor is only called from within the class, and by definition only by one thread. With the exception of catastrophic internal error where the destructor is called prematurely, this is by definition thread-safe in the sense that only one thread should be active and attempt to destruct it. |
|
Increment the reference count of this object.
Definition at line 247 of file CSeg.cpp. References m_iRefCnt. Referenced by AxPipe::CSplit::PumpSplit(), AxPipe::CPipe::Work(), and Writeable(). |
|
Run-time type identifcation. We're not using the built in RTTI because we sometimes want to be able to forego most of the run time library, as well as exceptions and RTTI. The point here is to create a guaranteed unique value that is the same for all instances of a class, while not requiring any inits outside of the class declaration, and also to 'fool' optimizing compilers, so that they cannot perform global optimization and figure out that it can fold identical functions into one. It happened in a previous version... That's why we include the static int, it can't be optimized away, at least not easily. You need to override ClassId() and RTClassId() in all derived clases you want to distinguish, this is most easily done by simply copying and pasting exactly these definitions. There is also the Run-Time version, accessible through a pointer to a polymorphic base-class for example, RTClassId(). Reimplemented in AxPipe::CSegMap. Definition at line 329 of file CSeg.cpp. Referenced by RTClassId(). |
|
Make a clone of ourself. The result is a child copy of the original - they share the buffer, but have individual offsets and lengths.
Definition at line 306 of file CSeg.cpp. Referenced by AxPipe::Stock::CPipeHMAC_SHA1< iBits >::Out(), AxPipe::CPipeBlock::OutPump(), and AxPipe::CFilterBlock::ReadBlock(). |
|
Drop cbOff bytes at the start of the buffer. Don't Drop() more than Len() bytes.
Definition at line 237 of file CSeg.cpp. References m_cbOff, and m_CritSect. Referenced by AxPipe::Stock::CPipeHMAC_SHA1< iBits >::Out(), AxPipe::CPipeBlock::OutPump(), AxPipe::CFilterBlock::ReadBlock(), AxPipe::CFilterByte::ReadByte(), and AxPipe::CFilterByte::Skip(). |
|
Check if a segment pointer is valid reference to standard data. Checks for NULL pointer and non-default Type().
Definition at line 298 of file CSeg.cpp. References Type(). |
|
Set the length of valid data in bytes in the segment.
Definition at line 206 of file CSeg.cpp. References m_cbLen, m_cbOff, and m_CritSect. |
|
Get the length of valid data in bytes in the segment.
Definition at line 195 of file CSeg.cpp. References m_cbLen, m_cbOff, and m_CritSect. Referenced by AxPipe::CFilter::CoStartFilter(), AxPipe::CSink::DoSegWork(), AxPipe::CSource::Drain(), AxPipe::CFilterByte::GetNextSeg(), CJoinInterleave::In(), AxPipe::Stock::CPipeSHA1::Out(), AxPipe::Stock::CPipeInflate::Out(), AxPipe::Stock::CPipeHMAC_SHA1< iBits >::Out(), AxPipe::CSinkMemFile::Out(), AxPipe::CPipeBlock::OutPump(), PtrRelease(), AxPipe::CFilterBlock::ReadBlock(), AxPipe::CFilterByte::ReadByte(), AxPipe::CFilterByte::Skip(), and Writeable(). |
|
Make a dependent copy of the original. Copy by assignment makes a dependent copy of the original section. It inherits the buffer, but is considered a child of the original. Definition at line 61 of file CSeg.cpp. References m_cbBuf, m_cbLen, m_cbOff, m_CritSect, m_fOwnPtr, m_fReadOnly, m_pMom, and m_pvBuf. |
|
Get the raw buffer pointer. This is the raw buffer pointer, unaffected by offsets or anything else, and it's also not const or anything, regardless of read-only status.
Definition at line 133 of file CSeg.cpp. References m_pvBuf. |
|
Get a read-only pointer to the valid data in the buffer, using m_cbOff.
Definition at line 141 of file CSeg.cpp. References m_cbOff, m_CritSect, and m_pvBuf. Referenced by AxPipe::Stock::CPipeSHA1::Out(), AxPipe::Stock::CPipeInflate::Out(), AxPipe::CSinkMemFile::Out(), AxPipe::CPipeBlock::OutPump(), PtrRelease(), PtrWr(), AxPipe::CFilterBlock::ReadBlock(), AxPipe::CFilterByte::ReadByte(), and Writeable(). |
|
Get an independent free buffer with valid data and also Release(). You may not refer to this CSeg* again, as it will have been Release() 'd. It only returns the data known to be valid in the buffer, not the raw buffer. Do check the length with Len() first, to find how much data there is.
Definition at line 162 of file CSeg.cpp. References Len(), m_cbOff, m_CritSect, m_fOwnPtr, m_iRefCnt, m_pMom, m_pvBuf, PtrRd(), and Release(). |
|
Get a writeable pointer to the valid data. If you really need to get write-access to the buffer, use CSeg::Writeable().
Definition at line 152 of file CSeg.cpp. References m_fReadOnly, and PtrRd(). Referenced by AxPipe::Stock::CPipeInflate::Out(), AxPipe::CSinkMemFile::Out(), AxPipe::CPipeBlock::OutPump(), AxPipe::CFilterBlock::ReadBlock(), and Writeable(). |
|
Decrement the reference count of this object. Decrement the reference counter, and self destruct if it reaches zero. If we're a child of another base section, decrement that reference count if our reference reaches zero. Never reference a CSeg * after calling Release().
Definition at line 262 of file CSeg.cpp. References m_iRefCnt. Referenced by AxPipe::CSink::DoSegWork(), AxPipe::CSource::Drain(), AxPipe::CFilterByte::GetNextSeg(), AxPipe::CSource::Out(), AxPipe::Stock::CPipeInflate::Out(), AxPipe::CJoin::CTSinkJoin::Out(), AxPipe::CSinkMemFile::Out(), AxPipe::Stock::CPipeInflate::OutClose(), AxPipe::CPipeBlock::OutPump(), AxPipe::CSink::OutSpecial(), PtrRelease(), AxPipe::CPipe::Pump(), AxPipe::CFilterBlock::ReadBlock(), and AxPipe::CPipe::Work(). |
|
Run-Time version of our type identification.
Reimplemented in AxPipe::CSegMap. Definition at line 337 of file CSeg.cpp. References ClassId(). Referenced by AxPipe::CSinkMemFile::Out(). |
|
Set the type, an opaque user-defined non-zero integer.
Definition at line 290 of file CSeg.cpp. References m_iType. |
|
Get the number of useable bytes in the buffer. This is not necessarily the same as the Len() of the buffer, nor is it necessarily the same as the size of the raw buffer.
Definition at line 184 of file CSeg.cpp. References m_cbBuf, m_cbOff, and m_CritSect. Referenced by AxPipe::Stock::CPipeInflate::Out(). |
|
Get the type, an opaque user-defined non-zero integer. A CSeg may have an arbitrary int associated with it. The default is zero, but it may be set to any value by other classes, and it may be used for any purpose. AxPipe defines some reserved values in AxPipe::eSegType.
Definition at line 280 of file CSeg.cpp. References m_iType. Referenced by AxPipe::CSink::DoSegWork(), and IsSeg(). |
|
Get a definitely writeable CSeg *, possibly a copy. Make a writeable CSeg of ourselves. If we already are writeable, just return 'this' and increment the ref count. If we're readonly, make a new section and copy the valid data we have there.
Definition at line 220 of file CSeg.cpp. References AddRef(), CSeg(), Len(), m_CritSect, m_fReadOnly, PtrRd(), and PtrWr(). |