Visual Computing Library
Loading...
Searching...
No Matches
vcl::comp::CustomComponents< ParentElemType > Class Template Reference

The CustomComponents Component is a container of additional components associated to an Element (e.g. Vertex, Face). More...

#include <vclib/mesh/components/custom_components.h>

Inheritance diagram for vcl::comp::CustomComponents< ParentElemType >:

Public Member Functions

 CustomComponents ()=default
 Initilizes an empty container of custom components.
 
bool hasCustomComponent (const std::string &compName) const
 Returns true if the element has a custom component with the given name, false otherwise. The type of the custom component is not checked.
 
template<typename CompType >
bool isCustomComponentOfType (const std::string &compName) const
 Returns true if the custom component of the given name is of the type given as template argument, false otherwise.
 
std::type_index customComponentType (const std::string &compName) const
 Returns the std::type_index of the custom component of the given name.
 
template<typename CompType >
std::vector< std::string > customComponentNamesOfType () const
 Returns a std::vector of std::strings containing the names of the custom components of the type given as template argument.
 
template<typename CompType >
const CompTypecustomComponent (const std::string &compName) const
 Returns the const reference to the custom component of the given name having the type given as template argument.
 
template<typename CompType >
CompTypecustomComponent (const std::string &compName)
 Returns the reference to the custom component of the given name having the type given as template argument.
 
template<typename CompType >
requires (!IS_VERTICAL)
void addCustomComponent (const std::string &compName, const CompType &value=CompType())
 
void deleteCustomComponent (const std::string &compName)
 

Static Public Attributes

static const uint COMPONENT_ID = CompId::CUSTOM_COMPONENTS
 The ID of component.
 

Protected Member Functions

template<typename Element >
void importFrom (const Element &e, bool=true)
 
void serialize (std::ostream &os) const
 
void deserialize (std::istream &is)
 

Private Attributes

detail::CustomComponentsData< ParentElemType, IS_VERTICAL > mData
 

Static Private Attributes

static const bool IS_VERTICAL = !std::is_same_v<ParentElemType, void>
 

Detailed Description

template<typename ParentElemType = void>
class vcl::comp::CustomComponents< ParentElemType >

The CustomComponents Component is a container of additional components associated to an Element (e.g. Vertex, Face).

CustomComponents are components that can be added at runtime. Each custom component is composed of:

  • a name, which is an std::string
  • a type, which needs to be known at compile time

E.g., to access to a CustomComponent of type 'int' called "myCustomComponent" from an element el:

el.customComponent<int>("myCustomComponent");
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43

CustomComponents can be stored horizontally or vertically.

If the CustomComponents component is horizontal (this happens mostly on Mesh data structures), a custom component can be added or removed from the object itself.

For example, having a Mesh m of type 'MyMesh' that has horizontal CustomComponents:

m.addCustomComponent<int>("myCustomComponent");

Otherwise, if the CustomComponents component is vertical (this happens mostly on Element types stored in a container, like Vertex, Face...), the addition/deletion of a custom component cannot be performed by the object, because its storage its managed by the Container of objects (that must provide a proper member function to do that).

For example, having a Mesh m of type MyMesh that has a VertexContainer where its Vertex has (vertical) CustomComponents:

m.addPerVertexCustomComponent<int>("myCustomComponent");

After this call, all the Vertices of the VertexContainer will have their custom component of type int called "myCustomComponent". The member function addPerVertexCustomComponent is provided by the VertexContainer and can be accessed directly from the Mesh.

Template Parameters
ParentElemTypeThis template argument must be void if the component needs to be stored horizontally, or the type of the parent element that will contain this component if the component needs to be stored vertically.

Member Function Documentation

◆ customComponent() [1/2]

template<typename ParentElemType = void>
template<typename CompType >
CompType & vcl::comp::CustomComponents< ParentElemType >::customComponent ( const std::string &  compName)
inline

Returns the reference to the custom component of the given name having the type given as template argument.

Note
The element must have a custom component with the given name, otherwise a std::out_of_range exception is thrown. If you don't know if the element has a custom component with the given name, use the CustomComponents::hasCustomComponent() member function.
The custom component must be of the type given as template argument, otherwise a std::bad_any_cast exception is thrown. The type of the custom component must be known at compile time.
Exceptions
std::out_of_rangeif the element does not have a custom component with the given name.
std::bad_any_castif the custom component is not of the type given as template argument.
Template Parameters
CompTypethe type of the custom component to retrieve.
Parameters
[in]compNamethe name of the custom component.
Returns
the reference to the custom component of the given name having the type given as template argument.

◆ customComponent() [2/2]

template<typename ParentElemType = void>
template<typename CompType >
const CompType & vcl::comp::CustomComponents< ParentElemType >::customComponent ( const std::string &  compName) const
inline

Returns the const reference to the custom component of the given name having the type given as template argument.

Note
The element must have a custom component with the given name, otherwise a std::out_of_range exception is thrown. If you don't know if the element has a custom component with the given name, use the CustomComponents::hasCustomComponent() member function.
The custom component must be of the type given as template argument, otherwise a std::bad_any_cast exception is thrown. The type of the custom component must be known at compile time.
Exceptions
std::out_of_rangeif the element does not have a custom component with the given name.
std::bad_any_castif the custom component is not of the type given as template argument.
Template Parameters
CompTypethe type of the custom component to retrieve.
Parameters
[in]compNamethe name of the custom component.
Returns
the const reference to the custom component of the given name having the type given as template argument.

◆ customComponentNamesOfType()

template<typename ParentElemType = void>
template<typename CompType >
std::vector< std::string > vcl::comp::CustomComponents< ParentElemType >::customComponentNamesOfType ( ) const
inline

Returns a std::vector of std::strings containing the names of the custom components of the type given as template argument.

Template Parameters
CompTypethe type of the custom components to retrieve.
Returns
a std::vector of std::strings containing the names of the custom components of the type given as template argument.

◆ customComponentType()

template<typename ParentElemType = void>
std::type_index vcl::comp::CustomComponents< ParentElemType >::customComponentType ( const std::string &  compName) const
inline

Returns the std::type_index of the custom component of the given name.

Note
The element must have a custom component with the given name, otherwise a std::out_of_range exception is thrown. If you don't know if the element has a custom component with the given name, use the CustomComponents::hasCustomComponent() member function.
Exceptions
std::out_of_rangeif the element does not have a custom component with the given name.
Parameters
[in]compNamethe name of the custom component.
Returns
the std::type_index of the custom component of the given name.

◆ hasCustomComponent()

template<typename ParentElemType = void>
bool vcl::comp::CustomComponents< ParentElemType >::hasCustomComponent ( const std::string &  compName) const
inline

Returns true if the element has a custom component with the given name, false otherwise. The type of the custom component is not checked.

Parameters
[in]compNamethe name of the custom component.
Returns
true if the element has a custom component with the given name, false otherwise.

◆ isCustomComponentOfType()

template<typename ParentElemType = void>
template<typename CompType >
bool vcl::comp::CustomComponents< ParentElemType >::isCustomComponentOfType ( const std::string &  compName) const
inline

Returns true if the custom component of the given name is of the type given as template argument, false otherwise.

Note
The element must have a custom component with the given name, otherwise a std::out_of_range exception is thrown. If you don't know if the element has a custom component with the given name, use the CustomComponents::hasCustomComponent() member function.
Exceptions
std::out_of_rangeif the element does not have a custom component with the given name.
Template Parameters
CompTypethe type of the custom component to check.
Parameters
[in]compNamethe name of the custom component.
Returns
true if the custom component of the given name is of the type CompType, false otherwise.

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