ply_rs/ply/
default_element.rs

1use super::KeyMap;
2use super::Property;
3use super::PropertyAccess;
4
5/// Ready to use data-structure for all kind of element definitions.
6///
7/// PLY files carry the payload format in their head section.
8/// Hence, they can contain all kind of elements, or formulated differently,
9/// they define types very dinamically.
10/// To achieve this flexibility in rust, this alias to a HashMap is provided.
11///
12/// If you need a more compact representation or faster access,
13/// you might want to define your own structures and implement the `PropertyAccess` trait.
14pub type DefaultElement = KeyMap<Property>;
15macro_rules! get(
16    ($e:expr) => (match $e {None => return None, Some(x) => x})
17);
18impl PropertyAccess for DefaultElement {
19    fn new() -> Self {
20        DefaultElement::new()
21    }
22    fn set_property(&mut self, key: String, property: Property) {
23        self.insert(key, property);
24    }
25    fn get_char(&self, key: &String) -> Option<i8> {
26        match *get!(self.get(key)) {
27            Property::Char(x) => Some(x),
28            _ => None,
29        }
30    }
31    fn get_uchar(&self, key: &String) -> Option<u8> {
32        match *get!(self.get(key)) {
33            Property::UChar(x) => Some(x),
34            _ => None,
35        }
36    }
37    fn get_short(&self, key: &String) -> Option<i16> {
38        match *get!(self.get(key)) {
39            Property::Short(x) => Some(x),
40            _ => None,
41        }
42    }
43    fn get_ushort(&self, key: &String) -> Option<u16> {
44        match *get!(self.get(key)) {
45            Property::UShort(x) => Some(x),
46            _ => None,
47        }
48    }
49    fn get_int(&self, key: &String) -> Option<i32> {
50        match *get!(self.get(key)) {
51            Property::Int(x) => Some(x),
52            _ => None,
53        }
54    }
55    fn get_uint(&self, key: &String) -> Option<u32> {
56        match *get!(self.get(key)) {
57            Property::UInt(x) => Some(x),
58            _ => None,
59        }
60    }
61    fn get_float(&self, key: &String) -> Option<f32> {
62        match *get!(self.get(key)) {
63            Property::Float(x) => Some(x),
64            _ => None,
65        }
66    }
67    fn get_double(&self, key: &String) -> Option<f64> {
68        match *get!(self.get(key)) {
69            Property::Double(x) => Some(x),
70            _ => None,
71        }
72    }
73    fn get_list_char(&self, key: &String) -> Option<&[i8]> {
74        match *get!(self.get(key)) {
75            Property::ListChar(ref x) => Some(x),
76            _ => None,
77        }
78    }
79    fn get_list_uchar(&self, key: &String) -> Option<&[u8]> {
80        match *get!(self.get(key)) {
81            Property::ListUChar(ref x) => Some(x),
82            _ => None,
83        }
84    }
85    fn get_list_short(&self, key: &String) -> Option<&[i16]> {
86        match *get!(self.get(key)) {
87            Property::ListShort(ref x) => Some(x),
88            _ => None,
89        }
90    }
91    fn get_list_ushort(&self, key: &String) -> Option<&[u16]> {
92        match *get!(self.get(key)) {
93            Property::ListUShort(ref x) => Some(x),
94            _ => None,
95        }
96    }
97    fn get_list_int(&self, key: &String) -> Option<&[i32]> {
98        match *get!(self.get(key)) {
99            Property::ListInt(ref x) => Some(x),
100            _ => None,
101        }
102    }
103    fn get_list_uint(&self, key: &String) -> Option<&[u32]> {
104        match *get!(self.get(key)) {
105            Property::ListUInt(ref x) => Some(x),
106            _ => None,
107        }
108    }
109    fn get_list_float(&self, key: &String) -> Option<&[f32]> {
110        match *get!(self.get(key)) {
111            Property::ListFloat(ref x) => Some(x),
112            _ => None,
113        }
114    }
115    fn get_list_double(&self, key: &String) -> Option<&[f64]> {
116        match *get!(self.get(key)) {
117            Property::ListDouble(ref x) => Some(x),
118            _ => None,
119        }
120    }
121}