diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-03 11:39:07 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-03 11:39:07 +0100 |
commit | 4a398a6771b42e1c928e2cbee35f8e5645e40369 (patch) | |
tree | b9c192599b65abe777b01f41ff493264cce32eba /src/core/CSS.cpp | |
parent | 41366eb61e5b85524b8ee07ae183df4f9f8a1f6d (diff) |
implemented SelectorNode::append, which is not tested yet.
Diffstat (limited to 'src/core/CSS.cpp')
-rw-r--r-- | src/core/CSS.cpp | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/core/CSS.cpp b/src/core/CSS.cpp index 06d062e..c2397d1 100644 --- a/src/core/CSS.cpp +++ b/src/core/CSS.cpp @@ -20,24 +20,19 @@ namespace ousia { -/** - * This returns all children of this SelectorNode that are connected by - * the given operator, have the given className and the given - * PseudoSelector. - */ std::vector<Rooted<SelectorNode>> SelectorNode::getChildren( const SelectionOperator &op, const std::string &className, const PseudoSelector &select) { std::vector<Rooted<SelectorNode>> out; - for(auto& e : edges){ - if(e->getSelectionOperator() != op){ + for (auto &e : edges) { + if (e->getSelectionOperator() != op) { continue; } - if(e->getTarget()->getName() != className){ + if (e->getTarget()->getName() != className) { continue; } - if(e->getTarget()->getPseudoSelector() != select){ + if (e->getTarget()->getPseudoSelector() != select) { continue; } out.push_back(e->getTarget()); @@ -45,5 +40,36 @@ std::vector<Rooted<SelectorNode>> SelectorNode::getChildren( return out; } - +std::vector<Rooted<SelectorNode>> SelectorNode::append( + Rooted<SelectorEdge> edge) +{ + std::vector<Rooted<SelectorNode>> out; + // look if we already have a child in an equivalent edge. + std::vector<Rooted<SelectorNode>> children = + getChildren(edge->getSelectionOperator(), edge->getTarget()->getName(), + edge->getTarget()->getPseudoSelector()); + // note that this can only be one child or no child. + if (children.size() == 0) { + // if there is no child the appending process is trivial: We can just + // add the whole subtree represented by the other node as child here. + edges.push_back(edge); + } else { + // otherwise we start the appending process recursively on the child + // level. + // TODO: RuleSet merging + if (edge->getTarget()->getEdges().size() == 0) { + // if there are no more subsequent edges this is a leafe we could + // not merge, because it is already present in the Tree. + out.push_back(edge->getTarget()); + } else { + // otherwise we go into recursion. + for (auto &e : edge->getTarget()->getEdges()) { + std::vector<Rooted<SelectorNode>> childLeafs = + children[0]->append(e); + out.insert(out.end(), childLeafs.begin(), childLeafs.end()); + } + } + } + return out; +} } |