umya_spreadsheet/structs/drawing/charts/
string_reference.rs1use crate::xml_read_loop;
2
3use super::Formula;
5use super::StringCache;
6use crate::structs::Spreadsheet;
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 StringReference {
15 formula: Formula,
16 string_cache: StringCache,
17}
18
19impl StringReference {
20 pub fn get_formula(&self) -> &Formula {
21 &self.formula
22 }
23
24 pub fn get_formula_mut(&mut self) -> &mut Formula {
25 &mut self.formula
26 }
27
28 pub fn set_formula(&mut self, value: Formula) -> &mut StringReference {
29 self.formula = value;
30 self
31 }
32
33 pub fn get_string_cache(&self) -> &StringCache {
34 &self.string_cache
35 }
36
37 pub fn get_string_cache_mut(&mut self) -> &mut StringCache {
38 &mut self.string_cache
39 }
40
41 pub fn set_string_cache(&mut self, value: StringCache) -> &mut StringReference {
42 self.string_cache = value;
43 self
44 }
45
46 pub(crate) fn set_attributes<R: std::io::BufRead>(
47 &mut self,
48 reader: &mut Reader<R>,
49 _e: &BytesStart,
50 ) {
51 xml_read_loop!(
52 reader,
53 Event::Start(ref e) => match e.name().0 {
54 b"c:f" => {
55 self.formula.set_attributes(reader, e);
56 }
57 b"c:strCache" => {
58 self.string_cache.set_attributes(reader, e);
59 }
60 _ => (),
61 },
62 Event::End(ref e) => {
63 if e.name().0 == b"c:strRef" {
64 return;
65 }
66 },
67 Event::Eof => panic!("Error: Could not find {} end element", "c:strRef"),
68 );
69 }
70
71 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, spreadsheet: &Spreadsheet) {
72 write_start_tag(writer, "c:strRef", vec![], false);
74
75 self.formula.write_to(writer);
77
78 self.string_cache
80 .write_to(writer, self.get_formula(), spreadsheet);
81
82 write_end_tag(writer, "c:strRef");
83 }
84}