1
2
3
4
5
6 #include <sngcpp/symbols/NamespaceSymbol.hpp>
7
8 namespace sngcpp { namespace symbols {
9
10 NamespaceSymbol::NamespaceSymbol(const Span& span_, const std::u32string& name_) : ContainerSymbol(span_, name_)
11 {
12 }
13
14 std::std::unique_ptr<sngxml::dom::Element>NamespaceSymbol::CreateElement()
15 {
16 std::unique_ptr<sngxml::dom::Element> namespaceElement(new sngxml::dom::Element(U"namespace"));
17 if (!projects.empty())
18 {
19 std::unique_ptr<sngxml::dom::Element> projectsElement(new sngxml::dom::Element(U"projects"));
20 for (const std::u32string& projectName : projects)
21 {
22 std::unique_ptr<sngxml::dom::Element> projectElement(new sngxml::dom::Element(U"project"));
23 projectElement->SetAttribute(U"name", projectName);
24 projectsElement->AppendChild(std::unique_ptr<sngxml::dom::Node>(projectElement.release()));
25 }
26 namespaceElement->AppendChild(std::unique_ptr<sngxml::dom::Node>(projectsElement.release()));
27 }
28 return namespaceElement;
29 }
30
31 void NamespaceSymbol::AddProject(const std::u32string& projectName)
32 {
33 projects.insert(projectName);
34 }
35
36 bool NamespaceSymbol::HasProject(const std::u32string& projectName) const
37 {
38 for (const auto& project : projects)
39 {
40 if (project == projectName) return true;
41 }
42 return false;
43 }
44
45 std::u32string NamespaceSymbol::FirstProject() const
46 {
47 if (projects.empty()) return std::u32string();
48 return *projects.begin();
49 }
50
51 } }