Geogram Version 1.9.7
A programming library of geometric algorithms
Loading...
Searching...
No Matches
GEO::LifeCycle Class Referenceabstract

Manages the life cycle of an object. More...

#include <geogram/basic/life_cycle.h>

Inheritance diagram for GEO::LifeCycle:
GEO::Counted GEO::GenericLifeCycle< T >

Public Member Functions

 LifeCycle (size_t object_size, bool is_pod=false)
 LifeCycle constructor.
 
 ~LifeCycle () override
 LifeCycle destructor.
 
size_t object_size () const
 Gets the size of an object.
 
bool is_pod () const
 Tests whether object is pod (plain ordinary datatype).
 
virtual void construct (Memory::pointer address)=0
 Calls the constructor of an object.
 
virtual void copy_construct (Memory::pointer lhs, Memory::pointer rhs)=0
 Copy-Constructs an object at a given address.
 
virtual void destroy (Memory::pointer address)=0
 Calls the destructor of an object.
 
virtual void assign (Memory::pointer lhs, Memory::pointer rhs)=0
 Calls the assignment operator.
 
virtual void reset (Memory::pointer address)=0
 Resets an object to its default value.
 
virtual void swap (Memory::pointer a, Memory::pointer b)=0
 Swaps the objects at two addresses.
 
virtual void construct_array (Memory::pointer address, index_t nb)=0
 Calls the constructor of objects in an array.
 
virtual void copy_construct_array (Memory::pointer lhs, Memory::pointer rhs, index_t nb)=0
 Copy-Constructs an array of object at a given address.
 
virtual void destroy_array (Memory::pointer address, index_t nb)=0
 Destroys an array of object at a given address.
 
virtual void assign_array (Memory::pointer lhs, Memory::pointer rhs, index_t nb)=0
 Copies an array of object at a given address.
 
virtual void reset_array (Memory::pointer address, index_t nb)=0
 Resets all objects in an array to their default value.
 
virtual Memory::pointer new_object ()=0
 Dynamically allocates a new object.
 
virtual Memory::pointer new_object (Memory::pointer rhs)=0
 Dynamically allocates a new object with copy constructor.
 
virtual void delete_object (Memory::pointer address)=0
 Deletes an object.
 
virtual Memory::pointer new_array (index_t nb)=0
 Dynamically allocates an array of objects.
 
virtual void delete_array (Memory::pointer address)=0
 Deletes an array of objects.
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count.
 
void unref () const
 Decrements the reference count.
 
bool is_shared () const
 Check if the object is shared.
 
int nb_refs () const
 Gets the number of references that point to this object.
 

Additional Inherited Members

- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count.
 
static void unref (const Counted *counted)
 Decrements the reference count.
 
- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object.
 
virtual ~Counted ()
 Destroys a reference counted object.
 

Detailed Description

Manages the life cycle of an object.

Provides ways to call the constructor, destructor, copy constructor and assignation operator on objects known only from their addresses as raw untyped pointers. This is used by the Attribute mechanism of Geogram and by the Any class in Graphite/GOM.

Definition at line 66 of file life_cycle.h.

Constructor & Destructor Documentation

◆ LifeCycle()

GEO::LifeCycle::LifeCycle ( size_t  object_size,
bool  is_pod = false 
)
inline

LifeCycle constructor.

Parameters
[in]object_sizethe size of an object in bytes.

Definition at line 73 of file life_cycle.h.

Member Function Documentation

◆ assign()

virtual void GEO::LifeCycle::assign ( Memory::pointer  lhs,
Memory::pointer  rhs 
)
pure virtual

Calls the assignment operator.

Parameters
[in]lhsthe address of the left hand side.
[in]rhsthe address of the right hand side.

Implemented in GEO::GenericLifeCycle< T >.

◆ assign_array()

virtual void GEO::LifeCycle::assign_array ( Memory::pointer  lhs,
Memory::pointer  rhs,
index_t  nb 
)
pure virtual

Copies an array of object at a given address.

Parameters
[in]lhsthe address of the left-hand-side objects
[in]rhsthe address of the right-hand-side objects to be copied.
[in]nbnumber of objects

No memory allocation is done.

Implemented in GEO::GenericLifeCycle< T >.

◆ construct()

virtual void GEO::LifeCycle::construct ( Memory::pointer  address)
pure virtual

Calls the constructor of an object.

Parameters
[in]addressthe address of the object to be constructed.

No memory allocation is done.

Implemented in GEO::GenericLifeCycle< T >.

◆ construct_array()

virtual void GEO::LifeCycle::construct_array ( Memory::pointer  address,
index_t  nb 
)
pure virtual

Calls the constructor of objects in an array.

Parameters
[in]addressthe address of the object array to be constructed.
[in]nbnumber of objects.

No memory allocation is done.

Implemented in GEO::GenericLifeCycle< T >.

◆ copy_construct()

virtual void GEO::LifeCycle::copy_construct ( Memory::pointer  lhs,
Memory::pointer  rhs 
)
pure virtual

Copy-Constructs an object at a given address.

Parameters
[in]lhsthe address where the object should be constructed.
[in]rhsthe address of the right-hand-side object to be copied.

No memory allocation is done.

Implemented in GEO::GenericLifeCycle< T >.

◆ copy_construct_array()

virtual void GEO::LifeCycle::copy_construct_array ( Memory::pointer  lhs,
Memory::pointer  rhs,
index_t  nb 
)
pure virtual

Copy-Constructs an array of object at a given address.

Parameters
[in]lhsthe address of the objects to be constructed.
[in]rhsthe address of the right-hand-side objects to be copied.
[in]nbnumber of objects

No memory allocation is done.

Implemented in GEO::GenericLifeCycle< T >.

◆ delete_array()

virtual void GEO::LifeCycle::delete_array ( Memory::pointer  address)
pure virtual

Deletes an array of objects.

Parameters
[in]addressthe address of the object array to be deleted.

Implemented in GEO::GenericLifeCycle< T >.

◆ delete_object()

virtual void GEO::LifeCycle::delete_object ( Memory::pointer  address)
pure virtual

Deletes an object.

Parameters
[in]addressthe address of the object.

Implemented in GEO::GenericLifeCycle< T >.

◆ destroy()

virtual void GEO::LifeCycle::destroy ( Memory::pointer  address)
pure virtual

Calls the destructor of an object.

Parameters
[in]addressthe address of the object to be destructed.

No memory deallocation is done.

Implemented in GEO::GenericLifeCycle< T >.

◆ destroy_array()

virtual void GEO::LifeCycle::destroy_array ( Memory::pointer  address,
index_t  nb 
)
pure virtual

Destroys an array of object at a given address.

Parameters
[in]addressthe address of the objects to be destroyed.
[in]nbnumber of objects

No memory deallocation is done.

Implemented in GEO::GenericLifeCycle< T >.

◆ is_pod()

bool GEO::LifeCycle::is_pod ( ) const
inline

Tests whether object is pod (plain ordinary datatype).

Plain ordinary datatypes can be copied with memcpy().

Return values
trueif object is pod.
falseotherwise.

Definition at line 98 of file life_cycle.h.

◆ new_array()

virtual Memory::pointer GEO::LifeCycle::new_array ( index_t  nb)
pure virtual

Dynamically allocates an array of objects.

Parameters
[in]nbnumber of objects.

Implemented in GEO::GenericLifeCycle< T >.

◆ new_object() [1/2]

virtual Memory::pointer GEO::LifeCycle::new_object ( )
pure virtual

Dynamically allocates a new object.

Returns
the address of the new object.

Implemented in GEO::GenericLifeCycle< T >.

◆ new_object() [2/2]

virtual Memory::pointer GEO::LifeCycle::new_object ( Memory::pointer  rhs)
pure virtual

Dynamically allocates a new object with copy constructor.

Parameters
[in]rhsthe address of the right-hand-side objects to be copied.
Returns
the address of the new object.

Implemented in GEO::GenericLifeCycle< T >.

◆ object_size()

size_t GEO::LifeCycle::object_size ( ) const
inline

Gets the size of an object.

Returns
the size of an object in bytes.

Definition at line 86 of file life_cycle.h.

◆ reset()

virtual void GEO::LifeCycle::reset ( Memory::pointer  address)
pure virtual

Resets an object to its default value.

Creates a new object with the default constructor and assigns it to the object at address.

Parameters
[in]addressthe address of an already initialized object.

Implemented in GEO::GenericLifeCycle< T >.

◆ reset_array()

virtual void GEO::LifeCycle::reset_array ( Memory::pointer  address,
index_t  nb 
)
pure virtual

Resets all objects in an array to their default value.

creates an object with the default value and assigns it to the element for each element in the array.

Parameters
[in]addressthe address of the object array to be reset.
[in]nbnumber of objects.

Implemented in GEO::GenericLifeCycle< T >.

◆ swap()

virtual void GEO::LifeCycle::swap ( Memory::pointer  a,
Memory::pointer  b 
)
pure virtual

Swaps the objects at two addresses.

Parameters
[in]a,bpointers to the two objects to be swapped

Implemented in GEO::GenericLifeCycle< T >.


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