1use crate::{ffi,Array,NodeType,Object};
7use glib::{translate::*};
8
9glib::wrapper! {
10 #[derive(Debug, PartialOrd, Ord)]
11 pub struct Node(Shared<ffi::JsonNode>);
12
13 match fn {
14 ref => |ptr| ffi::json_node_ref(ptr),
15 unref => |ptr| ffi::json_node_unref(ptr),
16 type_ => || ffi::json_node_get_type(),
17 }
18}
19
20impl Node {
21 #[doc(alias = "json_node_alloc")]
22 pub fn alloc() -> Node {
23 assert_initialized_main_thread!();
24 unsafe {
25 from_glib_full(ffi::json_node_alloc())
26 }
27 }
28
29 #[doc(alias = "json_node_new")]
30 pub fn new(type_: NodeType) -> Node {
31 assert_initialized_main_thread!();
32 unsafe {
33 from_glib_full(ffi::json_node_new(type_.into_glib()))
34 }
35 }
36
37 #[doc(alias = "json_node_copy")]
38#[must_use]
39 pub fn copy(&self) -> Node {
40 unsafe {
41 from_glib_full(ffi::json_node_copy(self.to_glib_none().0))
42 }
43 }
44
45 #[doc(alias = "json_node_dup_array")]
46 pub fn dup_array(&self) -> Option<Array> {
47 unsafe {
48 from_glib_full(ffi::json_node_dup_array(self.to_glib_none().0))
49 }
50 }
51
52 #[doc(alias = "json_node_dup_object")]
53 pub fn dup_object(&self) -> Option<Object> {
54 unsafe {
55 from_glib_full(ffi::json_node_dup_object(self.to_glib_none().0))
56 }
57 }
58
59 #[doc(alias = "json_node_dup_string")]
60 pub fn dup_string(&self) -> Option<glib::GString> {
61 unsafe {
62 from_glib_full(ffi::json_node_dup_string(self.to_glib_none().0))
63 }
64 }
65
66 #[cfg(feature = "v1_2")]
67 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
68 #[doc(alias = "json_node_equal")]
69 fn equal(&self, b: &Node) -> bool {
70 unsafe {
71 from_glib(ffi::json_node_equal(ToGlibPtr::<*mut ffi::JsonNode>::to_glib_none(self).0 as glib::ffi::gconstpointer, ToGlibPtr::<*mut ffi::JsonNode>::to_glib_none(b).0 as glib::ffi::gconstpointer))
72 }
73 }
74
75 #[doc(alias = "json_node_get_array")]
76 #[doc(alias = "get_array")]
77 pub fn array(&self) -> Option<Array> {
78 unsafe {
79 from_glib_none(ffi::json_node_get_array(self.to_glib_none().0))
80 }
81 }
82
83 #[doc(alias = "json_node_get_boolean")]
84 #[doc(alias = "get_boolean")]
85 pub fn is_boolean(&self) -> bool {
86 unsafe {
87 from_glib(ffi::json_node_get_boolean(self.to_glib_none().0))
88 }
89 }
90
91 #[doc(alias = "json_node_get_double")]
92 #[doc(alias = "get_double")]
93 pub fn double(&self) -> f64 {
94 unsafe {
95 ffi::json_node_get_double(self.to_glib_none().0)
96 }
97 }
98
99 #[doc(alias = "json_node_get_int")]
100 #[doc(alias = "get_int")]
101 pub fn int(&self) -> i64 {
102 unsafe {
103 ffi::json_node_get_int(self.to_glib_none().0)
104 }
105 }
106
107 #[doc(alias = "json_node_get_node_type")]
108 #[doc(alias = "get_node_type")]
109 pub fn node_type(&self) -> NodeType {
110 unsafe {
111 from_glib(ffi::json_node_get_node_type(self.to_glib_none().0))
112 }
113 }
114
115 #[doc(alias = "json_node_get_object")]
116 #[doc(alias = "get_object")]
117 pub fn object(&self) -> Option<Object> {
118 unsafe {
119 from_glib_none(ffi::json_node_get_object(self.to_glib_none().0))
120 }
121 }
122
123 #[doc(alias = "json_node_get_parent")]
124 #[doc(alias = "get_parent")]
125#[must_use]
126 pub fn parent(&self) -> Option<Node> {
127 unsafe {
128 from_glib_none(ffi::json_node_get_parent(self.to_glib_none().0))
129 }
130 }
131
132 #[doc(alias = "json_node_get_string")]
133 #[doc(alias = "get_string")]
134 pub fn string(&self) -> Option<glib::GString> {
135 unsafe {
136 from_glib_none(ffi::json_node_get_string(self.to_glib_none().0))
137 }
138 }
139
140 #[doc(alias = "json_node_get_value")]
141 #[doc(alias = "get_value")]
142 pub fn value(&self) -> glib::Value {
143 unsafe {
144 let mut value = glib::Value::uninitialized();
145 ffi::json_node_get_value(self.to_glib_none().0, value.to_glib_none_mut().0);
146 value
147 }
148 }
149
150 #[doc(alias = "json_node_get_value_type")]
151 #[doc(alias = "get_value_type")]
152 pub fn value_type(&self) -> glib::types::Type {
153 unsafe {
154 from_glib(ffi::json_node_get_value_type(self.to_glib_none().0))
155 }
156 }
157
158 #[cfg(feature = "v1_2")]
159 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
160 #[doc(alias = "json_node_hash")]
161 fn hash(&self) -> u32 {
162 unsafe {
163 ffi::json_node_hash(ToGlibPtr::<*mut ffi::JsonNode>::to_glib_none(self).0 as glib::ffi::gconstpointer)
164 }
165 }
166
167 #[doc(alias = "json_node_init")]
168#[must_use]
169 pub fn init(&self, type_: NodeType) -> Node {
170 unsafe {
171 from_glib_none(ffi::json_node_init(self.to_glib_none().0, type_.into_glib()))
172 }
173 }
174
175 #[doc(alias = "json_node_init_array")]
176#[must_use]
177 pub fn init_array(&self, array: Option<&Array>) -> Node {
178 unsafe {
179 from_glib_none(ffi::json_node_init_array(self.to_glib_none().0, array.to_glib_none().0))
180 }
181 }
182
183 #[doc(alias = "json_node_init_boolean")]
184#[must_use]
185 pub fn init_boolean(&self, value: bool) -> Node {
186 unsafe {
187 from_glib_none(ffi::json_node_init_boolean(self.to_glib_none().0, value.into_glib()))
188 }
189 }
190
191 #[doc(alias = "json_node_init_double")]
192#[must_use]
193 pub fn init_double(&self, value: f64) -> Node {
194 unsafe {
195 from_glib_none(ffi::json_node_init_double(self.to_glib_none().0, value))
196 }
197 }
198
199 #[doc(alias = "json_node_init_int")]
200#[must_use]
201 pub fn init_int(&self, value: i64) -> Node {
202 unsafe {
203 from_glib_none(ffi::json_node_init_int(self.to_glib_none().0, value))
204 }
205 }
206
207 #[doc(alias = "json_node_init_null")]
208#[must_use]
209 pub fn init_null(&self) -> Node {
210 unsafe {
211 from_glib_none(ffi::json_node_init_null(self.to_glib_none().0))
212 }
213 }
214
215 #[doc(alias = "json_node_init_object")]
216#[must_use]
217 pub fn init_object(&self, object: Option<&Object>) -> Node {
218 unsafe {
219 from_glib_none(ffi::json_node_init_object(self.to_glib_none().0, object.to_glib_none().0))
220 }
221 }
222
223 #[doc(alias = "json_node_init_string")]
224#[must_use]
225 pub fn init_string(&self, value: Option<&str>) -> Node {
226 unsafe {
227 from_glib_none(ffi::json_node_init_string(self.to_glib_none().0, value.to_glib_none().0))
228 }
229 }
230
231 #[cfg(feature = "v1_2")]
232 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
233 #[doc(alias = "json_node_is_immutable")]
234 pub fn is_immutable(&self) -> bool {
235 unsafe {
236 from_glib(ffi::json_node_is_immutable(self.to_glib_none().0))
237 }
238 }
239
240 #[doc(alias = "json_node_is_null")]
241 pub fn is_null(&self) -> bool {
242 unsafe {
243 from_glib(ffi::json_node_is_null(self.to_glib_none().0))
244 }
245 }
246
247 #[cfg(feature = "v1_2")]
248 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
249 #[doc(alias = "json_node_seal")]
250 pub fn seal(&self) {
251 unsafe {
252 ffi::json_node_seal(self.to_glib_none().0);
253 }
254 }
255
256 #[doc(alias = "json_node_set_array")]
257 pub fn set_array(&self, array: &Array) {
258 unsafe {
259 ffi::json_node_set_array(self.to_glib_none().0, array.to_glib_none().0);
260 }
261 }
262
263 #[doc(alias = "json_node_set_boolean")]
264 pub fn set_boolean(&self, value: bool) {
265 unsafe {
266 ffi::json_node_set_boolean(self.to_glib_none().0, value.into_glib());
267 }
268 }
269
270 #[doc(alias = "json_node_set_double")]
271 pub fn set_double(&self, value: f64) {
272 unsafe {
273 ffi::json_node_set_double(self.to_glib_none().0, value);
274 }
275 }
276
277 #[doc(alias = "json_node_set_int")]
278 pub fn set_int(&self, value: i64) {
279 unsafe {
280 ffi::json_node_set_int(self.to_glib_none().0, value);
281 }
282 }
283
284 #[doc(alias = "json_node_set_object")]
285 pub fn set_object(&self, object: Option<&Object>) {
286 unsafe {
287 ffi::json_node_set_object(self.to_glib_none().0, object.to_glib_none().0);
288 }
289 }
290
291 #[doc(alias = "json_node_set_parent")]
292 pub fn set_parent(&self, parent: Option<&Node>) {
293 unsafe {
294 ffi::json_node_set_parent(self.to_glib_none().0, parent.to_glib_none().0);
295 }
296 }
297
298 #[doc(alias = "json_node_set_string")]
299 pub fn set_string(&self, value: &str) {
300 unsafe {
301 ffi::json_node_set_string(self.to_glib_none().0, value.to_glib_none().0);
302 }
303 }
304
305 #[doc(alias = "json_node_set_value")]
306 pub fn set_value(&self, value: &glib::Value) {
307 unsafe {
308 ffi::json_node_set_value(self.to_glib_none().0, value.to_glib_none().0);
309 }
310 }
311
312 #[doc(alias = "json_node_take_array")]
313 pub fn take_array(&self, array: Array) {
314 unsafe {
315 ffi::json_node_take_array(self.to_glib_none().0, array.into_glib_ptr());
316 }
317 }
318
319 #[doc(alias = "json_node_take_object")]
320 pub fn take_object(&self, object: Object) {
321 unsafe {
322 ffi::json_node_take_object(self.to_glib_none().0, object.into_glib_ptr());
323 }
324 }
325
326 #[doc(alias = "json_node_type_name")]
327 pub fn type_name(&self) -> glib::GString {
328 unsafe {
329 from_glib_none(ffi::json_node_type_name(self.to_glib_none().0))
330 }
331 }
332}
333
334#[cfg(feature = "v1_2")]
335#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
336impl PartialEq for Node {
337 #[inline]
338 fn eq(&self, other: &Self) -> bool {
339 self.equal(other)
340 }
341}
342#[cfg(feature = "v1_2")]
343#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
344
345impl Eq for Node {}
346
347#[cfg(feature = "v1_2")]
348#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
349impl std::hash::Hash for Node {
350 #[inline]
351 fn hash<H>(&self, state: &mut H) where H: std::hash::Hasher {
352 std::hash::Hash::hash(&self.hash(), state)
353 }
354}