1use super::memory;
2use super::element::Content;
3use super::attribute::Attribute;
4
5#[derive(Copy, Clone, Debug)]
6pub struct ElementPtr {
7 pub ptr: usize
8}
9
10pub const NULL: usize = 0x1_000_000;
11
12impl ElementPtr {
13
14 pub fn null() -> Self {
15 Self::new(NULL)
16 }
17
18 #[inline]
19 pub fn new(ptr: usize) -> Self {
20 ElementPtr { ptr }
21 }
22
23 #[inline]
24 pub fn to_string(&self) -> String {
25 memory::get(self.ptr).to_string()
26 }
27
28 #[inline]
29 pub fn get_inner_string(&self) -> String {
30 memory::get(self.ptr).get_inner_string()
31 }
32
33 #[inline]
34 pub fn add_element_ptr(&self, element_ptr: ElementPtr) {
35 memory::get_mut(self.ptr).add_element_ptr(element_ptr);
36 }
37
38 #[inline]
39 pub fn get_contents(&self) -> &Vec<Content> {
40 memory::get(self.ptr).get_contents()
41 }
42
43 #[inline]
44 pub fn get_contents_mut(&self) -> &mut Vec<Content> {
45 memory::get_mut(self.ptr).get_contents_mut()
46 }
47
48 #[inline]
49 pub fn add_contents(&self, contents: Vec<Content>) {
50 memory::get_mut(self.ptr).add_contents(contents);
51 }
52
53 #[inline]
54 pub fn get_attribute(&self, attribute: String) -> Option<String> {
55 memory::get_mut(self.ptr).get_attribute(attribute)
56 }
57
58 #[inline]
59 pub fn get_attributes(&self) -> &Vec<Attribute> {
60 &memory::get(self.ptr).attributes
61 }
62
63 #[inline]
64 pub fn get_tag_name(&self) -> String {
65 memory::get(self.ptr).tag_name.clone()
66 }
67
68 #[inline]
69 pub fn set_attribute(&self, attribute: String, value: String) {
70 memory::get_mut(self.ptr).set_attribute(attribute, value);
71 }
72
73 #[inline]
74 pub fn get_parent(&self) -> Option<ElementPtr> {
75 memory::get(self.ptr).get_parent()
76 }
77
78 #[inline]
79 pub fn delete_child_element(&self, child: ElementPtr) {
80 memory::get_mut(self.ptr).delete_child_element(child);
81 }
82
83 #[inline]
84 pub fn get_children(&self) -> Vec<ElementPtr> {
85 memory::get(self.ptr).get_children()
86 }
87
88 #[inline]
89 pub fn get_siblings(&self) -> Vec<ElementPtr> {
90 memory::get(self.ptr).get_siblings()
91 }
92
93 #[inline]
94 pub fn set_parent(&self, parent: ElementPtr) {
95 memory::get_mut(self.ptr).set_parent(parent);
96 }
97
98 #[inline]
99 pub fn set_parent_recursive(&self) {
100 memory::get_mut(self.ptr).set_parent_recursive();
101 }
102
103 #[inline]
104 pub fn has_unique_attributes(&self) -> bool {
105 memory::get(self.ptr).has_unique_attributes()
106 }
107
108}
109
110impl PartialEq for ElementPtr {
111 fn eq(&self, other: &ElementPtr) -> bool {
112 self.ptr != super::pointer::NULL
113 && self.ptr == other.ptr
114 }
115}