Gazebo Gazebo

API Reference

3.15.1
Component< DataType, Identifier, Serializer > Class Template Reference

A component type that wraps any data type. The intention is for this class to be used to create simple components while avoiding a lot of boilerplate code. The Identifier must be a unique type so that type aliases can be used to create new components. However the type does not need to be defined anywhere eg. More...

#include <Component.hh>

Public Types

using Type = DataType
 Alias for DataType. More...
 

Public Member Functions

 Component ()=default
 Default constructor. More...
 
 Component (DataType _data)
 Constructor. More...
 
 ~Component () override=default
 Destructor. More...
 
DataType & Data ()
 Get the mutable component data. This function will be deprecated in Gazebo 3, replaced by const DataType &Data() const. Use void SetData(const DataType &) to modify data. More...
 
const DataType & Data () const
 Get the immutable component data. More...
 
void Deserialize (std::istream &_in) override
 Fills a component based on a stream with a serialized data. By default, it will do nothing. Derived classes should override this function to support deserialization. More...
 
bool operator!= (const Component &_component) const
 Inequality operator. More...
 
bool operator== (const Component &_component) const
 Equality operator. More...
 
void Serialize (std::ostream &_out) const override
 Fills a stream with a serialized version of the component. By default, it will leave the stream empty. Derived classes should override this function to support serialization. More...
 
bool SetData (const DataType &_data, const std::function< bool(const DataType &, const DataType &)> &_eql)
 Set the data of this component. More...
 
ComponentTypeId TypeId () const override
 Returns the unique ID for the component's type. The ID is derived from the name that is manually chosen during the Factory registration and is guaranteed to be the same across compilers and runs. More...
 
- Public Member Functions inherited from BaseComponent
 BaseComponent ()=default
 Default constructor. More...
 
virtual ~BaseComponent ()=default
 Default destructor. More...
 

Static Public Attributes

static ComponentTypeId typeId {0}
 Unique ID for this component type. This is set through the Factory registration. More...
 
static std::string typeName
 Unique name for this component type. This is set through the Factory registration. More...
 

Detailed Description

template<typename DataType, typename Identifier, typename Serializer = serializers::DefaultSerializer<DataType>>
class ignition::gazebo::components::Component< DataType, Identifier, Serializer >

A component type that wraps any data type. The intention is for this class to be used to create simple components while avoiding a lot of boilerplate code. The Identifier must be a unique type so that type aliases can be used to create new components. However the type does not need to be defined anywhere eg.

using Static = Component<bool, class StaticTag>;

Note, however, that this scheme does not have a mechanism to stop someone accidentally defining another component that wraps a bool as such:

using AnotherComp = Component<bool, class StaticTag>;

In this case, Static and AnotherComp are exactly the same types and would not be differentiable by the EntityComponentManager.

A third template argument can be passed to Component to specify the serializer class to use. If this argument is not provided, Component will use DefaultSerializer<DataType> where DataType is the first template argument to Component. eg.

class BoolSerializer; // Defined elsewhere
using Static = Component<bool, class StaticTag, BoolSerializer>;
Template Parameters
DataTypeType of the data being wrapped by this component.
IdentifierUnique identifier for the component class, to avoid collision.
SerializerA class that can serialize DataType. Defaults to a serializer that uses stream operators << and >> on the data if they exist.

Member Typedef Documentation

◆ Type

using Type = DataType

Alias for DataType.

Constructor & Destructor Documentation

◆ Component() [1/2]

Component ( )
default

Default constructor.

◆ Component() [2/2]

Component ( DataType  _data)
explicit

Constructor.

Parameters
[in]_dataData to copy

◆ ~Component()

~Component ( )
overridedefault

Destructor.

Member Function Documentation

◆ Data() [1/2]

const DataType & Data

Get the mutable component data. This function will be deprecated in Gazebo 3, replaced by const DataType &Data() const. Use void SetData(const DataType &) to modify data.

Returns
Mutable reference to the actual component information.
Todo:
(nkoenig) Deprecate this function in version 3.

Referenced by Component< DataType, Identifier, Serializer >::operator!=(), and Component< DataType, Identifier, Serializer >::operator==().

◆ Data() [2/2]

const DataType& Data ( ) const

Get the immutable component data.

Returns
Immutable reference to the actual component information.

◆ Deserialize()

void Deserialize ( std::istream _in)
overridevirtual

Fills a component based on a stream with a serialized data. By default, it will do nothing. Derived classes should override this function to support deserialization.

Parameters
[in]_inIn stream.

Reimplemented from BaseComponent.

◆ operator!=()

bool operator!= ( const Component< DataType, Identifier, Serializer > &  _component) const

Inequality operator.

Parameters
[in]_componentComponent to compare to.
Returns
True if different.

References Component< DataType, Identifier, Serializer >::Data().

◆ operator==()

bool operator== ( const Component< DataType, Identifier, Serializer > &  _component) const

Equality operator.

Parameters
[in]_componentComponent to compare to.
Returns
True if equal.

References Component< DataType, Identifier, Serializer >::Data().

◆ Serialize()

void Serialize ( std::ostream _out) const
overridevirtual

Fills a stream with a serialized version of the component. By default, it will leave the stream empty. Derived classes should override this function to support serialization.

Parameters
[in]_outOut stream.

Reimplemented from BaseComponent.

◆ SetData()

bool SetData ( const DataType &  _data,
const std::function< bool(const DataType &, const DataType &)> &  _eql 
)

Set the data of this component.

Parameters
[in]_dataNew data for this component.
[in]_eqlEquality comparison function. This function should return true if two instances of DataType are equal.
Returns
True if the _eql function returns false.

◆ TypeId()

ComponentTypeId TypeId ( ) const
overridevirtual

Returns the unique ID for the component's type. The ID is derived from the name that is manually chosen during the Factory registration and is guaranteed to be the same across compilers and runs.

Implements BaseComponent.

Member Data Documentation

◆ typeId

ComponentTypeId typeId {0}
inlinestatic

Unique ID for this component type. This is set through the Factory registration.

Referenced by Component< NoData, Identifier, Serializer >::TypeId().

◆ typeName

std::string typeName
inlinestatic

Unique name for this component type. This is set through the Factory registration.


The documentation for this class was generated from the following file:
Component< bool, class StaticTag > Static
A component used to indicate that a model is static (i.e. not moveable).
Definition: gz/sim/components/Static.hh:34