ply_rs/ply/
default_element.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use super::KeyMap;
use super::Property;
use super::PropertyAccess;

/// Ready to use data-structure for all kind of element definitions.
///
/// PLY files carry the payload format in their head section.
/// Hence, they can contain all kind of elements, or formulated differently,
/// they define types very dinamically.
/// To achieve this flexibility in rust, this alias to a HashMap is provided.
///
/// If you need a more compact representation or faster access,
/// you might want to define your own structures and implement the `PropertyAccess` trait.
pub type DefaultElement = KeyMap<Property>;
macro_rules! get(
    ($e:expr) => (match $e {None => return None, Some(x) => x})
);
impl PropertyAccess for DefaultElement {
    fn new() -> Self {
        DefaultElement::new()
    }
    fn set_property(&mut self, key: String, property: Property) {
        self.insert(key, property);
    }
    fn get_char(&self, key: &String) -> Option<i8> {
        match *get!(self.get(key)) {
            Property::Char(x) => Some(x),
            _ => None,
        }
    }
    fn get_uchar(&self, key: &String) -> Option<u8> {
        match *get!(self.get(key)) {
            Property::UChar(x) => Some(x),
            _ => None,
        }
    }
    fn get_short(&self, key: &String) -> Option<i16> {
        match *get!(self.get(key)) {
            Property::Short(x) => Some(x),
            _ => None,
        }
    }
    fn get_ushort(&self, key: &String) -> Option<u16> {
        match *get!(self.get(key)) {
            Property::UShort(x) => Some(x),
            _ => None,
        }
    }
    fn get_int(&self, key: &String) -> Option<i32> {
        match *get!(self.get(key)) {
            Property::Int(x) => Some(x),
            _ => None,
        }
    }
    fn get_uint(&self, key: &String) -> Option<u32> {
        match *get!(self.get(key)) {
            Property::UInt(x) => Some(x),
            _ => None,
        }
    }
    fn get_float(&self, key: &String) -> Option<f32> {
        match *get!(self.get(key)) {
            Property::Float(x) => Some(x),
            _ => None,
        }
    }
    fn get_double(&self, key: &String) -> Option<f64> {
        match *get!(self.get(key)) {
            Property::Double(x) => Some(x),
            _ => None,
        }
    }
    fn get_list_char(&self, key: &String) -> Option<&[i8]> {
        match *get!(self.get(key)) {
            Property::ListChar(ref x) => Some(x),
            _ => None,
        }
    }
    fn get_list_uchar(&self, key: &String) -> Option<&[u8]> {
        match *get!(self.get(key)) {
            Property::ListUChar(ref x) => Some(x),
            _ => None,
        }
    }
    fn get_list_short(&self, key: &String) -> Option<&[i16]> {
        match *get!(self.get(key)) {
            Property::ListShort(ref x) => Some(x),
            _ => None,
        }
    }
    fn get_list_ushort(&self, key: &String) -> Option<&[u16]> {
        match *get!(self.get(key)) {
            Property::ListUShort(ref x) => Some(x),
            _ => None,
        }
    }
    fn get_list_int(&self, key: &String) -> Option<&[i32]> {
        match *get!(self.get(key)) {
            Property::ListInt(ref x) => Some(x),
            _ => None,
        }
    }
    fn get_list_uint(&self, key: &String) -> Option<&[u32]> {
        match *get!(self.get(key)) {
            Property::ListUInt(ref x) => Some(x),
            _ => None,
        }
    }
    fn get_list_float(&self, key: &String) -> Option<&[f32]> {
        match *get!(self.get(key)) {
            Property::ListFloat(ref x) => Some(x),
            _ => None,
        }
    }
    fn get_list_double(&self, key: &String) -> Option<&[f64]> {
        match *get!(self.get(key)) {
            Property::ListDouble(ref x) => Some(x),
            _ => None,
        }
    }
}