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