|
BehaviorTree
Core Library to create and execute Behavior Trees
|
Registry for polymorphic shared_ptr cast relationships. More...
#include <polymorphic_cast_registry.hpp>
Public Types | |
| using | CastFunction = std::function< linb::any(const linb::any &)> |
Public Member Functions | |
| PolymorphicCastRegistry (const PolymorphicCastRegistry &)=delete | |
| PolymorphicCastRegistry & | operator= (const PolymorphicCastRegistry &)=delete |
| PolymorphicCastRegistry (PolymorphicCastRegistry &&)=delete | |
| PolymorphicCastRegistry & | operator= (PolymorphicCastRegistry &&)=delete |
| template<typename Derived , typename Base > | |
| void | registerCast () |
| Register a Derived -> Base inheritance relationship. | |
| bool | isConvertible (std::type_index from_type, std::type_index to_type) const |
| Check if from_type can be converted to to_type. | |
| bool | canUpcast (std::type_index from_type, std::type_index to_type) const |
| Check if from_type can be UPCAST to to_type (not downcast). | |
| nonstd::expected< linb::any, std::string > | tryCast (const linb::any &from, std::type_index from_type, std::type_index to_type) const |
| Attempt to cast the value to the target type. | |
| std::set< std::type_index > | getBaseTypes (std::type_index type) const |
| Get all registered base types for a given type. | |
| void | clear () |
| Clear all registrations (mainly for testing). | |
Registry for polymorphic shared_ptr cast relationships.
This enables passing shared_ptr<Derived> to ports expecting shared_ptr<Base> without breaking ABI compatibility. Users register inheritance relationships at runtime, and the registry handles upcasting/downcasting transparently.
This class is typically owned by BehaviorTreeFactory and passed to Blackboard during tree creation. This avoids global state and makes testing easier.
Usage with BehaviorTreeFactory: BehaviorTreeFactory factory; factory.registerPolymorphicCast<Cat, Animal>(); factory.registerPolymorphicCast<Sphynx, Cat>(); auto tree = factory.createTreeFromText(xml);
|
inline |
Check if from_type can be UPCAST to to_type (not downcast).
This is stricter than isConvertible - only allows going from derived to base, not the reverse.
|
inline |
Check if from_type can be converted to to_type.
Returns true if:
|
inline |
Register a Derived -> Base inheritance relationship.
This enables:
| Derived | The derived class (must inherit from Base) |
| Base | The base class (must be polymorphic - have virtual functions) |
|
inline |
Attempt to cast the value to the target type.
| from | The source any containing a shared_ptr |
| from_type | The type_index of the stored type |
| to_type | The target type_index |