Nui
Loading...
Searching...
No Matches
basic_element.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <algorithm>
6#include <cctype>
7#include <memory>
8#include <string>
9#include <optional>
10
11namespace Nui::Dom
12{
13 class BasicElement : public std::enable_shared_from_this<BasicElement>
14 {
15 public:
17 : element_{std::move(val)}
18 {}
19 virtual ~BasicElement() = default;
20 BasicElement(BasicElement const&) = default;
21 BasicElement(BasicElement&&) noexcept = default;
22 BasicElement& operator=(BasicElement const&) = default;
23 BasicElement& operator=(BasicElement&&) noexcept = default;
24
25 Nui::val const& val() const
26 {
27 return element_;
28 }
30 {
31 return element_;
32 }
33 // NOLINTNEXTLINE(hicpp-explicit-conversions)
34 operator Nui::val const&() const
35 {
36 return element_;
37 }
38 // NOLINTNEXTLINE(hicpp-explicit-conversions)
39 operator Nui::val&()
40 {
41 return element_;
42 }
43 // NOLINTNEXTLINE(hicpp-explicit-conversions)
44 operator Nui::val&&() &&
45 {
46 return std::move(element_);
47 }
48
49 template <class Derived>
50 std::shared_ptr<Derived> shared_from_base()
51 {
52 return std::static_pointer_cast<Derived>(shared_from_this());
53 }
54 template <class Derived>
55 std::weak_ptr<Derived> weak_from_base()
56 {
57 return std::weak_ptr<Derived>(shared_from_base<Derived>());
58 }
59 std::string tagName() const
60 {
61 auto tag = element_["tagName"].as<std::string>();
62 std::transform(tag.begin(), tag.end(), tag.begin(), [](unsigned char c) {
63 return std::tolower(c);
64 });
65 return tag;
66 }
67 std::optional<std::string> namespaceUri() const
68 {
69 if (!element_.isUndefined() && element_.hasOwnProperty("namespaceURI"))
70 return element_["namespaceURI"].as<std::string>();
71 return std::nullopt;
72 }
73
74 protected:
75 explicit BasicElement()
76 : element_{Nui::val::undefined()}
77 {}
78
80 };
81}
Definition basic_element.hpp:14
Nui::val & val()
Definition basic_element.hpp:29
BasicElement(BasicElement &&) noexcept=default
BasicElement()
Definition basic_element.hpp:75
BasicElement(BasicElement const &)=default
virtual ~BasicElement()=default
Nui::val element_
Definition basic_element.hpp:79
std::string tagName() const
Definition basic_element.hpp:59
std::shared_ptr< Derived > shared_from_base()
Definition basic_element.hpp:50
std::weak_ptr< Derived > weak_from_base()
Definition basic_element.hpp:55
BasicElement(Nui::val val)
Definition basic_element.hpp:16
std::optional< std::string > namespaceUri() const
Definition basic_element.hpp:67
Definition basic_element.hpp:12
Definition file_dialog.hpp:6
emscripten::val val
Definition val.hpp:5