bpmn++
A BPMN parser library, written in C++
Loading...
Searching...
No Matches
MessageFlow.cpp
Go to the documentation of this file.
1#include "MessageFlow.h"
2#include "Model.h"
3#include "Process.h"
4#include "Scope.h"
5#include "FlowNode.h"
6
7using namespace BPMN;
8
10 : BaseElement(messageFlow)
11 , element(messageFlow)
12 , source( {nullptr,nullptr} )
13 , target( {nullptr,nullptr} )
14{
15}
16
17void MessageFlow::initialize(std::vector< std::unique_ptr<Process> >& processes, std::unordered_map<std::string,std::string>& participantMap) {
18 // find source
19 if ( participantMap.contains(element->sourceRef.value.value) ) {
20 // source is provided by participant reference
21 for (auto& process : processes ) {
22 if ( process->id == participantMap[element->sourceRef.value.value] ) {
23 source = { process.get(), nullptr };
24 break;
25 }
26 FlowNode* flowNode = findRecursive(element->sourceRef.value.value, process->as<Scope>());
27 if ( flowNode ) {
28 source = { process.get(), flowNode };
29 break;
30 }
31 }
32 if ( !source.first ) {
33 throw std::runtime_error("MessageFlow: cannot find source of '" + id +"'");
34 }
35 }
36 else {
37 // source is provided by node reference (or empty collapsed participant)
38 for (auto& process : processes ) {
39 FlowNode* flowNode = findRecursive(element->sourceRef.value.value, process->as<Scope>());
40 if ( flowNode ) {
41 source = { process.get(), flowNode };
42 break;
43 }
44 }
45 }
46
47 // find target
48 if ( participantMap.contains(element->targetRef.value.value) ) {
49 for (auto& process : processes ) {
50 if ( process->id == participantMap[element->targetRef.value.value] ) {
51 target = { process.get(), nullptr };
52 break;
53 }
54 FlowNode* flowNode = findRecursive(element->targetRef.value.value, process->as<Scope>());
55 if ( flowNode ) {
56 target = { process.get(), flowNode };
57 break;
58 }
59
60 }
61 if ( !target.first ) {
62 throw std::runtime_error("MessageFlow: cannot find target of '" + id +"'");
63 }
64 }
65 else {
66 // target is provided by node reference (or empty collapsed participant)
67 for (auto& process : processes ) {
68 FlowNode* flowNode = findRecursive(element->targetRef.value.value, process->as<Scope>());
69 if ( flowNode ) {
70 target = { process.get(), flowNode };
71 break;
72 }
73 }
74 }
75}
76
77FlowNode* MessageFlow::findRecursive(std::string& id, Scope* scope) {
78 for ( auto& childNode : scope->childNodes ) {
79 if ( childNode->get<>()->id.has_value() && id == childNode->get<>()->id->get().value.value ) {
80 return childNode->as<FlowNode>();
81 }
82 if ( auto childScope = childNode->represents<Scope>(); childScope ) {
83 FlowNode* flowNode = findRecursive(id, childScope);
84 if ( flowNode ) {
85 return flowNode;
86 }
87 }
88 }
89 return nullptr;
90}
91
Base class for all core BPMN elements.
Definition BaseElement.h:15
std::string id
Id of element.
Definition BaseElement.h:23
T * get()
Casts the element to the specified type T.
Definition BaseElement.h:47
T * as()
Casts the element to the specified type T.
Definition Element.h:38
Base class for BPMN elements that may contain incoming and outgoing sequence flows.
Definition FlowNode.h:20
std::pair< Process *, FlowNode * > target
Reference to the target node of the message flow.
Definition MessageFlow.h:31
MessageFlow(XML::bpmn::tMessageFlow *messageFlow)
Constructs a MessageFlow object based on a XML::bpmn::tMessageFlow element.
XML::bpmn::tMessageFlow * element
Definition MessageFlow.h:26
void initialize(std::vector< std::unique_ptr< Process > > &processes, std::unordered_map< std::string, std::string > &participantMap)
std::pair< Process *, FlowNode * > source
Reference to the source node of the message flow.
Definition MessageFlow.h:29
FlowNode * findRecursive(std::string &id, Scope *scope)
Base class for BPMN elements that may contain a ChildNode elements.
Definition Scope.h:24
std::vector< std::unique_ptr< Node > > childNodes
Vector containing all child nodes within the scope of the nodes.
Definition Scope.h:30
Attribute & sourceRef
Attribute value can be expected to be of type 'std::string'.
Attribute & targetRef
Attribute value can be expected to be of type 'std::string'.
The BPMN namespace contains linked classes representing a BPMN model.
std::string value
Definition XMLObject.h:49