Easy3D 2.6.1
Loading...
Searching...
No Matches
PropertyContainer Class Reference

Implementation of a generic property container. More...

#include <easy3d/core/property.h>

Public Member Functions

 PropertyContainer ()
 Default constructor.
 
virtual ~PropertyContainer ()
 Destructor. Deletes all property arrays.
 
 PropertyContainer (const PropertyContainer &_rhs)
 Copy constructor. Performs deep copy of property arrays.
 
PropertyContaineroperator= (const PropertyContainer &_rhs)
 Assignment operator. Performs deep copy of property arrays.
 
void transfer (const PropertyContainer &_rhs) const
 Transfers properties from another property container.
 
void copy_properties (const PropertyContainer &_rhs)
 Copies properties that don't already exist from another container.
 
bool transfer (const PropertyContainer &_rhs, std::size_t from, std::size_t to) const
 Transfers one element with all properties.
 
size_t size () const
 Returns the current size of the property arrays.
 
size_t n_properties () const
 Returns the number of property arrays.
 
std::vector< std::string > properties () const
 Returns a vector of all property names.
 
template<class T>
Property< T > add (const std::string &name, const T t=T())
 Adds a property with a given name and default value.
 
template<class T>
Property< T > get (const std::string &name) const
 Gets a property by its name.
 
template<class T>
Property< T > get_or_add (const std::string &name, const T t=T())
 Gets or adds a property by its name.
 
const std::type_info & get_type (const std::string &name) const
 Gets the type information of a property by its name.
 
template<class T>
bool remove (Property< T > &h)
 Removes a property.
 
bool remove (const std::string &name)
 Removes a property by its name.
 
bool rename (const std::string &old_name, const std::string &new_name)
 Renames a property.
 
void clear ()
 Deletes all properties.
 
void reserve (size_t n) const
 Reserves memory for n entries in all arrays.
 
void resize (size_t n)
 Resizes all arrays to size n.
 
void resize_property_array (size_t n)
 Resizes the vector of properties to n, deleting all other properties.
 
void shrink_to_fit () const
 Frees unused space in all arrays.
 
void push_back ()
 Adds a new element to each vector.
 
void reset (size_t idx) const
 Resets an element to its default property values.
 
void swap (size_t i0, size_t i1) const
 Swaps elements i0 and i1 in all arrays.
 
void swap (PropertyContainer &other) noexcept
 Swaps content with another property container.
 
void copy (size_t from, size_t to) const
 Copies an element from one index to another in all arrays.
 
const std::vector< BasePropertyArray * > & arrays () const
 Returns the vector of property arrays (read-only).
 
std::vector< BasePropertyArray * > & arrays ()
 Returns the vector of property arrays.
 

Detailed Description

Implementation of a generic property container.

Constructor & Destructor Documentation

◆ PropertyContainer()

PropertyContainer ( const PropertyContainer & _rhs)
inline

Copy constructor. Performs deep copy of property arrays.

Parameters
_rhsThe property container to copy from.

Member Function Documentation

◆ add()

template<class T>
Property< T > add ( const std::string & name,
const T t = T() )
inline

Adds a property with a given name and default value.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The added property.

◆ arrays() [1/2]

std::vector< BasePropertyArray * > & arrays ( )
inline

Returns the vector of property arrays.

Returns
The vector of property arrays.

◆ arrays() [2/2]

const std::vector< BasePropertyArray * > & arrays ( ) const
inline

Returns the vector of property arrays (read-only).

Returns
The vector of property arrays.

◆ copy()

void copy ( size_t from,
size_t to ) const
inline

Copies an element from one index to another in all arrays.

Parameters
fromThe index to copy from.
toThe index to copy to.

◆ copy_properties()

void copy_properties ( const PropertyContainer & _rhs)
inline

Copies properties that don't already exist from another container.

Parameters
_rhsThe property container to copy from.

◆ get()

template<class T>
Property< T > get ( const std::string & name) const
inline

Gets a property by its name.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
Returns
The property if it exists, otherwise an invalid property.

◆ get_or_add()

template<class T>
Property< T > get_or_add ( const std::string & name,
const T t = T() )
inline

Gets or adds a property by its name.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The property if it exists, otherwise the added property.

◆ get_type()

const std::type_info & get_type ( const std::string & name) const
inline

Gets the type information of a property by its name.

Parameters
nameThe name of the property.
Returns
The type information of the property. Returns a typeid(void) if the property does not exist.

◆ n_properties()

size_t n_properties ( ) const
inline

Returns the number of property arrays.

Returns
The number of property arrays.

◆ operator=()

PropertyContainer & operator= ( const PropertyContainer & _rhs)
inline

Assignment operator. Performs deep copy of property arrays.

Parameters
_rhsThe property container to assign from.
Returns
A reference to the assigned property container.

◆ properties()

std::vector< std::string > properties ( ) const
inline

Returns a vector of all property names.

Returns
A vector of all property names.

◆ remove() [1/2]

bool remove ( const std::string & name)
inline

Removes a property by its name.

Parameters
nameThe name of the property to remove.
Returns
True if the property was removed, false otherwise.

◆ remove() [2/2]

template<class T>
bool remove ( Property< T > & h)
inline

Removes a property.

Template Parameters
TThe type of the property.
Parameters
hThe property to remove.
Returns
True if the property was removed, false otherwise.

◆ rename()

bool rename ( const std::string & old_name,
const std::string & new_name )
inline

Renames a property.

Parameters
old_nameThe current name of the property.
new_nameThe new name of the property.
Returns
True if the property was renamed, false otherwise.

◆ reserve()

void reserve ( size_t n) const
inline

Reserves memory for n entries in all arrays.

Parameters
nThe number of entries to reserve memory for.

◆ reset()

void reset ( size_t idx) const
inline

Resets an element to its default property values.

Parameters
idxThe index of the element to reset.

◆ resize()

void resize ( size_t n)
inline

Resizes all arrays to size n.

Parameters
nThe new size of the arrays.

◆ resize_property_array()

void resize_property_array ( size_t n)
inline

Resizes the vector of properties to n, deleting all other properties.

Parameters
nThe new size of the property vector.

◆ size()

size_t size ( ) const
inline

Returns the current size of the property arrays.

Returns
The current size of the property arrays.

◆ swap() [1/2]

void swap ( PropertyContainer & other)
inlinenoexcept

Swaps content with another property container.

Parameters
otherThe other property container to swap with.

◆ swap() [2/2]

void swap ( size_t i0,
size_t i1 ) const
inline

Swaps elements i0 and i1 in all arrays.

Parameters
i0The index of the first element.
i1The index of the second element.

◆ transfer() [1/2]

void transfer ( const PropertyContainer & _rhs) const
inline

Transfers properties from another property container.

Parameters
_rhsThe property container to transfer from.

◆ transfer() [2/2]

bool transfer ( const PropertyContainer & _rhs,
std::size_t from,
std::size_t to ) const
inline

Transfers one element with all properties.

Attention
Properties must be the same in the two containers
Parameters
_rhsThe property container to transfer from.
fromThe index to transfer from.
toThe index to transfer to.
Returns
True if the transfer was successful, false otherwise.

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