Skip to content

Commit ec926aa

Browse files
committed
[modelling/dynamics] Add templated casting-getters for underlying DAE/ODE for IntegratorAbstract and ExplicitIntegratorAbstract
1 parent 7f7dfca commit ec926aa

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Templated getters `getCost<U>()` and `getDynamics<U>()` in the StageModel class, to get the concrete type.
12+
- Templated getters `getCost<U>()` and `getDynamics<U>()` in the StageModel class, and another `getDynamics<U>()` for integrator classes, to get the concrete types ([##205](https://github.com/Simple-Robotics/aligator/pull/205))
1313

1414
### Changed
1515

include/aligator/modelling/dynamics/integrator-abstract.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ struct IntegratorAbstractTpl : DynamicsModelTpl<_Scalar> {
3131
/// The underlying continuous dynamics.
3232
xyz::polymorphic<ContinuousDynamics> continuous_dynamics_;
3333

34+
template <typename U> U *getDynamics() {
35+
return dynamic_cast<U *>(&*continuous_dynamics_);
36+
}
37+
template <typename U> const U *getDynamics() const {
38+
return dynamic_cast<const U *>(&*continuous_dynamics_);
39+
}
40+
3441
/// Constructor from instances of DynamicsType.
3542
explicit IntegratorAbstractTpl(
3643
const xyz::polymorphic<ContinuousDynamics> &cont_dynamics);

include/aligator/modelling/dynamics/integrator-explicit.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ struct ExplicitIntegratorAbstractTpl : ExplicitDynamicsModelTpl<_Scalar> {
3232

3333
xyz::polymorphic<ODEType> ode_;
3434

35+
template <typename U> U *getDynamics() { return dynamic_cast<U *>(&*ode_); }
36+
template <typename U> const U *getDynamics() const {
37+
return dynamic_cast<const U *>(&*ode_);
38+
}
39+
3540
explicit ExplicitIntegratorAbstractTpl(
3641
const xyz::polymorphic<ODEType> &cont_dynamics);
3742
virtual ~ExplicitIntegratorAbstractTpl() = default;

0 commit comments

Comments
 (0)