-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.cpp
74 lines (61 loc) · 1.53 KB
/
Factory.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
/*
* xPath.cpp
*
* Created on: Dec 9, 2014
* Author: matthijs
*/
#include "Factory.h"
#include "Globals.h"
#include "Xpath.h"
#include <sstream>
#include <string>
Factory::Factory(const std::string &xpath) : Name("factory") {
for (const Xpath& x : XPathCollection(xpath)) {
XPathScanner *path = new XPathScanner(x);
path->addListener(this);
structures.push_back(path);
}
}
Factory::~Factory() {
Globals::DESTRUCTING = true;
deleteXPathScanners();
}
void Factory::setAdapter(SaxParserAdapter *parser) {
for (XPathScanner *tree : structures) {
tree->setAdapter(parser);
}
}
void Factory::moveStream(std::stringstream& stream) {
stream.seekp(0, std::ios::end);
std::stringstream::pos_type offset = stream.tellp();
if ((int)offset != 0) {
stream.seekp(0, std::ios::beg);
notifyOutput(stream);
}
}
size_t Factory::getXPathScannerSize() const {
size_t n = 0;
for (XPathScanner * scanner : structures) {
n += scanner->getSize();
}
return n;
}
double Factory::getEfficiency() const {
return 1;
}
std::string Factory::toString() const {
std::stringstream s;
s << getEfficiency() << "%";
return s.str();
}
void Factory::onNewXPathMatch(Node *node) {
XPathScannerListener::onNewXPathMatch(node);
notifyHit(node);
}
void Factory::deleteXPathScanners() {
for (auto it = structures.begin(); it != structures.end(); ) {
XPathScanner * scanner = *it;
it = structures.erase(it);
delete scanner;
}
}