Gazebo Physics

API Reference

5.3.2
CanReadRequiredData< Derived, Specification > Class Template Reference

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

#include <CanReadData.hh>

Public Member Functions

 CanReadRequiredData ()
 
template<typename CompositeType >
void ReadRequiredData (const CompositeType &_data, const ReadOptions &_options=ReadOptions())
 

Detailed Description

template<typename Derived, typename Specification>
class ignition::physics::CanReadRequiredData< Derived, Specification >

CanReadRequiredData provides compile-time static analysis to ensure that the inheriting class provides a Read(~) function overload for each of the data types that are listed as required in the Specification. It also provides a function that will invoke Read(~) 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 CanReadRequiredData<MyClass, MySpecification>
{
// ... define my class ...
};

You may also use CanReadExpectedData if you want to further guarantee that your class is able to read all the expected data. This is recommended, because otherwise it might be easy to quietly overlook data types that you assumed were being read, resulting in incorrect behavior.

Note that you are allowed to inherit both CanReadRequiredData and CanReadExpectedData while passing different Specifications to each, but you should be aware that ReadRequiredData will only read the data required by the Specification that is given to CanReadRequiredData. Likewise, ReadExpectedData will only read the data expected by the Specification that is given to CanReadExpectedData.

While you can technically inherit CanReadRequiredData 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 ReadRequiredData(~). Instead, it is beter to inherit it once and combine the Specifications using SpecifyData<Specification1, Specification2, ...>. For example:

class MyClass : public CanReadRequiredData<
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 Read(~) functions. See the page ReadCompilationFail for more information.

Constructor & Destructor Documentation

◆ CanReadRequiredData()

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

Member Function Documentation

◆ ReadRequiredData()

void ReadRequiredData ( const CompositeType &  _data,
const ReadOptions _options = ReadOptions() 
)

Call this function to read all the types in _data that are listed as required in the Specification. Setting _options.onlyReadUnqueriedData to true will make it so that only data entries that have not been queried will be passed to the Read(~) function. If _options.onlyReadUnqueriedData is false, then all data that the Specification lists as required will be read.

Parameters
[in]_dataCompositeData instance to read from.
[in]_optionsReadOptions for customizing the read operation.

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