bpmn++
A BPMN parser library, written in C++
Loading...
Searching...
No Matches
Node.cpp
Go to the documentation of this file.
1#include "Node.h"
2#include "Scope.h"
3
4using namespace BPMN;
5
7 : BaseElement(element)
8{
9}
10
11Node* Node::find(std::function<bool(Node*)> condition) {
12 if (condition(this)) {
13 return this;
14 }
15
16 if (Scope* scope = this->represents<Scope>(); scope) {
17 for (auto& childNode : scope->childNodes) {
18 Node* node = childNode.get();
19 Node* result = node->find(condition);
20 if (result != nullptr) {
21 return result;
22 }
23 }
24 }
25 return nullptr;
26}
27
28const Node* Node::find(std::function<bool(const Node*)> condition) const {
29 if (condition(this)) {
30 return this;
31 }
32
33 if (const Scope* scope = this->represents<Scope>(); scope) {
34 for (const auto& childNode : scope->childNodes) {
35 const Node* node = childNode.get();
36 const Node* result = node->find(condition);
37 if (result != nullptr) {
38 return result;
39 }
40 }
41 }
42 return nullptr;
43}
44
45std::vector< Node* > Node::find_all(std::function<bool(Node*)> condition) {
46 std::vector< Node* > result;
47
48 if (condition(this)) {
49 result.push_back(this);
50 }
51
52 if ( Scope* scope = this->represents<Scope>(); scope ) {
53 for ( auto &childNode : scope->childNodes) {
54 Node* node = childNode.get();
55 std::vector< Node* > childResults = node->find_all(condition);
56 result.insert(result.end(), childResults.begin(), childResults.end());
57 }
58 }
59
60 return result;
61}
62
63std::vector< const Node* > Node::find_all(std::function<bool(const Node*)> condition) const {
64 std::vector< const Node* > result;
65
66 if (condition(this)) {
67 result.push_back(this);
68 }
69
70 if ( const Scope* scope = this->represents<Scope>(); scope ) {
71 for ( const auto& childNode : scope->childNodes) {
72 const Node* node = childNode.get();
73 std::vector< const Node* > childResults = node->find_all(condition);
74 result.insert(result.end(), childResults.begin(), childResults.end());
75 }
76 }
77
78 return result;
79}
80
Base class for all core BPMN elements.
Definition BaseElement.h:15
T * get()
Casts the element to the specified type T.
Definition BaseElement.h:47
Base class for all nodes in a BPMN model.
Definition Node.h:24
Node * find(std::function< bool(Node *)> condition)
Returns the first node found matching a given condition.
Definition Node.cpp:11
Node(XML::bpmn::tBaseElement *element)
Constructs a Node object representing a BPMN process or flow node.
Definition Node.cpp:6
std::vector< Node * > find_all(std::function< bool(Node *)> condition)
Returns all nodes matching a given condition.
Definition Node.cpp:45
Base class for BPMN elements that may contain a ChildNode elements.
Definition Scope.h:24
The BPMN namespace contains linked classes representing a BPMN model.