Orcus
shared_strings.hpp
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
7
8#ifndef INCLUDED_ORCUS_SPREADSHEET_SHARED_STRINGS_HPP
9#define INCLUDED_ORCUS_SPREADSHEET_SHARED_STRINGS_HPP
10
11#include "orcus/spreadsheet/import_interface.hpp"
12#include "orcus/spreadsheet/styles.hpp"
13#include "orcus/pstring.hpp"
14#include "orcus/env.hpp"
15
16#include <cstdlib>
17#include <vector>
18#include <unordered_map>
19
20namespace ixion { class model_context; }
21
22namespace orcus {
23
24class string_pool;
25
26namespace spreadsheet {
27
28class styles;
29
30struct ORCUS_SPM_DLLPUBLIC format_run
31{
32 size_t pos;
33 size_t size;
34 pstring font;
35 double font_size;
36 color_t color;
37 bool bold:1;
38 bool italic:1;
39
40 format_run();
41
42 void reset();
43 bool formatted() const;
44};
45
46typedef std::vector<format_run> format_runs_t;
47
51class ORCUS_SPM_DLLPUBLIC import_shared_strings : public iface::import_shared_strings
52{
53 typedef std::unordered_map<pstring, size_t, pstring::hash> str_index_map_type;
54
55 import_shared_strings() = delete;
57 import_shared_strings& operator=(const import_shared_strings&) = delete;
58
59public:
60
61 // format runs for all shared strings, mapped by string IDs.
62 typedef std::unordered_map<size_t, format_runs_t*> format_runs_map_type;
63
64 import_shared_strings(orcus::string_pool& sp, ixion::model_context& cxt, styles& styles);
65 virtual ~import_shared_strings();
66
67 virtual size_t append(const char* s, size_t n);
68 virtual size_t add(const char* s, size_t n);
69
70 virtual void set_segment_font(size_t font_index);
71 virtual void set_segment_bold(bool b);
72 virtual void set_segment_italic(bool b);
73 virtual void set_segment_font_name(const char* s, size_t n);
74 virtual void set_segment_font_size(double point);
75 virtual void set_segment_font_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
76 virtual void append_segment(const char* s, size_t n);
77 virtual size_t commit_segments();
78
79 const format_runs_t* get_format_runs(size_t index) const;
80
81 const std::string* get_string(size_t index) const;
82
83 void dump() const;
84
85private:
86 orcus::string_pool& m_string_pool;
87 ixion::model_context& m_cxt;
88 styles& m_styles;
89
94 format_runs_map_type m_formats;
95
96 ::std::string m_cur_segment_string;
97 format_run m_cur_format;
98 format_runs_t* mp_cur_format_runs;
99 str_index_map_type m_set;
100};
101
102}}
103
104#endif
105/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: pstring.hpp:28
Definition: import_interface.hpp:31
Definition: shared_strings.hpp:52
virtual size_t append(const char *s, size_t n)
virtual void set_segment_font_size(double point)
virtual void set_segment_font_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue)
virtual void append_segment(const char *s, size_t n)
virtual size_t add(const char *s, size_t n)
virtual void set_segment_font_name(const char *s, size_t n)
virtual void set_segment_font(size_t font_index)
Definition: styles.hpp:150
Definition: string_pool.hpp:23
Definition: styles.hpp:21
Definition: shared_strings.hpp:31