diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-11-14 13:52:40 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-11-14 13:52:40 +0100 |
commit | e3cf0a9d726c9d76f4938590691336fbf2e9f6d5 (patch) | |
tree | 2e2307a8ad7ed0912e611de65c1bf053a2c8e42a /src/core | |
parent | 46fadba6f804b44a726b5b2de1bac188a1785a54 (diff) |
Moved Managed to core and implemented managing of nodes for the CSS Style Tree.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Managed.cpp (renamed from src/core/dom/Managed.cpp) | 3 | ||||
-rw-r--r-- | src/core/Managed.hpp (renamed from src/core/dom/Managed.hpp) | 42 | ||||
-rw-r--r-- | src/core/dom/Node.hpp | 2 | ||||
-rw-r--r-- | src/core/utils/CSSParser.cpp | 10 | ||||
-rw-r--r-- | src/core/utils/CSSParser.hpp | 81 |
5 files changed, 80 insertions, 58 deletions
diff --git a/src/core/dom/Managed.cpp b/src/core/Managed.cpp index ec3849f..8cbbb17 100644 --- a/src/core/dom/Managed.cpp +++ b/src/core/Managed.cpp @@ -22,7 +22,6 @@ #include "Managed.hpp" namespace ousia { -namespace dom { /* Private Class ScopedIncrement */ @@ -363,5 +362,3 @@ void Manager::sweep() } } } -} - diff --git a/src/core/dom/Managed.hpp b/src/core/Managed.hpp index deccb99..8cef1d2 100644 --- a/src/core/dom/Managed.hpp +++ b/src/core/Managed.hpp @@ -16,8 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _OUSIA_DOM_MANAGED_HPP_ -#define _OUSIA_DOM_MANAGED_HPP_ +#ifndef _OUSIA_MANAGED_HPP_ +#define _OUSIA_MANAGED_HPP_ #include <iostream> #include <map> @@ -26,7 +26,6 @@ #include <unordered_set> namespace ousia { -namespace dom { // TODO: Implement clone, getReferenced and getReferencing @@ -186,7 +185,8 @@ protected: int deletionRecursionDepth = 0; /** - * Returns the object ObjectDescriptor for the given object from the objects map. + * Returns the object ObjectDescriptor for the given object from the objects + * map. */ ObjectDescriptor *getDescriptor(Managed *o); @@ -307,6 +307,26 @@ public: { return Owned<T>{t, this}; } + + template <class T> + std::vector<Owned<T>> acquire(const std::vector<Handle<T>> &vec) + { + std::vector<Owned<T>> res; + for (auto &e : vec) { + res.push_back(acquire(e)); + } + return res; + } + + template <class T> + std::vector<Owned<T>> acquire(const std::vector<T*> &vec) + { + std::vector<Owned<T>> res; + for (auto &e : vec) { + res.push_back(acquire(e)); + } + return res; + } }; /** @@ -326,7 +346,8 @@ protected: friend class Rooted<T>; friend class Owned<T>; - static_assert(std::is_convertible<T*, Managed*>::value, "T must be a Managed"); + static_assert(std::is_convertible<T *, Managed *>::value, + "T must be a Managed"); /** * Reference to the represented managed object. @@ -389,8 +410,11 @@ public: /** * Comparison operator between base Owned and base Owned. */ - template<class T2> - bool operator==(const Handle<T2> &h) const { return ptr == h.get(); } + template <class T2> + bool operator==(const Handle<T2> &h) const + { + return ptr == h.get(); + } /** * Comparison operator between base Owned and pointer. @@ -682,9 +706,7 @@ public: */ Managed *getOwner() const { return owner; } }; - -} } -#endif /* _OUSIA_DOM_MANAGED_HPP_ */ +#endif /* _OUSIA_MANAGED_HPP_ */ diff --git a/src/core/dom/Node.hpp b/src/core/dom/Node.hpp index 9c006a1..98a51d9 100644 --- a/src/core/dom/Node.hpp +++ b/src/core/dom/Node.hpp @@ -24,7 +24,7 @@ #include <functional> #include <unordered_set> -#include "Managed.hpp" +#include <core/Managed.hpp> namespace ousia { namespace dom { diff --git a/src/core/utils/CSSParser.cpp b/src/core/utils/CSSParser.cpp index e66eb34..1639152 100644 --- a/src/core/utils/CSSParser.cpp +++ b/src/core/utils/CSSParser.cpp @@ -44,11 +44,11 @@ static const TokenTreeNode CSS_ROOT{{{"{", CURLY_OPEN}, {"/*", COMMENT_OPEN}, {"*/", COMMENT_CLOSE}}}; -StyleNode CSSParser::parse(BufferedCharReader &input) { - Tokenizer tokenizer {input, CSS_ROOT}; - //TODO: implement - -} +//StyleNode CSSParser::parse(BufferedCharReader &input) { +// Tokenizer tokenizer {input, CSS_ROOT}; +// //TODO: implement +// +//} 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 <vector> #include <tuple> +#include <core/Managed.hpp> +#include <core/dom/Node.hpp> + #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<std::string, std::string> values; const Specificity specificity; public: - RuleSet(std::map<std::string, std::string> values, Specificity specificity) - : values(values), specificity(specificity) + RuleSet(Manager &mgr, std::map<std::string, std::string> values, + Specificity specificity) + : Managed(mgr), values(std::move(values)), specificity(specificity) { } @@ -90,7 +94,7 @@ private: public: PseudoSelector(std::string name, std::vector<std::string> 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<StyleNode> target; + const SelectionOperator selectionOperator; + + public: + StyleEdge(Manager &mgr, Handle<StyleNode> target, + SelectionOperator selectionOperator) + : Managed(mgr), + target(acquire(target)), + selectionOperator(selectionOperator) + { + } + + Rooted<StyleNode> 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<StyleEdge> edges; - const std::vector<RuleSet> ruleSets; + std::vector<Owned<StyleEdge>> edges; + const std::vector<Owned<RuleSet>> ruleSets; public: - StyleNode(std::string className, PseudoSelector pseudoSelector, - std::vector<StyleEdge> edges, std::vector<RuleSet> ruleSets) - : className(className), - pseudoSelector(pseudoSelector), - edges(edges), - ruleSets(ruleSets) + StyleNode(Manager &mgr, std::string name, + PseudoSelector pseudoSelector, + const std::vector<Handle<StyleEdge>> &edges, + const std::vector<Handle<RuleSet>> &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<StyleEdge> &getEdges() const { return edges; } + const std::vector<Owned<StyleEdge>> &getEdges() const { return edges; } - const std::vector<RuleSet> &getRuleSets() const { return ruleSets; } + const std::vector<Owned<RuleSet>> &getRuleSets() const { return ruleSets; } }; class CSSParser { |