From e3cf0a9d726c9d76f4938590691336fbf2e9f6d5 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 14 Nov 2014 13:52:40 +0100 Subject: Moved Managed to core and implemented managing of nodes for the CSS Style Tree. --- src/core/utils/CSSParser.hpp | 81 +++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 39 deletions(-) (limited to 'src/core/utils/CSSParser.hpp') diff --git a/src/core/utils/CSSParser.hpp b/src/core/utils/CSSParser.hpp index 8db5cdd..0f9cd8f 100644 --- a/src/core/utils/CSSParser.hpp +++ b/src/core/utils/CSSParser.hpp @@ -24,6 +24,9 @@ #include #include +#include +#include + #include "BufferedCharReader.hpp" namespace ousia { @@ -62,14 +65,15 @@ bool operator==(const Specificity &x, const Specificity &y) return std::tie(x.b, x.c, x.d) == std::tie(y.b, y.c, y.d); } -class RuleSet { +class RuleSet : public Managed { private: const std::map values; const Specificity specificity; public: - RuleSet(std::map values, Specificity specificity) - : values(values), specificity(specificity) + RuleSet(Manager &mgr, std::map values, + Specificity specificity) + : Managed(mgr), values(std::move(values)), specificity(specificity) { } @@ -90,7 +94,7 @@ private: public: PseudoSelector(std::string name, std::vector args, bool generative) - : name(name), args(args), generative(generative) + : name(std::move(name)), args(std::move(args)), generative(generative) { } @@ -103,53 +107,52 @@ public: enum class SelectionOperator { DESCENDANT, DIRECT_DESCENDANT }; -// TODO: Subclass of Andreas' Node class -class StyleEdge { -private: - // TODO: This is wrong! Here we want to have a managed pointer as Andreas - // mentioned! - // const StyleNode target; - const SelectionOperator selectionOperator; - +class StyleNode : public dom::Node { public: - StyleEdge(/*StyleNode target,*/ SelectionOperator selectionOperator) - : /*target(target),*/ selectionOperator(selectionOperator) - { - } - - // const StyleNode &getTarget() const { return target; } + class StyleEdge : public Managed { + private: + Owned target; + const SelectionOperator selectionOperator; + + public: + StyleEdge(Manager &mgr, Handle target, + SelectionOperator selectionOperator) + : Managed(mgr), + target(acquire(target)), + selectionOperator(selectionOperator) + { + } + + Rooted getTarget() const { return target; } + + const SelectionOperator &getSelectionOperator() const + { + return selectionOperator; + } + }; - const SelectionOperator &getSelectionOperator() const - { - return selectionOperator; - } -}; - -// TODO: Subclass of Andreas' Node class -class StyleNode { private: - const std::string className; const PseudoSelector pseudoSelector; - const std::vector edges; - const std::vector ruleSets; + std::vector> edges; + const std::vector> ruleSets; public: - StyleNode(std::string className, PseudoSelector pseudoSelector, - std::vector edges, std::vector ruleSets) - : className(className), - pseudoSelector(pseudoSelector), - edges(edges), - ruleSets(ruleSets) + StyleNode(Manager &mgr, std::string name, + PseudoSelector pseudoSelector, + const std::vector> &edges, + const std::vector> &ruleSets) + : dom::Node(mgr, std::move(name)), + pseudoSelector(std::move(pseudoSelector)), + edges(acquire(edges)), + ruleSets(acquire(ruleSets)) { } - const std::string &getClassName() const { return className; } - const PseudoSelector &getPseudoSelector() const { return pseudoSelector; } - const std::vector &getEdges() const { return edges; } + const std::vector> &getEdges() const { return edges; } - const std::vector &getRuleSets() const { return ruleSets; } + const std::vector> &getRuleSets() const { return ruleSets; } }; class CSSParser { -- cgit v1.2.3