17 #ifndef IGNITION_GAZEBO_COMPONENTS_COMPONENT_HH_ 18 #define IGNITION_GAZEBO_COMPONENTS_COMPONENT_HH_ 28 #include <ignition/gazebo/config.hh> 29 #include <ignition/gazebo/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
245 static bool warned{
false};
248 ignwarn <<
"Trying to serialize component of type [" << this->TypeId()
249 <<
"], which hasn't implemented the `Serialize` function. " 250 <<
"Component will not be serialized." <<
std::endl;
262 static bool warned{
false};
265 ignwarn <<
"Trying to deserialize component of type [" 266 << this->TypeId() <<
"], which hasn't implemented the " 267 <<
"`Deserialize` function. Component will not be deserialized." 314 template <
typename DataType,
typename Identifier,
326 public:
explicit Component(DataType _data);
334 public:
bool operator==(
const Component &_component)
const;
339 public:
bool operator!=(
const Component &_component)
const;
345 public:
void Serialize(
std::ostream &_out)
const override;
355 public: DataType &Data();
363 public:
bool SetData(
const DataType &_data,
365 bool(
const DataType &,
const DataType &)> &_eql);
369 public:
const DataType &Data()
const;
372 private: DataType data;
391 template <
typename Identifier,
typename Serializer>
399 Serializer> &)
const;
406 Serializer> &)
const;
412 public:
void Serialize(
std::ostream &_out)
const override;
427 template <
typename DataType,
typename Identifier,
typename Serializer>
429 : data(std::move(_data))
434 template <
typename DataType,
typename Identifier,
typename Serializer>
441 template <
typename DataType,
typename Identifier,
typename Serializer>
443 const DataType &_data,
444 const std::function<
bool(
const DataType &,
const DataType &)> &_eql)
446 bool result = !_eql(_data, this->data);
452 template <
typename DataType,
typename Identifier,
typename Serializer>
459 template <
typename DataType,
typename Identifier,
typename Serializer>
463 return this->data == _component.
Data();
467 template <
typename DataType,
typename Identifier,
typename Serializer>
471 return this->data != _component.
Data();
475 template <
typename DataType,
typename Identifier,
typename Serializer>
479 Serializer::Serialize(_out, this->
Data());
483 template <
typename DataType,
typename Identifier,
typename Serializer>
487 Serializer::Deserialize(_in, this->
Data());
491 template <
typename DataType,
typename Identifier,
typename Serializer>
498 template <
typename Identifier,
typename Serializer>
506 template <
typename Identifier,
typename Serializer>
514 template <
typename Identifier,
typename Serializer>
521 template <
typename Identifier,
typename Serializer>
525 Serializer::Serialize(_out);
529 template <
typename Identifier,
typename Serializer>
533 Serializer::Deserialize(_in);
Type trait that determines if a operator<< is defined on Stream and DataType, i.e, it checks if the function Stream& operator<<(Stream&, const DataType&) exists. Example:
Definition: Component.hh:62
Default serializer template to call stream operators only on types that support them. If the stream operator is not available, a warning message is printed.
Definition: Component.hh:108
bool operator!=(const Component &_component) const
Inequality operator.
Definition: Component.hh:468
static ComponentTypeId typeId
Unique ID for this component type. This is set through the Factory registration.
Definition: Component.hh:376
bool operator==(const Component &_component) const
Equality operator.
Definition: Component.hh:460
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: Component.hh:206
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: Component.hh:476
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: Component.hh:492
virtual void Deserialize(std::istream &)
Fills a component based on a stream with a serialized data. By default, it will do nothing...
Definition: Component.hh:260
virtual void Serialize(std::ostream &) const
Fills a stream with a serialized version of the component. By default, it will leave the stream empty...
Definition: Component.hh:243
Specialization for components that don't wrap any data. This class to be used to create simple compon...
Definition: Component.hh:392
static std::string typeName
Unique name for this component type. This is set through the Factory registration.
Definition: Component.hh:380
static std::ostream & Serialize(std::ostream &_out)
Definition: Component.hh:214
uint64_t ComponentTypeId
A unique identifier for a component type. A component type must be derived from components::BaseCompo...
Definition: Types.hh:86
DataType Type
Alias for DataType.
Definition: Component.hh:319
void Deserialize(std::istream &_in) override
Fills a component based on a stream with a serialized data. By default, it will do nothing...
Definition: Component.hh:484
static std::ostream & Serialize(std::ostream &_out, const DataType &_data)
Serialization.
Definition: Component.hh:111
static std::istream & Deserialize(std::istream &_in, DataType &_data)
Deserialization.
Definition: Component.hh:157
Helper trait to determine if a type is shared_ptr or not.
Definition: Component.hh:43
A component type that wraps any data type. The intention is for this class to be used to create simpl...
Definition: Component.hh:316
static std::istream & Deserialize(std::istream &_in)
Definition: Component.hh:220
This library is part of the Ignition Robotics project.
static std::string typeName
Unique name for this component type. This is set through the Factory registration.
Definition: Component.hh:423
DataType & Data()
Get the mutable component data. This function will be deprecated in Gazebo 3, replaced by const DataT...
Definition: Component.hh:435
bool SetData(const DataType &_data, const std::function< bool(const DataType &, const DataType &)> &_eql)
Set the data of this component.
Definition: Component.hh:442
Base class for all components.
Definition: Component.hh:230
Type trait that determines if a operator>> is defined on Stream and DataType, i.e, it checks if the function Stream& operator>>(Stream&, DataType&) exists. Example:
Definition: Component.hh:86