Go to the documentation of this file.
17 #ifndef GZ_GAZEBO_COMPONENTS_COMPONENT_HH_
18 #define GZ_GAZEBO_COMPONENTS_COMPONENT_HH_
26 #include <gz/common/Console.hh>
28 #include <gz/sim/config.hh>
29 #include <gz/sim/Export.hh>
38 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
61 template <
typename Stream,
typename DataType>
64 private:
template <
typename StreamArg,
typename DataTypeArg>
65 static auto Test(
int _test)
66 -> decltype(std::declval<StreamArg &>()
69 private:
template <
typename,
typename>
72 public:
static constexpr
bool value =
73 decltype(Test<Stream, DataType>(
true))::value;
85 template <
typename Stream,
typename DataType>
88 private:
template <
typename StreamArg,
typename DataTypeArg>
89 static auto Test(
int _test)
90 -> decltype(std::declval<StreamArg &>() >> std::declval<DataTypeArg &>(),
93 private:
template <
typename,
typename>
96 public:
static constexpr
bool value =
97 decltype(Test<Stream, DataType>(0))::value;
101 namespace serializers
107 template <
typename DataType>
112 const DataType &_data)
118 typename DataType::element_type>::value)
124 static bool warned{
false};
127 ignwarn <<
"Trying to serialize component with data type ["
128 <<
typeid(DataType).name() <<
"], which doesn't have "
129 <<
"`operator<<`. Component will not be serialized."
141 static bool warned{
false};
144 ignwarn <<
"Trying to serialize component with data type ["
145 <<
typeid(DataType).name() <<
"], which doesn't have "
146 <<
"`operator<<`. Component will not be serialized."
163 typename DataType::element_type>::value)
169 static bool warned{
false};
172 ignwarn <<
"Trying to deserialize component with data type ["
173 <<
typeid(DataType).name() <<
"], which doesn't have "
174 <<
"`operator>>`. Component will not be deserialized."
186 static bool warned{
false};
189 ignwarn <<
"Trying to deserialize component with data type ["
190 <<
typeid(DataType).name() <<
"], which doesn't have "
191 <<
"`operator>>`. Component will not be deserialized."
209 namespace serializers
247 static bool warned{
false};
250 ignwarn <<
"Trying to serialize component of type [" << this->TypeId()
251 <<
"], which hasn't implemented the `Serialize` function. "
252 <<
"Component will not be serialized." <<
std::endl;
266 static bool warned{
false};
269 ignwarn <<
"Trying to deserialize component of type ["
270 << this->TypeId() <<
"], which hasn't implemented the "
271 <<
"`Deserialize` function. Component will not be deserialized."
318 template <
typename DataType,
typename Identifier,
330 public:
explicit Component(DataType _data);
338 public:
bool operator==(
const Component &_component)
const;
343 public:
bool operator!=(
const Component &_component)
const;
349 public:
void Serialize(
std::ostream &_out)
const override;
359 public: DataType &Data();
366 public:
bool SetData(
const DataType &_data,
368 bool(
const DataType &,
const DataType &)> &_eql);
372 public:
const DataType &Data()
const;
375 private: DataType data;
394 template <
typename Identifier,
typename Serializer>
402 Serializer> &_component)
const;
409 Serializer> &_component)
const;
415 public:
void Serialize(
std::ostream &_out)
const override;
430 template <
typename DataType,
typename Identifier,
typename Serializer>
432 : data(
std::move(_data))
437 template <
typename DataType,
typename Identifier,
typename Serializer>
444 template <
typename DataType,
typename Identifier,
typename Serializer>
446 const DataType &_data,
447 const std::function<
bool(
const DataType &,
const DataType &)> &_eql)
449 bool result = !_eql(_data, this->data);
455 template <
typename DataType,
typename Identifier,
typename Serializer>
462 template <
typename DataType,
typename Identifier,
typename Serializer>
466 return this->data == _component.
Data();
470 template <
typename DataType,
typename Identifier,
typename Serializer>
474 return this->data != _component.
Data();
478 template <
typename DataType,
typename Identifier,
typename Serializer>
482 Serializer::Serialize(_out, this->Data());
486 template <
typename DataType,
typename Identifier,
typename Serializer>
490 Serializer::Deserialize(_in, this->Data());
494 template <
typename DataType,
typename Identifier,
typename Serializer>
501 template <
typename Identifier,
typename Serializer>
509 template <
typename Identifier,
typename Serializer>
517 template <
typename Identifier,
typename Serializer>
524 template <
typename Identifier,
typename Serializer>
528 Serializer::Serialize(_out);
532 template <
typename Identifier,
typename Serializer>
536 Serializer::Deserialize(_in);
void Deserialize(std::istream &_in) override
Fills a component based on a stream with a serialized data. By default, it will do nothing....
Definition: gz/sim/components/Component.hh:487
This library is part of the Ignition Robotics project.
bool SetData(const DataType &_data, const std::function< bool(const DataType &, const DataType &)> &_eql)
Set the data of this component.
Definition: gz/sim/components/Component.hh:445
BaseComponent()=default
Default constructor.
Type trait that determines if a operator>> is defined on Stream and DataType, i.e,...
Definition: gz/sim/components/Component.hh:86
static std::string typeName
Unique name for this component type. This is set through the Factory registration.
Definition: gz/sim/components/Component.hh:383
Type trait that determines if a operator<< is defined on Stream and DataType, i.e,...
Definition: gz/sim/components/Component.hh:62
static std::ostream & Serialize(std::ostream &_out)
Definition: gz/sim/components/Component.hh:214
Helper trait to determine if a type is shared_ptr or not.
Definition: gz/sim/components/Component.hh:43
static constexpr bool value
Definition: gz/sim/components/Component.hh:96
Specialization for components that don't wrap any data. This class to be used to create simple compon...
Definition: gz/sim/components/Component.hh:395
ComponentTypeId TypeId() const override
Returns the unique ID for the component's type. The ID is derived from the name that is manually chos...
Definition: gz/sim/components/Component.hh:495
virtual ComponentTypeId TypeId() const =0
Returns the unique ID for the component's type. The ID is derived from the name that is manually chos...
DataType Type
Alias for DataType.
Definition: gz/sim/components/Component.hh:323
virtual void Deserialize(std::istream &_in)
Fills a component based on a stream with a serialized data. By default, it will do nothing....
Definition: gz/sim/components/Component.hh:262
static std::istream & Deserialize(std::istream &_in)
Definition: gz/sim/components/Component.hh:220
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...
Definition: gz/sim/components/Component.hh:479
Base class for all components.
Definition: gz/sim/components/Component.hh:230
static constexpr bool value
Definition: gz/sim/components/Component.hh:72
static ComponentTypeId typeId
Unique ID for this component type. This is set through the Factory registration.
Definition: gz/sim/components/Component.hh:379
static std::string typeName
Unique name for this component type. This is set through the Factory registration.
Definition: gz/sim/components/Component.hh:426
Default serializer template to call stream operators only on types that support them....
Definition: gz/sim/components/Component.hh:108
A component type that wraps any data type. The intention is for this class to be used to create simpl...
Definition: gz/sim/components/Component.hh:320
virtual void Serialize(std::ostream &_out) const
Fills a stream with a serialized version of the component. By default, it will leave the stream empty...
Definition: gz/sim/components/Component.hh:243
~Component() override=default
Destructor.
bool operator!=(const Component &_component) const
Inequality operator.
Definition: gz/sim/components/Component.hh:471
DataType & Data()
Get the mutable component data. This function will be deprecated in Gazebo 3, replaced by const DataT...
Definition: gz/sim/components/Component.hh:438
static std::istream & Deserialize(std::istream &_in, DataType &_data)
Deserialization.
Definition: gz/sim/components/Component.hh:157
bool operator==(const Component &_component) const
Equality operator.
Definition: gz/sim/components/Component.hh:463
Component()=default
Default constructor.
uint64_t ComponentTypeId
A unique identifier for a component type. A component type must be derived from components::BaseCompo...
Definition: include/gz/sim/Types.hh:87
static std::ostream & Serialize(std::ostream &_out, const DataType &_data)
Serialization.
Definition: gz/sim/components/Component.hh:111
std::add_lvalue_reference< void > NoData
Convenient type to be used by components that don't wrap any data. I.e. they act as tags and their pr...
Definition: gz/sim/components/Component.hh:206
virtual ~BaseComponent()=default
Default destructor.