sbMemoryUtils.h File Reference
#include <nsMemory.h>
#include <stdlib.h>
Include dependency graph for sbMemoryUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  sbAutoFreeXPCOMPointerArray< T >
 
class  sbAutoFreeXPCOMArrayByRef< T >
 
class  sbAutoFreeXPCOMArray< T >
 
class  sbAutoNSMemPtr
 
class  sbAutoMemPtr< T >
 
class  sbAutoNSTypePtr< T >
 
class  sbAutoNSArray< T >
 

Macros

#define SB_AUTO_CLASS2(aName, aType, aType2, aIsValid, aDispose, aInvalidate)
 
#define SB_AUTO_CLASS(aName, aType, aIsValid, aDispose, aInvalidate)   SB_AUTO_CLASS2(aName, aType, char, aIsValid, aDispose, aInvalidate)
 
#define SB_AUTO_NULL_CLASS(aName, aType, aDispose)   SB_AUTO_CLASS(aName, aType, mValue != NULL, aDispose, mValue = NULL)
 

Functions

template<class COMPtr , class ReturnType >
nsresult sbReturnCOMPtr (COMPtr &aPtr, ReturnType **aReturn)
 
void * SB_CloneMemory (const void *ptr, PRSize size)
 Clone a block of contiguous memory. More...
 

Macro Definition Documentation

#define SB_AUTO_CLASS (   aName,
  aType,
  aIsValid,
  aDispose,
  aInvalidate 
)    SB_AUTO_CLASS2(aName, aType, char, aIsValid, aDispose, aInvalidate)

Definition at line 218 of file sbMemoryUtils.h.

#define SB_AUTO_CLASS2 (   aName,
  aType,
  aType2,
  aIsValid,
  aDispose,
  aInvalidate 
)

Define a class that wraps a data type and auto-disposes it when going out of scope. The class name is specified by aName, and the data type is specified by aType. An additional class field type may be specified by aType2. A code snippet that checks for valid data is specified by aIsValid. A code snippet that disposes of the data is specified by aDispose. A code snippet that invalidates the data is specified by aInvalidate. The code snippets may use mValue to refer to the wrapped data and mValue2 to refer to the additional class field.

Parameters
aNameName of class.
aTypeClass data type.
aType2Additional class field data type.
aIsValidCode snippet to test for data validity.
aDisposeCode snippet to dispose of the data.
aInvalidateCode snippet to invalidate the data.

Example: SB_AUTO_CLASS(sbAutoMemPtr, void*, !!mValue, NS_Free(mValue), mValue = nsnull) sbAutoMemPtr autoMem(memPtr);

SB_AUTO_CLASS2(sbAutoClassData, void*, classType*, !!mValue, mValue2->Delete(mValue), mValue = nsnull) sbAutoClassData(data, this);

Definition at line 135 of file sbMemoryUtils.h.

#define SB_AUTO_NULL_CLASS (   aName,
  aType,
  aDispose 
)    SB_AUTO_CLASS(aName, aType, mValue != NULL, aDispose, mValue = NULL)

Define an auto-disposal class wrapper for data types whose invalid value is NULL.

Parameters
aNameName of class.
aTypeClass data type.
aDisposeCode snippet to dispose of the data.

Definition at line 231 of file sbMemoryUtils.h.

Function Documentation

void* SB_CloneMemory ( const void *  ptr,
PRSize  size 
)
inline

Clone a block of contiguous memory.

Definition at line 294 of file sbMemoryUtils.h.

Here is the caller graph for this function:

template<class COMPtr , class ReturnType >
nsresult sbReturnCOMPtr ( COMPtr &  aPtr,
ReturnType **  aReturn 
)
inline

Definition at line 278 of file sbMemoryUtils.h.