Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CP_PtrBlock Class Reference

Memory allocation class based on pointers. More...

List of all members.

Public Member Functions

Constructor / Destructor
 CP_PtrBlock ()
 Constructor.
 CP_PtrBlock (UInt32 inSize)
 CP_PtrBlock (CP_PtrBlock &inPtrBlock)
 CP_PtrBlock (Ptr inMacPtr, bool inOwnsPtr=true)
 ~CP_PtrBlock ()
 Destructor.
Copying
void CopyTo (void *ioBuffer, UInt32 inNumBytes) const
void CopyFrom (const void *inBuffer, UInt32 inNumBytes)
Getters
OSPtr GetOSPtr () const
char * GetPtr () const
Length
UInt32 Length () const
void SetLength (UInt32 inLength)
Locking
void Lock () const
void Unlock () const
bool IsLocked () const
Operators
CP_PtrBlockoperator= (const CP_PtrBlock &inPtrBlock)
 operator Ptr () const
Testers
bool IsValid () const
bool OwnsPtr () const
Wrapping
void Wrap (OSPtr inExistingPtr, bool inOwnsPtr=true)
void Detach ()

Protected Attributes

OSPtr fBlock
bool fOwnsPtr
bool fLocked
UInt32 fActualBlockLength

Private Member Functions

Allocation
void Allocate (UInt32 inSize)
void Deallocate ()


Detailed Description

A reference counted object to manage blocks of memory using pointers.


Constructor & Destructor Documentation

CPLAT_Begin_Namespace_CPLAT CP_PtrBlock::CP_PtrBlock  ) 
 

Constructor.

Exceptions:
none 

CP_PtrBlock::CP_PtrBlock UInt32  inSize  )  [explicit]
 

Constructor.

Parameters:
inSize The size of the desired memory allocation in bytes.
Exceptions:
none 

CP_PtrBlock::CP_PtrBlock CP_PtrBlock inPtrBlock  )  [explicit]
 

Copy constructor. Ownership of the memory block will be handled according to the inOwnershipOptions parameter.

Parameters:
inPtrBlock The object to copy.
inOwnershipOptions How to handle ownership of the new and old blocks.
Exceptions:
none 

CP_PtrBlock::CP_PtrBlock Ptr  inMacPtr,
bool  inOwnsPtr = true
[explicit]
 

Constructor.

Parameters:
inMacPtr An existing MacOS Ptr to assign to this object.
inOwnsHandle Flag to indicate if this class becomes responsible for the deletion of the OSHandle.
Exceptions:
none 

CP_PtrBlock::~CP_PtrBlock  ) 
 

Destructor.

Exceptions:
none 


Member Function Documentation

void CP_PtrBlock::CopyTo void *  ioBuffer,
UInt32  inNumBytes
const
 

Copies the passed in number of bytes of this memory block to the passed in destination buffer. The copy will start at the beginning of the memory block.

Parameters:
ioBuffer Points to the location the bytes will be copied to.
inNumBytes The number of bytes to copy.
Exceptions:
none 
Returns:
void

void CP_PtrBlock::CopyFrom const void *  inBuffer,
UInt32  inNumBytes
 

Copies the passed in number of bytes from the passed in buffer to this block of memory, starting at the first byte of this memory block.

Parameters:
inBuffer Points to the location of the bytes to copy from.
inNumBytes The number of bytes to copy.
Exceptions:
none 
Returns:
void

OSPtr CP_PtrBlock::GetOSPtr  )  const
 

Geturn the memory block.

char * CP_PtrBlock::GetPtr  )  const
 

Returns the pointer to the memory block of this object. Will implicitely lock the block, so you'll need to call Unlock() before you can resize the block.

Exceptions:
none 
Returns:
char A char * for the memory of this object.

UInt32 CP_PtrBlock::Length  )  const
 

Returns the length of this memory block.

Exceptions:
OSErr OSErr if there is a problem getting length.
Returns:
The length of the memory block

void CP_PtrBlock::SetLength UInt32  inLength  ) 
 

Set the length of the memory block. This will cause the platforms memory block to be resized to accommodate these changes.

Parameters:
inLength The length to resize this memory block to.
Exceptions:
std::bad_alloc OSError if out of memory or setting length failed because block is locked.
OSErr OSError if setting length failed for other reasons.
Returns:
void

void CP_PtrBlock::Lock  )  const
 

Locks the platforms OSPtr if necessary.

Exceptions:
none 
Returns:
void

void CP_PtrBlock::Unlock  )  const
 

Unlocks the platforms OSPtr.

Exceptions:
none 
Returns:
void

bool CP_PtrBlock::IsLocked  )  const
 

Returns true if the memory block is locked.

Exceptions:
none 
Returns:
bool Returns true if the memory block is locked.

CP_PtrBlock & CP_PtrBlock::operator= const CP_PtrBlock inPtrBlock  ) 
 

Assignment operator. This will cause the memory of the source block to be copied into a new block.

Exceptions:
none 
Returns:
void

CP_PtrBlock::operator Ptr  )  const
 

Returns the MacOS Handle.

Exceptions:
none 
Returns:
OSHandle

bool CP_PtrBlock::IsValid  )  const
 

Returns true if the memory block is not NULL.

Exceptions:
none 
Returns:
bool Returns true if the memory block is not NULL.

bool CP_PtrBlock::OwnsPtr  )  const
 

Returns true if this object owns the block of memory, and is therefore responsible for its deletion. Otherwise the memory block held by this object will not be deleted by this class.

Exceptions:
none 
Returns:
bool Returns true if this object owns the memory handle.

void CP_PtrBlock::Wrap OSPtr  inExistingPtr,
bool  inOwnsPtr = true
 

Wrap ourselves around an existing platforms OSPtr. If inOwnsPtr is true, then this object takes over ownership of the OSPtr and will be responsible for deleting the memory.

Parameters:
inExistingPtr The existing OSPtr to take ownership of.
inOwnsPtr Flag to indicate if this class takes on ownership of the handle, and will be responsible for its deletion.
Exceptions:
none 
Returns:
void

void CP_PtrBlock::Detach  ) 
 

Notifies this class that it no longer owns the memory, and will not delete it. You are now responsible for deleting the memory to avoid a memory leak.

Exceptions:
none 
Returns:
void

void CP_PtrBlock::Allocate UInt32  inSize  )  [private]
 

Private routine to handle the allocation of the platforms memory block.

Parameters:
inSize The desired size of the memory allocation.
Exceptions:
NULL NULL exception if the memory can't be allocated.
Returns:
void

void CP_PtrBlock::Deallocate  )  [private]
 

Private routine to handle the deallocation of the platforms memory block. This will only happen if this object owns the allocated memory, otherwise you are responsible for the deallocation of the memory.

Exceptions:
none 
Returns:
void


Member Data Documentation

OSPtr CP_PtrBlock::fBlock [protected]
 

bool CP_PtrBlock::fOwnsPtr [protected]
 

Platforms memory object.

bool CP_PtrBlock::fLocked [mutable, protected]
 

Flag to indicate who is responsible for deleting the platforms memory.

UInt32 CP_PtrBlock::fActualBlockLength [protected]
 

Flag to indicate if the block is locked.


The documentation for this class was generated from the following files:
Generated on Tue Sep 20 20:22:00 2005 for CPLAT_MacOS by  doxygen 1.4.0