From 345847ce2de9a6000e9d90ddfbc2faa0dbd0c7a5 Mon Sep 17 00:00:00 2001 From: Alexey Fedoseev Date: Fri, 10 May 2024 18:08:01 +0300 Subject: [PATCH] extend C++ library API --- cyberiadamlpp.cpp | 17 +++++++++++++++++ cyberiadamlpp.h | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cyberiadamlpp.cpp b/cyberiadamlpp.cpp index 8ac2989..a6e08c3 100644 --- a/cyberiadamlpp.cpp +++ b/cyberiadamlpp.cpp @@ -2220,6 +2220,23 @@ std::list Document::get_state_machines() return result; } +const StateMachine* Document::get_parent_sm(const Element* element) const +{ + if (element != NULL) { + ElementType type = element->get_type(); + if (type == elementRoot) { + return NULL; + } else if (type == elementSM) { + return static_cast(element); + } else { + CYB_ASSERT(element->get_parent()); + return get_parent_sm(element->get_parent()); + } + } else { + return NULL; + } +} + std::ostream& Document::dump(std::ostream& os) const { Element::dump(os); diff --git a/cyberiadamlpp.h b/cyberiadamlpp.h index ba2a2f7..711d362 100644 --- a/cyberiadamlpp.h +++ b/cyberiadamlpp.h @@ -40,7 +40,7 @@ namespace Cyberiada { // ----------------------------------------------------------------------------- // Cyberiada diagram element types: enum ElementType { - elementRoot, // document (root namespace) + elementRoot = 0, // document (root namespace) elementSM, // state machine elementSimpleState, // simple state elementCompositeState, // composite state @@ -624,6 +624,7 @@ namespace Cyberiada { std::list get_state_machines() const; std::list get_state_machines(); + const StateMachine* get_parent_sm(const Element* element) const; protected: virtual std::ostream& dump(std::ostream& os) const;