umya_spreadsheet/structs/
conditional_format_value_object.rs

1use super::ConditionalFormatValueObjectValues;
2use super::EnumValue;
3use super::StringValue;
4use crate::reader::driver::*;
5use crate::writer::driver::*;
6use quick_xml::events::{BytesStart, Event};
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::io::Cursor;
10
11#[derive(Clone, Default, Debug)]
12pub struct ConditionalFormatValueObject {
13    r#type: EnumValue<ConditionalFormatValueObjectValues>,
14    val: StringValue,
15}
16
17impl ConditionalFormatValueObject {
18    #[inline]
19    pub fn get_type(&self) -> &ConditionalFormatValueObjectValues {
20        self.r#type.get_value()
21    }
22
23    #[inline]
24    pub fn set_type(&mut self, value: ConditionalFormatValueObjectValues) -> &mut Self {
25        self.r#type.set_value(value);
26        self
27    }
28
29    #[inline]
30    pub fn get_val(&self) -> &str {
31        self.val.get_value_str()
32    }
33
34    #[inline]
35    pub fn set_val<S: Into<String>>(&mut self, value: S) -> &mut Self {
36        self.val.set_value(value.into());
37        self
38    }
39
40    pub(crate) fn set_attributes<R: std::io::BufRead>(
41        &mut self,
42        reader: &mut Reader<R>,
43        e: &BytesStart,
44        empty_flg: bool,
45    ) {
46        set_string_from_xml!(self, e, r#type, "type");
47        set_string_from_xml!(self, e, val, "val");
48
49        if empty_flg {
50            return;
51        }
52
53        xml_read_loop!(
54            reader,
55            Event::End(ref e) => {
56                if e.name().into_inner() == b"cfvo" {
57                    return
58                }
59            },
60            Event::Eof => panic!("Error: Could not find {} end element", "cfvo")
61        );
62    }
63
64    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
65        // cfvo
66        let mut attributes: Vec<(&str, &str)> = Vec::new();
67        let ctype = self.r#type.get_value_string();
68        if self.r#type.has_value() {
69            attributes.push(("type", ctype));
70        }
71        let val = self.val.get_value_str();
72        if self.val.has_value() {
73            attributes.push(("val", val));
74        }
75
76        write_start_tag(writer, "cfvo", attributes, true);
77    }
78}