srctree

Robin Linden parent abb09c0a acc79680
all: Use default comparison operators where possible

inlinesplit
dom/dom.h added: 13, removed: 32, total 0
@@ -12,21 +12,27 @@ namespace dom {
 
using AttrMap = std::map<std::string, std::string>;
 
struct Text { std::string text; };
struct Text {
std::string text;
bool operator==(Text const &) const = default;
};
 
struct Element {
std::string name;
AttrMap attributes;
bool operator==(Element const &) const = default;
};
 
struct Node {
std::vector<Node> children;
std::variant<Text, Element> data;
bool operator==(Node const &) const = default;
};
 
struct Document {
std::string doctype;
Node html;
bool operator==(Document const &) const = default;
};
 
inline Document create_document(std::string_view doctype, Node html) {
@@ -45,22 +51,6 @@ std::vector<Node const *> nodes_by_path(Node const &root, std::string_view path)
 
std::string to_string(Document const &node);
 
inline bool operator==(dom::Text const &a, dom::Text const &b) noexcept {
return a.text == b.text;
}
 
inline bool operator==(dom::Element const &a, dom::Element const &b) noexcept {
return a.name == b.name && a.attributes == b.attributes;
}
 
inline bool operator==(dom::Node const &a, dom::Node const &b) noexcept {
return a.children == b.children && a.data == b.data;
}
 
inline bool operator==(dom::Document const &a, dom::Document const &b) noexcept {
return a.doctype == b.doctype && a.html == b.html;
}
 
} // namespace dom
 
#endif
 
layout/layout.h added: 13, removed: 32, total 0
@@ -10,12 +10,9 @@ namespace layout {
 
struct Rect {
float x{}, y{}, width{}, height{};
bool operator==(Rect const &) const = default;
};
 
constexpr bool operator==(Rect const &a, Rect const &b) noexcept {
return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
}
 
enum class LayoutType {
Inline,
Block,
@@ -27,15 +24,9 @@ struct LayoutBox {
LayoutType type;
Rect dimensions;
std::vector<LayoutBox> children;
bool operator==(LayoutBox const &) const = default;
};
 
inline bool operator==(LayoutBox const &a, LayoutBox const &b) noexcept {
return a.node == b.node
&& a.type == b.type
&& a.dimensions == b.dimensions
&& a.children == b.children;
}
 
LayoutBox create_layout(style::StyledNode const &node, int width);
 
std::string to_string(LayoutBox const &box);
 
style/styled_node.h added: 13, removed: 32, total 0
@@ -18,7 +18,7 @@ struct StyledNode {
};
 
inline bool operator==(style::StyledNode const &a, style::StyledNode const &b) noexcept {
return a.node == b.node && a.properties == b.properties && a.children == b.children;
return a.node.get() == b.node.get() && a.properties == b.properties && a.children == b.children;
}
 
} // namespace style