umya_spreadsheet/structs/
row_item.rs

1// i
2use crate::reader::driver::*;
3use crate::structs::EnumValue;
4use crate::structs::ItemValues;
5use crate::structs::MemberPropertyIndex;
6use crate::structs::UInt32Value;
7use crate::writer::driver::*;
8use quick_xml::events::{BytesStart, Event};
9use quick_xml::Reader;
10use quick_xml::Writer;
11use std::io::Cursor;
12
13#[derive(Clone, Default, Debug)]
14pub struct RowItem {
15    index: UInt32Value,
16    item_type: EnumValue<ItemValues>,
17    repeated_item_count: UInt32Value,
18    member_property_index: Option<MemberPropertyIndex>,
19}
20impl RowItem {
21    #[inline]
22    pub fn get_index(&self) -> &u32 {
23        self.index.get_value()
24    }
25
26    #[inline]
27    pub fn set_index(&mut self, value: u32) -> &mut Self {
28        self.index.set_value(value);
29        self
30    }
31
32    #[inline]
33    pub fn get_item_type(&self) -> &ItemValues {
34        self.item_type.get_value()
35    }
36
37    #[inline]
38    pub fn set_item_type(&mut self, value: ItemValues) -> &mut Self {
39        self.item_type.set_value(value);
40        self
41    }
42
43    #[inline]
44    pub fn get_repeated_item_count(&self) -> &u32 {
45        self.repeated_item_count.get_value()
46    }
47
48    #[inline]
49    pub fn set_repeated_item_count(&mut self, value: u32) -> &mut Self {
50        self.repeated_item_count.set_value(value);
51        self
52    }
53
54    #[inline]
55    pub fn get_member_property_index(&self) -> Option<&MemberPropertyIndex> {
56        self.member_property_index.as_ref()
57    }
58
59    #[inline]
60    pub fn get_member_property_index_mut(&mut self) -> Option<&mut MemberPropertyIndex> {
61        self.member_property_index.as_mut()
62    }
63
64    #[inline]
65    pub fn set_member_property_index_color(&mut self, value: MemberPropertyIndex) -> &mut Self {
66        self.member_property_index = Some(value);
67        self
68    }
69
70    #[inline]
71    pub(crate) fn set_attributes<R: std::io::BufRead>(
72        &mut self,
73        reader: &mut Reader<R>,
74        e: &BytesStart,
75        empty_flg: bool,
76    ) {
77        set_string_from_xml!(self, e, index, "i");
78        set_string_from_xml!(self, e, item_type, "t");
79        set_string_from_xml!(self, e, repeated_item_count, "r");
80
81        if empty_flg {
82            return;
83        }
84
85        xml_read_loop!(
86            reader,
87            Event::Empty(ref e) => {
88                if e.name().into_inner() == b"x" {
89                    let mut obj = MemberPropertyIndex::default();
90                    obj.set_attributes(reader, e);
91                    self.set_member_property_index_color(obj);
92                }
93            },
94            Event::End(ref e) => {
95                if e.name().into_inner() == b"i" {
96                    return
97                }
98            },
99            Event::Eof => panic!("Error: Could not find {} end element", "i")
100        );
101    }
102
103    #[inline]
104    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
105        let empty_flg = self.member_property_index.is_some();
106        // i
107        let mut attributes: Vec<(&str, &str)> = Vec::new();
108        let index_str = self.index.get_value_string();
109        if self.index.has_value() {
110            attributes.push(("i", &index_str));
111        }
112        if self.item_type.has_value() {
113            attributes.push(("t", self.item_type.get_value_string()));
114        }
115        let repeated_item_count_str = self.repeated_item_count.get_value_string();
116        if self.repeated_item_count.has_value() {
117            attributes.push(("r", &repeated_item_count_str));
118        }
119        write_start_tag(writer, "i", attributes, empty_flg);
120        if empty_flg == false {
121            if let Some(v) = &self.member_property_index {
122                v.write_to(writer);
123            }
124            write_end_tag(writer, "i");
125        }
126    }
127}