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... | |
std::unique_ptr< BaseComponent > | Clone () const override |
Clone the component. 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 gz::sim::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.
Note, however, that this scheme does not have a mechanism to stop someone accidentally defining another component that wraps a bool as such:
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.
- Template Parameters
-
DataType Type of the data being wrapped by this component. Identifier Unique identifier for the component class, to avoid collision. Serializer A 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]
|
default |
Default constructor.
◆ Component() [2/2]
|
explicit |
Constructor.
- Parameters
-
[in] _data Data to copy
◆ ~Component()
|
overridedefault |
Destructor.
Member Function Documentation
◆ Clone()
|
overridevirtual |
◆ 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()
|
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] _in In stream.
Reimplemented from BaseComponent.
◆ operator!=()
bool operator!= | ( | const Component< DataType, Identifier, Serializer > & | _component | ) | const |
Inequality operator.
- Parameters
-
[in] _component Component 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] _component Component to compare to.
- Returns
- True if equal.
References Component< DataType, Identifier, Serializer >::Data().
◆ Serialize()
|
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] _out Out 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] _data New data for this component. [in] _eql Equality comparison function. This function should return true if two instances of DataType are equal.
- Returns
- True if the _eql function returns false.
◆ TypeId()
|
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
|
inlinestatic |
Unique ID for this component type. This is set through the Factory registration.
Referenced by Component< NoData, Identifier, Serializer >::TypeId().
◆ 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: