From fddd8a6fc3c9a7971111a345a83283a0a1662f9f Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 5 Dec 2014 14:13:36 +0100 Subject: Added compilable version of RuleSets to the CSS.hpp. --- src/core/CSS.hpp | 84 +++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) (limited to 'src/core/CSS.hpp') diff --git a/src/core/CSS.hpp b/src/core/CSS.hpp index 1f5fedc..3b4289a 100644 --- a/src/core/CSS.hpp +++ b/src/core/CSS.hpp @@ -23,6 +23,8 @@ #include #include +#include + #include "Managed.hpp" #include "Node.hpp" @@ -44,51 +46,43 @@ struct Specificity { int d; Specificity(int b, int c, int d) : b(b), c(c), d(d) {} -}; -// TODO: Is this inline usage correct? I used this to prevent "multiple -// definition" errors -inline 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); -} + friend 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); + } -inline 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); -} + friend 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); + } -inline 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); -} + friend 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); + } +}; /** * The RuleSet class serves as a container class for key-value * pairs. The values are TypeInstances. The proper type is * implicitly defined by the keyword. - * - * TODO: This code is currently commented out until the TypeSystem works. */ -/*class RuleSet : public Managed { +class RuleSet : public Managed { private: - const std::map values; - const Specificity specificity; + const std::map values; public: - RuleSet(Manager &mgr, std::map values, - Specificity specificity) - : Managed(mgr), values(std::move(values)), specificity(specificity) - { - } - - const std::map &getValues() const - { - return values; - } + /** + * Initializes an empty RuleSet. + */ + RuleSet(Manager &mgr) : Managed(mgr), values() {} - const Specificity &getSpecificity() const { return specificity; } -};*/ + const std::map &getValues() const + { + return values; + } +}; /** * PseudoSelectors are functions that change the behaviour of Selectors. @@ -249,8 +243,7 @@ public: private: const PseudoSelector pseudoSelector; ManagedVector edges; - // TODO: This is temporarily commented out until the TypeSystem works. - // Owned ruleSets; + Owned ruleSet; bool accepting; /** @@ -261,21 +254,28 @@ private: const PseudoSelector *select); public: + + /** + * This initializes an empty SelectorNode with the given name and the + * given PseudoSelector. + */ SelectorNode(Manager &mgr, std::string name, PseudoSelector pseudoSelector) : Node(mgr, std::move(name)), pseudoSelector(std::move(pseudoSelector)), - edges(this) //, - // TODO: This is temporarily commented out until the TypeSystem works. - // ruleSets(acquire(ruleSets)) + edges(this), + ruleSet(new RuleSet(mgr), this) { } + /** + * This initializes an empty SelectorNode with the given name and the + * trivial PseudoSelector "true". + */ SelectorNode(Manager &mgr, std::string name) : Node(mgr, std::move(name)), pseudoSelector("true", false), - edges(this) //, - // TODO: This is temporarily commented out until the TypeSystem works. - // ruleSets(acquire(ruleSets)) + edges(this), + ruleSet(new RuleSet(mgr), this) { } @@ -283,9 +283,7 @@ public: ManagedVector &getEdges() { return edges; } - // TODO: This is temporarily commented out until the TypeSystem works. - // const std::vector> &getRuleSets() const { return - // ruleSets; } + Rooted getRuleSet() const { return ruleSet; } /** * This returns the child of this SelectorNode that is connected by -- cgit v1.2.3