Atlas 0.7.0
Networking protocol for the Worldforge system.
|
#include <BaseObject.h>
Public Member Functions | |
Allocator () | |
~Allocator () | |
T * | getDefaultObjectInstance () |
T * | alloc () |
void | free (T *instance) |
void | release () |
Public Attributes | |
std::map< std::string, uint32_t > | attr_flags_Data |
Protected Attributes | |
T | m_defaults_Data |
std::mutex | m_begin_Data_mutex |
T * | m_begin_Data |
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".
Definition at line 78 of file BaseObject.h.
Atlas::Objects::Allocator< T >::Allocator |
Ctor.
Definition at line 153 of file BaseObject.h.
References Atlas::Objects::Allocator< T >::attr_flags_Data, and Atlas::Objects::Allocator< T >::m_defaults_Data.
Atlas::Objects::Allocator< T >::~Allocator |
Dtor.
Definition at line 159 of file BaseObject.h.
|
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.
Definition at line 170 of file BaseObject.h.
|
inline |
Frees up an instance.
This means that the instance will be returned to the pool, ready to be used again.
instance | The instance to free. |
Definition at line 188 of file BaseObject.h.
|
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.
Definition at line 164 of file BaseObject.h.
void Atlas::Objects::Allocator< T >::release |
Deletes all pooled but unused instances.
Definition at line 199 of file BaseObject.h.
std::map<std::string, uint32_t> Atlas::Objects::Allocator< T >::attr_flags_Data |
A map of attributes and their flags.
Definition at line 104 of file BaseObject.h.
Referenced by Atlas::Objects::Allocator< T >::Allocator().
|
protected |
The first available instance, not currently in use.
If this is null, a new instance needs to be created.
Definition at line 97 of file BaseObject.h.
|
protected |
Mutex for whenever the m_being_Data_mutex field need to be accessed. A std::atomic might be nicer, but the current code requires a mutex.
Definition at line 90 of file BaseObject.h.
|
protected |
The default instance, acting as a prototype for all other instances.
Definition at line 83 of file BaseObject.h.
Referenced by Atlas::Objects::Allocator< T >::Allocator().