|
10 | 10 |
|
11 | 11 | namespace aligator { |
12 | 12 |
|
| 13 | +#define ALIGATOR_CHECK_DERIVED_CLASS(Base, Derived) \ |
| 14 | + static_assert((std::is_base_of_v<Base, Derived>), \ |
| 15 | + "Failed check for derived class.") |
| 16 | + |
13 | 17 | /** @brief A stage in the control problem. |
14 | 18 | * |
15 | 19 | * @details Each stage containts cost functions, dynamical |
@@ -46,6 +50,30 @@ template <typename _Scalar> struct StageModelTpl { |
46 | 50 | /// Dynamics model |
47 | 51 | PolyDynamics dynamics_; |
48 | 52 |
|
| 53 | + /// @brief Get a pointer to an expected concrete type for the cost function. |
| 54 | + template <typename U> U *getCost() { |
| 55 | + ALIGATOR_CHECK_DERIVED_CLASS(Cost, U); |
| 56 | + return dynamic_cast<U *>(&*cost_); |
| 57 | + } |
| 58 | + |
| 59 | + /// @copybrief castCost() |
| 60 | + template <typename U> const U *getCost() const { |
| 61 | + ALIGATOR_CHECK_DERIVED_CLASS(Cost, U); |
| 62 | + return dynamic_cast<const U *>(&*cost_); |
| 63 | + } |
| 64 | + |
| 65 | + /// @brief Get a pointer to an expected concrete type for the dynamics class. |
| 66 | + template <typename U> U *getDynamics() { |
| 67 | + ALIGATOR_CHECK_DERIVED_CLASS(Dynamics, U); |
| 68 | + return dynamic_cast<U *>(&*dynamics_); |
| 69 | + } |
| 70 | + |
| 71 | + /// @copybrief castDynamics() |
| 72 | + template <typename U> const U *getDynamics() const { |
| 73 | + ALIGATOR_CHECK_DERIVED_CLASS(Dynamics, U); |
| 74 | + return dynamic_cast<const U *>(&*dynamics_); |
| 75 | + } |
| 76 | + |
49 | 77 | /// Constructor assumes the control space is a Euclidean space of |
50 | 78 | /// dimension @p nu. |
51 | 79 | StageModelTpl(const PolyCost &cost, const PolyDynamics &dynamics); |
|
0 commit comments