ply_rs/ply/property.rs
1
2/// Scalar type used to encode properties in the payload.
3///
4/// For the translation to rust types, see individual documentation.
5#[derive(Debug, PartialEq, Eq, Clone)]
6pub enum ScalarType {
7 /// Signed 8 bit integer, rust: `i8`.
8 Char,
9 /// Unsigned 8 bit integer, rust: `u8`.
10 UChar,
11 /// Signed 16 bit integer, rust: `i16`.
12 Short,
13 /// Unsigned 16 bit integer, rust: `u16`.
14 UShort,
15 /// Signed 32 bit integer, rust: `i32`.
16 Int,
17 /// Unsigned 32 bit integer, rust: `u32`.
18 UInt,
19 /// 32 bit floating point number, rust: `f32`.
20 Float,
21 /// 64 bit floating point number, rust: `f64`.
22 Double,
23}
24
25/// Data type used to encode properties in the payload.
26///
27/// There are two possible types: scalars and lists.
28/// Lists are a sequence of scalars with a leading integer value defining how many elements the list contains.
29#[derive(Debug, PartialEq, Eq, Clone)]
30pub enum PropertyType {
31 /// Simple, "one-number" type.
32 Scalar(ScalarType),
33 /// Defines a sequence of scalars with the same type.
34 ///
35 /// First value is the index type which should be an integer variant,
36 /// Encoded in ascii, you always get the same number in the file (for example `32` or `17`).
37 /// Hence, a good choice is mainly important for internal representation and binary encoding. T
38 /// he possible trade-off should be obvious:
39 /// List length/flexibility against storage size. Though this obviously depends on your specific use case.
40 ///
41 /// Second value is the type of the list elemetns.
42 List(ScalarType, ScalarType)
43}
44
45/// Wrapper used to implement a dynamic type system as required by the PLY file format.
46#[derive(Debug, PartialEq, Clone)]
47pub enum Property {
48 Char(i8),
49 UChar(u8),
50 Short(i16),
51 UShort(u16),
52 Int(i32),
53 UInt(u32),
54 Float(f32),
55 Double(f64),
56 ListChar(Vec<i8>),
57 ListUChar(Vec<u8>),
58 ListShort(Vec<i16>),
59 ListUShort(Vec<u16>),
60 ListInt(Vec<i32>),
61 ListUInt(Vec<u32>),
62 ListFloat(Vec<f32>),
63 ListDouble(Vec<f64>),
64}
65
66/// Provides setters and getters for the Parser and the Writer.
67///
68/// This trait allows you to create your own data structure for the case that the
69/// default HashMap isn't efficient enough for you.
70///
71/// All setters and getters have default implementations that do nothing or at most return `None`.
72///
73/// Feel free only to implement what your application actually uses:
74/// If you know, that you only expect unsigned shorts, don't bother about implementing signed shorts or floats, it won't be called.
75///
76/// The getters are named in congruence with `PropertyType` and `ScalarType`.
77pub trait PropertyAccess {
78 fn new() -> Self;
79 fn set_property(&mut self, _property_name: String, _property: Property) {
80 // By default, do nothing
81 // Sombody might only want to write, no point in bothering him/her with setter implementations.
82 }
83 fn get_char(&self, _property_name: &String) -> Option<i8> {
84 None
85 }
86 fn get_uchar(&self, _property_name: &String) -> Option<u8> {
87 None
88 }
89 fn get_short(&self, _property_name: &String) -> Option<i16> {
90 None
91 }
92 fn get_ushort(&self, _property_name: &String) -> Option<u16> {
93 None
94 }
95 fn get_int(&self, _property_name: &String) -> Option<i32> {
96 None
97 }
98 fn get_uint(&self, _property_name: &String) -> Option<u32> {
99 None
100 }
101 fn get_float(&self, _property_name: &String) -> Option<f32> {
102 None
103 }
104 fn get_double(&self, _property_name: &String) -> Option<f64> {
105 None
106 }
107 fn get_list_char(&self, _property_name: &String) -> Option<&[i8]> {
108 None
109 }
110 fn get_list_uchar(&self, _property_name: &String) -> Option<&[u8]> {
111 None
112 }
113 fn get_list_short(&self, _property_name: &String) -> Option<&[i16]> {
114 None
115 }
116 fn get_list_ushort(&self, _property_name: &String) -> Option<&[u16]> {
117 None
118 }
119 fn get_list_int(&self, _property_name: &String) -> Option<&[i32]> {
120 None
121 }
122 fn get_list_uint(&self, _property_name: &String) -> Option<&[u32]> {
123 None
124 }
125 fn get_list_float(&self, _property_name: &String) -> Option<&[f32]> {
126 None
127 }
128 fn get_list_double(&self, _property_name: &String) -> Option<&[f64]> {
129 None
130 }
131}