CrystalSpace

Public API Reference

CS::CowWrapper< T, MemoryAllocator > Class Template Reference

Copy-on-write wrapper for arbitrary types. More...

#include <csutil/cowwrapper.h>

List of all members.

Public Member Functions

 CowWrapper (const T &other)
 Create a new wrapper and initialize with other.
 CowWrapper (const CowWrapper &other)
 Copy reference to data from other.
T & operator* ()
 Return a non-const reference to the contained data.
const T & operator* () const
 Return a const reference to the contained data.
T * operator-> ()
 Return a non-const pointer to the contained data.
const T * operator-> () const
 Return a const pointer to the contained data.

Static Public Attributes

static const size_t allocSize = sizeof (WrappedData)
 This is the size of the memory block the wrapper internally uses to store the actual data.

Detailed Description

template<typename T, class MemoryAllocator = Memory::AllocatorMalloc>
class CS::CowWrapper< T, MemoryAllocator >

Copy-on-write wrapper for arbitrary types.

  _________________________________________
 / Instances transparently maintain a      \
 | reference-counted pointer to the actual |
 | data; if an instance is copied, merely  |
 | this pointer is copied.                 |
 |                                         |
 | As long as all access to the data is    |
 | constant, the data is shared between    |
 | instances. Only if non-const access is  |
 | requested the data is duplicated.       |
 |                                         |
 \ The wrapper itself acts like a pointer. /
  -----------------------------------------
         \   ^__^
          \  (oo)\_______
             (__)\       )\/\
                 ||----w |
                 ||     ||
 
Remarks:
Contained types must have a proper copy constructor.
Care should be taken that the data is accessed with proper const-ness, since only the then data can be shared. Otherwise, data may be duplicated needlessly.

Definition at line 62 of file cowwrapper.h.


Constructor & Destructor Documentation

template<typename T , class MemoryAllocator = Memory::AllocatorMalloc>
CS::CowWrapper< T, MemoryAllocator >::CowWrapper ( const CowWrapper< T, MemoryAllocator > &  other  )  [inline]

Copy reference to data from other.

Definition at line 103 of file cowwrapper.h.

template<typename T , class MemoryAllocator = Memory::AllocatorMalloc>
CS::CowWrapper< T, MemoryAllocator >::CowWrapper ( const T &  other  )  [inline]

Create a new wrapper and initialize with other.

Definition at line 105 of file cowwrapper.h.


Member Function Documentation

template<typename T , class MemoryAllocator = Memory::AllocatorMalloc>
T& CS::CowWrapper< T, MemoryAllocator >::operator* (  )  [inline]

Return a non-const reference to the contained data.

Remarks:
This will copy the contained data, so only use when really necessary.

Definition at line 120 of file cowwrapper.h.

template<typename T , class MemoryAllocator = Memory::AllocatorMalloc>
const T& CS::CowWrapper< T, MemoryAllocator >::operator* (  )  const [inline]

Return a const reference to the contained data.

Definition at line 111 of file cowwrapper.h.

template<typename T , class MemoryAllocator = Memory::AllocatorMalloc>
T* CS::CowWrapper< T, MemoryAllocator >::operator-> (  )  [inline]

Return a non-const pointer to the contained data.

Remarks:
This will copy the contained data, so only use when really necessary.

Definition at line 137 of file cowwrapper.h.

template<typename T , class MemoryAllocator = Memory::AllocatorMalloc>
const T* CS::CowWrapper< T, MemoryAllocator >::operator-> (  )  const [inline]

Return a const pointer to the contained data.

Definition at line 130 of file cowwrapper.h.


Member Data Documentation

template<typename T , class MemoryAllocator = Memory::AllocatorMalloc>
const size_t CS::CowWrapper< T, MemoryAllocator >::allocSize = sizeof (WrappedData) [static]

This is the size of the memory block the wrapper internally uses to store the actual data.

It is published to make fixed-size allocators possible.

Definition at line 92 of file cowwrapper.h.


The documentation for this class was generated from the following file:

Generated for Crystal Space 2.0 by doxygen 1.6.1