Crystal Space: CS::CowWrapper< T, MemoryAllocator > Class Template Reference (Crystal Space Public API Reference)

| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# 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)

## 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 98 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 100 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 115 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 106 of file cowwrapper.h.

Referenced by CS::CowWrapper< T, MemoryAllocator >::operator->().

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 132 of file cowwrapper.h.

References CS::CowWrapper< T, MemoryAllocator >::operator *().

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 125 of file cowwrapper.h.

References CS::CowWrapper< T, MemoryAllocator >::operator *().

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

- csutil/cowwrapper.h