FreePOOMA  2.4.1
Public Types | Static Public Member Functions
ElementProperties< T > Struct Template Reference

Traits class for determining, and possibly modifying, the construction and destruction properties of elements of type T. More...

#include <ElementProperties.h>

List of all members.

Public Types

enum  { hasTrivialDefaultConstructor = false }
enum  { hasTrivialDestructor = false }
enum  { concrete = false }
enum  { basicType = false }
typedef T This_t

Static Public Member Functions

static void construct (This_t *addr)
static void construct (This_t *addr, const This_t &model)
static This_tclone (const This_t &model)
static void destruct (This_t *addr)

Detailed Description

template<class T>
struct ElementProperties< T >

Traits class for determining, and possibly modifying, the construction and destruction properties of elements of type T.

In detail, this class serves several purposes:

The first capability is provided by defining the two bool fields:

hasTrivialDefaultConstructor is true for data types whose default constructors have the same semantics as the native C data types; i.e. they do nothing: no allocations, no default values, etc. Normally RefCountedBlockPtr calls placement operator new to initizlize objects in the space that it allocates and manages. However, this is unnecessary overhead for types whose default constructor does nothing. Thus if hasTrivialDefaultConstructor is true, RefCountedBlockPtr will leave memory uninitialized in the default case.

Versions of ElementProperties for the most common C data types are defined below. Similar specializations might also be useful for other statically sized data types, such as TinyArrays. (Note that one could optionally define the specializations for native data types to initialize memory with some obviously corrupt value in order to help track initialization problems during debugging, although purify is probably a better tool for such investigations.)

Similarly, hasTrivialDestructor == true causes RefCountedBlockPtr to skip the explicit destructor calls that are normally necessary when destroying an object created with placement new. This will almost always have the same value as hasTrivialDefaultConstructor, but the additional flexibility carries no additional cost so it was included.

The class must also define the following static functions:

If the "trivial" flags are true, then the last two functions will never be called, but they must be defined or the compiler will complain. In these cases it is best to define the functions to throw an exception (see below).

The non-specialized ElementProperties<T> class defines both flags to be false. It defines the construct methods to use the default and copy constructors with placement new, respectively, under the assumption that these will make deep copies. Finally, it defines the destruct method to explicitly invoke the destructor on the object.


Member Typedef Documentation

template<class T >
typedef T ElementProperties< T >::This_t

Member Enumeration Documentation

template<class T >
anonymous enum
Enumerator:
hasTrivialDefaultConstructor 
template<class T >
anonymous enum
Enumerator:
hasTrivialDestructor 
template<class T >
anonymous enum
Enumerator:
concrete 
template<class T >
anonymous enum
Enumerator:
basicType 

Member Function Documentation

template<class T >
static void ElementProperties< T >::construct ( This_t addr) [inline, static]
template<class T >
static void ElementProperties< T >::construct ( This_t addr,
const This_t model 
) [inline, static]
template<class T >
static This_t* ElementProperties< T >::clone ( const This_t model) [inline, static]
template<class T >
static void ElementProperties< T >::destruct ( This_t addr) [inline, static]

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