fbx_dom/objects/
null_node.rs1use std::collections::HashMap;
4use std::convert::TryFrom;
5
6use crate::{OwnedObject, Property};
7
8use super::{FbxObjectTag, FbxTypeMismatch, fbx_object_tag};
9
10#[derive(Debug, PartialEq)]
12pub struct NullNode(pub OwnedObject);
13
14impl NullNode {
15 pub fn inner(&self) -> &OwnedObject {
16 &self.0
17 }
18
19 pub fn into_inner(self) -> OwnedObject {
20 self.0
21 }
22
23 pub fn properties(&self) -> &HashMap<String, Property> {
25 &self.0.properties
26 }
27
28 pub fn property(&self, name: &str) -> Option<&Property> {
29 self.0.properties.get(name)
30 }
31}
32
33impl TryFrom<OwnedObject> for NullNode {
34 type Error = FbxTypeMismatch;
35
36 fn try_from(o: OwnedObject) -> Result<Self, Self::Error> {
37 match fbx_object_tag(&o) {
38 FbxObjectTag::NullNode => Ok(NullNode(o)),
39 _ => Err(FbxTypeMismatch::wrong_object_kind(
40 o,
41 "NullNode".to_string(),
42 )),
43 }
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use std::collections::HashMap;
50 use std::convert::TryFrom;
51
52 use crate::objects::{NODE_ATTRIBUTE_NULL_CLASS_NAME, NODE_ATTRIBUTE_TYPE_NAME};
53 use crate::{OwnedObject, Property};
54
55 use super::NullNode;
56
57 #[test]
58 fn property_accessors_return_owned_object_properties() {
59 let mut properties = HashMap::new();
60 properties.insert("Size".to_string(), Property::Float(100.0));
61 let o = OwnedObject {
62 object_index: 99,
63 name: "Null".into(),
64 type_name: NODE_ATTRIBUTE_TYPE_NAME.into(),
65 class_name: NODE_ATTRIBUTE_NULL_CLASS_NAME.into(),
66 properties,
67 attributes: HashMap::new(),
68 connected_object_ids: vec![],
69 object_property_targets: vec![],
70 pp_property_targets: HashMap::new(),
71 };
72 let null_node = NullNode::try_from(o).unwrap();
73 assert_eq!(null_node.property("Size"), Some(&Property::Float(100.0)));
74 assert_eq!(null_node.properties().len(), 1);
75 }
76}