dora_ssr/dora/
dictionary.rs

1/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
9extern "C" {
10	fn dictionary_type() -> i32;
11	fn dictionary_get_count(slf: i64) -> i32;
12	fn dictionary_get_keys(slf: i64) -> i64;
13	fn dictionary_clear(slf: i64);
14	fn dictionary_new() -> i64;
15}
16use crate::dora::IObject;
17/// A struct for storing pairs of string keys and various values.
18pub struct Dictionary { raw: i64 }
19crate::dora_object!(Dictionary);
20impl Dictionary {
21	pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
22		(unsafe { dictionary_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
23			match raw {
24				0 => None,
25				_ => Some(Box::new(Dictionary { raw: raw }))
26			}
27		})
28	}
29	/// Gets the number of items in the dictionary.
30	pub fn get_count(&self) -> i32 {
31		return unsafe { dictionary_get_count(self.raw()) };
32	}
33	/// Gets the keys of the items in the dictionary.
34	pub fn get_keys(&self) -> Vec<String> {
35		return unsafe { crate::dora::Vector::to_str(dictionary_get_keys(self.raw())) };
36	}
37	/// Removes all the items from the dictionary.
38	pub fn clear(&mut self) {
39		unsafe { dictionary_clear(self.raw()); }
40	}
41	/// Creates instance of the "Dictionary".
42	pub fn new() -> Dictionary {
43		unsafe { return Dictionary { raw: dictionary_new() }; }
44	}
45}