1
2
3
4
5
6 #ifndef SNGXML_DOM_ELEMENT_INCLUDED
7 #define SNGXML_DOM_ELEMENT_INCLUDED
8 #include <sngxml/dom/Node.hpp>
9 #include <map>
10
11 namespace sngxml { namespace dom {
12
13 class Attr : public Node
14 {
15 public:
16 Attr();
17 Attr(const std::u32string& name_, const std::u32string& value_);
18 Attr(const Attr&) = delete;
19 Attr& operator=(const Attr&) = delete;
20 Attr(Attr&&) = delete;
21 Attr& operator=(Attr&&) = delete;
22 std::unique_ptr<Node> CloneNode(bool deep) override;
23 void Write(CodeFormatter& formatter) override;
24 const std::u32string& Value() const { return value; }
25 std::u32string& Value() { return value; }
26 private:
27 std::u32string value;
28 };
29
30 class Element : public ParentNode
31 {
32 public:
33 Element(const std::u32string& name_);
34 Element(const std::u32string& name_, std::std::map<std::u32string, std::std::unique_ptr<Attr>>&&attributeMap_);
35 Element(const Element&) = delete;
36 Element& operator=(const Element&) = delete;
37 Element(Element&&) = delete;
38 Element& operator=(Element&&) = delete;
39 std::unique_ptr<Node> CloneNode(bool deep) override;
40 const std::u32string& TagName() const { return Name(); }
41 bool HasAttributes() const override;
42 void Write(CodeFormatter& formatter) override;
43 std::u32string GetAttribute(const std::u32string& attrName) const;
44 void AddAttribute(std::std::unique_ptr<Attr>&&attr);
45 void SetAttribute(const std::u32string& attrName, const std::u32string& attrValue);
46 void RemoveAttribute(const std::u32string& attrName);
47 void WalkAttribute(NodeOp& nodeOp) override;
48 NodeList GetElementsByTagName(const std::u32string& tagName);
49 void Accept(Visitor& visitor) override;
50 private:
51 std::map<std::u32string, std::std::unique_ptr<Attr>>attributeMap;
52 void WriteAttributes(CodeFormatter& formatter);
53 bool HasMultilineContent();
54 };
55
56 } }
57
58 #endif // SNGXML_DOM_ELEMENT_INCLUDED