Drake
Drake C++ Documentation
SystemScalarConverter Class Reference

Detailed Description

Helper class to convert a System into a System<T>, intended for internal use by the System framework, not directly by users.

For user-facing documentation see System Scalar Conversion.

Because it is not templated on a System subclass, this class can be used by LeafSystem without any direct knowledge of the subtypes being converted. In other words, it enables a runtime flavor of the CRTP.

Throughout this class, the following template naming convention applies:

Template Parameters
Sis the System subclass that this object will convert from and to.
Uthe source scalar type (to convert from), which must be one of the default scalars.
Tthe resulting scalar type (to convert into), which must be one of the default scalars.
Note
Conversions where T and U types are the same are not supported. Template functions such as IsConvertible<T, U>() are still callable, but will always return false, null, etc.

#include <drake/systems/framework/system_scalar_converter.h>

Public Member Functions

 SystemScalarConverter ()
 (Advanced) Creates a converter that supports no conversions. More...
 
template<template< typename > class S>
 SystemScalarConverter (SystemTypeTag< S >)
 Creates a converter that uses S's scalar-converting copy constructor to perform system scalar conversion. More...
 
bool empty () const
 Returns true iff no conversions are supported. More...
 
void RemoveUnlessAlsoSupportedBy (const SystemScalarConverter &other)
 Removes from this converter all pairs where other.IsConvertible<T, U> is false. More...
 
template<typename T , typename U >
void Remove ()
 Removes from this converter the ability to convert from System to System<T>. More...
 
template<typename T , typename U >
bool IsConvertible () const
 Returns true iff this object can convert a System into a System<T>, i.e., whether Convert() will return non-null. More...
 
bool IsConvertible (const std::type_info &t_info, const std::type_info &u_info) const
 Returns true iff this object can convert a System into a System<T>, i.e., whether Convert() will return non-null. More...
 
template<typename T , typename U >
std::unique_ptr< System< T > > Convert (const System< U > &other) const
 Converts a System into a System<T>. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 SystemScalarConverter (const SystemScalarConverter &)=default
 
SystemScalarConverteroperator= (const SystemScalarConverter &)=default
 
 SystemScalarConverter (SystemScalarConverter &&)=default
 
SystemScalarConverteroperator= (SystemScalarConverter &&)=default
 

Static Public Member Functions

template<template< typename > class S>
static SystemScalarConverter MakeWithoutSubtypeChecking ()
 (Advanced) Creates a converter similar to the single-argument constructor, with the built-in checks for guaranteed subtype preservation of the System turned off. More...
 

Friends

template<typename T , typename U >
void system_scalar_converter_internal::AddPydrakeConverterFunction (SystemScalarConverter *, const std::function< System< T > *(const System< U > &)> &)
 

Constructor & Destructor Documentation

◆ SystemScalarConverter() [1/4]

◆ SystemScalarConverter() [2/4]

◆ SystemScalarConverter() [3/4]

(Advanced) Creates a converter that supports no conversions.

The single- argument constructor below is the overload intended for users.

◆ SystemScalarConverter() [4/4]

Creates a converter that uses S's scalar-converting copy constructor to perform system scalar conversion.

That constructor takes the form of:

template <typename T>
class FooSystem final : public LeafSystem<T> {
template <typename U>
explicit FooSystem(const FooSystem<U>& other);
};

By default, the converter supports conversions to and from all of the default scalars, but systems may specialize the scalar_conversion::Traits to disable support for some or all of these conversions. Conversions where T and U types are the same are not supported.

This an implicit conversion constructor (not marked explicit), in order to make calling code substantially more readable, with relatively little risk of an unwanted accidental conversion happening.

See System Scalar Conversion for additional overview documentation.

Member Function Documentation

◆ Convert()

std::unique_ptr<System<T> > Convert ( const System< U > &  other) const

Converts a System into a System<T>.

This is the API that LeafSystem uses to provide a default implementation of DoToAutoDiffXd, etc. Returns null when IsConvertible() is false.

◆ empty()

bool empty ( ) const

Returns true iff no conversions are supported.

(In other words, whether this is a default-constructed object.)

◆ IsConvertible() [1/2]

bool IsConvertible ( ) const

Returns true iff this object can convert a System into a System<T>, i.e., whether Convert() will return non-null.

◆ IsConvertible() [2/2]

bool IsConvertible ( const std::type_info &  t_info,
const std::type_info &  u_info 
) const

Returns true iff this object can convert a System into a System<T>, i.e., whether Convert() will return non-null.

◆ MakeWithoutSubtypeChecking()

static SystemScalarConverter MakeWithoutSubtypeChecking ( )
static

(Advanced) Creates a converter similar to the single-argument constructor, with the built-in checks for guaranteed subtype preservation of the System turned off.

In general, subtype preservation is an important invariant of scalar conversion, so be extremely cautious about disabling it.

◆ operator=() [1/2]

SystemScalarConverter& operator= ( const SystemScalarConverter )
default

◆ operator=() [2/2]

SystemScalarConverter& operator= ( SystemScalarConverter &&  )
default

◆ Remove()

void Remove ( )

Removes from this converter the ability to convert from System to System<T>.

◆ RemoveUnlessAlsoSupportedBy()

void RemoveUnlessAlsoSupportedBy ( const SystemScalarConverter other)

Removes from this converter all pairs where other.IsConvertible<T, U> is false.

The subtype S need not be the same between this and other.

Friends And Related Function Documentation

◆ system_scalar_converter_internal::AddPydrakeConverterFunction

void system_scalar_converter_internal::AddPydrakeConverterFunction ( SystemScalarConverter ,
const std::function< System< T > *(const System< U > &)> &   
)
friend

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