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

CP_MacOSPtr Class Reference

Memory allocation class based on pointers. More...

Inheritance diagram for CP_MacOSPtr:

CP_M_RefCounted List of all members.

Public Member Functions

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

Protected Attributes

Ptr 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_MacOSPtr::CP_MacOSPtr  ) 
 

Constructor.

Exceptions:
none 

CP_MacOSPtr::CP_MacOSPtr UInt32  inSize  ) 
 

Constructor.

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

CP_MacOSPtr::CP_MacOSPtr CP_MacOSPtr inPtrBlock  ) 
 

Copy constructor.

Parameters:
inPtrBlock The object to copy the fields from. This will increase the reference count of the passed in handle block, since the copying operation will now point to the same memory block of OS memory.
Exceptions:
none 

CP_MacOSPtr::CP_MacOSPtr Ptr  inMacPtr,
bool  inOwnsPtr = true
 

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_MacOSPtr::~CP_MacOSPtr  ) 
 

Destructor.

Exceptions:
none 


Member Function Documentation

void CP_MacOSPtr::CopyTo void *  inBuffer,
UInt32  inNumBytes
const
 

Returns a char * to the actual bytes of this memory.

Exceptions:
none 
Returns:
char * Points to the first byte in the memory block.

void CP_MacOSPtr::CopyFrom void *  ioBuffer,
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:
ioBuffer Points to the location of the bytes to copy from.
inNumBytes The number of bytes to copy.
Exceptions:
none 
Returns:
void

Ptr CP_MacOSPtr::GetOSPtr  ) 
 

Returns the OS memory block.

Exceptions:
none 
Returns:
Ptr The OS memory block.

char * CP_MacOSPtr::GetPtr  ) 
 

Returns the OSPtr for the memory block of this object. If this object still owns this memory, be careful not to delete the OSPtr, otherwise there will be a problem when this object tries to release the already released memory.

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

UInt32 CP_MacOSPtr::Length  )  const
 

Returns the length of this memory block.

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

void CP_MacOSPtr::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:
OSErr OSError if setting length failed.
Returns:
void

void CP_MacOSPtr::Lock  ) 
 

Locks the platforms OSPtr if necessary.

Exceptions:
none 
Returns:
void

void CP_MacOSPtr::Unlock  ) 
 

Unlocks the platforms OSPtr.

Exceptions:
none 
Returns:
void

bool CP_MacOSPtr::IsLocked  ) 
 

Returns true if the memory block is locked.

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

CP_MacOSPtr & CP_MacOSPtr::operator= CP_MacOSPtr inPtrBlock  ) 
 

Assignment operator. This will cause any memory in this object to be deallocated first, if we own the handle. Then the OS memory block will point to that of the passed in handle block object. The passed in handle block objects reference count will also be increased, since the underlying OSHandle is now shareed by this class.

Exceptions:
none 
Returns:
void

CP_MacOSPtr::operator Ptr  ) 
 

Returns the MacOS Handle.

Exceptions:
none 
Returns:
OSHandle

bool CP_MacOSPtr::IsValid  ) 
 

Returns true if the memory block is not NULL.

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

bool CP_MacOSPtr::OwnsPtr  ) 
 

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_MacOSPtr::Wrap Ptr  inExistingPtr,
bool  inOwnsPtr = true
 

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

Parameters:
inExistingPtr The existing Ptr to take ownership of.
inOwnsHandle 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_MacOSPtr::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_MacOSPtr::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_MacOSPtr::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

UInt32 CP_M_RefCounted::AddReference  )  const [inherited]
 

Add a reference to our object, returning the new reference count.

Exceptions:
none 
Returns:
UInt32 const Returns the new reference count.

UInt32 CP_M_RefCounted::RemoveReference  )  const [inherited]
 

Remove a reference to our object, returning the new reference count. If the count is 0, then this object is also deleted, and 0 is returned.

Exceptions:
none 
Returns:
UInt32 const Returns the new reference count.

void CP_M_RefCounted::Autorelease  )  const [inherited]
 

Add the object to the topmost auto-release pool. This will ensure that the object is eventually released.

See also:
CP_AutoReleasePool
Exceptions:
none 
Returns:
void

UInt32 CP_M_RefCounted::GetRefCount  )  const [inherited]
 

Returns the current ref count.

Exceptions:
none 
Returns:
UInt32 The current referencce count.


Member Data Documentation

Ptr CP_MacOSPtr::fBlock [protected]
 

bool CP_MacOSPtr::fOwnsPtr [protected]
 

Platforms memory object.

bool CP_MacOSPtr::fLocked [protected]
 

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

UInt32 CP_MacOSPtr::fActualBlockLength [protected]
 

Flag to indicate if the block is locked.


The documentation for this class was generated from the following files:
Generated on Sat Sep 17 20:01:49 2005 for CPLAT by  doxygen 1.4.0