-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeScanner.cpp
112 lines (96 loc) · 2.37 KB
/
NodeScanner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* xNodeWrapper.cpp
*
* Created on: Nov 19, 2014
* Author: matthijs
*/
#include <sstream>
#include "NodeScanner.h"
NodeScanner::NodeScanner(NodeScanner * n, NodeType o, Edge l) :
Node(n, o), connection(l) {
if (hasParent()) getParent()->addChild(this);
}
NodeScanner::~NodeScanner() {
clearParent();
clearChildren();
}
void NodeScanner::setName(const std::string& n) {
Node::setName(n);
if (n.compare("*") == 0) {
wildcard = true;
}
}
void NodeScanner::onNewNode(Node *node) {
// std::cout << std::endl;
if (node && cmpDir(node)) {
notifyFoundNode(node);
}
}
bool NodeScanner::cmpDir(Node *query, const NodeScanner *source) const {
if (!query) {
return false;
} else if (query->getType() == getType() && (isWildcard() || getName().compare(query->getName()) == 0)) {
switch (getConnectionType()) {
case EDGE_ROOT:
return true;
case EDGE_ANCESTOR:
case EDGE_DIRECT:
return !hasParent() || getParent()->cmpDir(query->getParent(), this);
}
} else if (source) {
switch (source->getConnectionType()) {
case EDGE_ROOT:
return false;
case EDGE_ANCESTOR:
return cmpDir(query->getParent(), source);
case EDGE_DIRECT:
return false;
}
}
return false;
}
NodeScanner::Edge NodeScanner::getConnectionType() const {
return connection;
}
std::string NodeScanner::toString() const {
std::stringstream summary;
summary << getID() << ":";
switch (connection) {
case EDGE_DIRECT:
summary << "/";
break;
case EDGE_ANCESTOR:
summary << "//";
break;
default:
summary << "";
break;
}
summary << getName();
return summary.str();
}
bool NodeScanner::isWildcard() const {
return wildcard;
}
NodeScanner *NodeScanner::getParent() const {
return static_cast<NodeScanner *>(Parent::getParent());
}
void NodeScanner::setParent(NodeScanner * parent) {
Node::setParent(parent);
}
void NodeScanner::addListener(NodeScannerListener *l) {
NodeScannerAdapter::addListener(l);
}
void NodeScanner::removeListener(NodeScannerListener *l) {
NodeScannerAdapter::removeListener(l);
}
bool NodeScanner::hasListener(NodeScannerListener *l) {
return NodeScannerAdapter::hasListener(l);
}
void merge(NodeScanner *keep, NodeScanner *remove) {
for(NodeScanner * child : remove->getChildren()) child->setParent(keep);
if(remove->hasParent()) {
remove->getParent()->removeChild(remove);
remove->getParent()->addChild(keep);
}
}