Gazebo Physics

API Reference

6.7.0
CanWriteRequiredData< Derived, Specification > Class Template Reference

CanWriteRequiredData provides compile-time static analysis to ensure that the inheriting class provides a Write(~) function overload for each of the data types that are listed as required in the Specification. It also provides a function that will invoke Write(~) on each of the required data types (you may indicate whether or not it should only invoke them on unqueried data). More...

#include <CanWriteData.hh>

Public Member Functions

 CanWriteRequiredData ()
 The ability to compile this constructor ensures that an inherited class has functions that can write each of the data types required by the Specification. More...
 
template<typename CompositeType >
void WriteRequiredData (CompositeType &_data, const WriteOptions &_options=WriteOptions()) const
 Call this function to write all the types in _data that are listed as required in the Specification. More...
 

Detailed Description

template<typename Derived, typename Specification>
class gz::physics::CanWriteRequiredData< Derived, Specification >

CanWriteRequiredData provides compile-time static analysis to ensure that the inheriting class provides a Write(~) function overload for each of the data types that are listed as required in the Specification. It also provides a function that will invoke Write(~) on each of the required data types (you may indicate whether or not it should only invoke them on unqueried data).

Note that you must pass the name of your class in as the first template argument when inheriting it (Curiously Recurring Template Pattern CRTP), e.g.:

class MyClass : public CanWriteRequiredData<MyClass, MySpecification>
{
// ... define my class ...
};

You may also use CanWriteExpectedData if you want to further guarantee that your class is able to write all the expected data (recommended).

Note that you are allowed to inherit both CanWriteRequiredData and CanWriteExpectedData while passing different Specifications to each, but you should be aware that WriteRequiredData will only handle the data required by the Specification that is given to CanWriteRequiredData. Likewise, WriteExpectedData will only handle the data expected by the Specification that is given to CanWriteExpectedData.

While you can technically inherit CanWriteRequiredData multiple times and provide each base with a different Specification, this is strongly discouraged because then you will be left with multiple ambiguous versions of WriteRequiredData(~). Instead, it is beter to inherit it once and combine the Specifications using SpecifyData<Specification1, Specification2, ...>. For example:

class MyClass : public CanWriteRequiredData<
MyClass,
SpecifyData<MySpecification1,
MySpecification2,
MySpecification3> >
{
// ... define my class ...
};

This class is designed to cause a compilation error if the inheriting class does not provide all the necessary Write(~) functions. See the page WriteCompilationFail for more information.

Constructor & Destructor Documentation

◆ CanWriteRequiredData()

The ability to compile this constructor ensures that an inherited class has functions that can write each of the data types required by the Specification.

Member Function Documentation

◆ WriteRequiredData()

void WriteRequiredData ( CompositeType &  _data,
const WriteOptions _options = WriteOptions() 
) const

Call this function to write all the types in _data that are listed as required in the Specification.

Parameters
[out]_dataCompositeData instance to write to.
[in]_optionsWriteOptions for customizing the write operation.

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