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:
S | is the System subclass that this object will convert from and to. |
U | the source scalar type (to convert from), which must be one of the default scalars. |
T | the resulting scalar type (to convert into), which must be one of the default scalars. |
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 | |
SystemScalarConverter & | operator= (const SystemScalarConverter &)=default |
SystemScalarConverter (SystemScalarConverter &&)=default | |
SystemScalarConverter & | operator= (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 > &)> &) |
|
default |
|
default |
(Advanced) Creates a converter that supports no conversions.
The single- argument constructor below is the overload intended for users.
SystemScalarConverter | ( | SystemTypeTag< S > | ) |
Creates a converter that uses S's scalar-converting copy constructor to perform system scalar conversion.
That constructor takes the form of:
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.
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.
bool empty | ( | ) | const |
Returns true iff no conversions are supported.
(In other words, whether this is a default-constructed object.)
bool IsConvertible | ( | ) | const |
bool IsConvertible | ( | const std::type_info & | t_info, |
const std::type_info & | u_info | ||
) | const |
|
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.
|
default |
|
default |
void Remove | ( | ) |
Removes from this converter the ability to convert from System to System<T>.
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
.
|
friend |