Atlas-C++
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Atlas::Objects::Allocator< T > Class Template Reference

Trait which handles allocation of instances of BaseObject. More...

#include <BaseObject.h>

Public Member Functions

 Allocator ()
 Ctor.
 
 ~Allocator ()
 Dtor.
 
T * getDefaultObjectInstance ()
 Gets the default object instance, which acts as a prototype for all other instances in the system. More...
 
T * alloc ()
 Allocates a new instance to be used. More...
 
void free (T *instance)
 Frees up an instance. More...
 
void release ()
 Deletes all pooled but unused instances.
 

Public Attributes

std::map< std::string, int32_t > attr_flags_Data
 A map of attributes and their flags.
 

Protected Attributes

m_defaults_Data
 The default instance, acting as a prototype for all other instances.
 
T * m_begin_Data
 The first available instance, not currently in use. More...
 

Detailed Description

template<typename T>
class Atlas::Objects::Allocator< T >

Trait which handles allocation of instances of BaseObject.

This class handles allocation and deallocation of templates BaseObject instances. Instead of creating and deleting BaseObjects as they are used we keep a small pool around, reusing old instances when needed.

This class is tightly coupled with both SmartPtr and BaseObject and rely on a couple of templated naming conventions. Any subclass of BaseObject should therefore keep a static instance of this in a field named "allocator".

Member Function Documentation

template<typename T >
T * Atlas::Objects::Allocator< T >::alloc ( )
inline

Allocates a new instance to be used.

This will either reuse and existing instance or create a new, depending of whether there's a free unused instance available.

Returns
An instance ready to be used.
template<typename T>
void Atlas::Objects::Allocator< T >::free ( T *  instance)
inline

Frees up an instance.

This means that the instance will be returned to the pool, ready to be used again.

Parameters
instanceThe instance to free.
template<typename T >
T * Atlas::Objects::Allocator< T >::getDefaultObjectInstance ( )
inline

Gets the default object instance, which acts as a prototype for all other instances in the system.

Any alterations made to the prototype instance will reflect on all other instances of the same class.

Returns
The default object instance.

Member Data Documentation

template<typename T>
T* Atlas::Objects::Allocator< T >::m_begin_Data
protected

The first available instance, not currently in use.

If this is null, a new instance needs to be created.


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

Copyright 2000-2004 the respective authors.

This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.