8#ifndef INCLUDED_ORCUS_SPREADSHEET_PIVOT_HPP
9#define INCLUDED_ORCUS_SPREADSHEET_PIVOT_HPP
12#include "../types.hpp"
33namespace spreadsheet {
40class debug_state_dumper_pivot_cache;
41class debug_state_dumper_pivot_table;
45using pivot_cache_indices_t = std::vector<size_t>;
47struct ORCUS_SPM_DLLPUBLIC pivot_cache_record_value_t
49 using value_type = std::variant<bool, double, std::size_t, std::string_view, date_time_t, error_value_t>;
51 enum class record_type
66 pivot_cache_record_value_t();
67 pivot_cache_record_value_t(std::string_view s);
68 pivot_cache_record_value_t(
double v);
69 pivot_cache_record_value_t(
size_t index);
71 bool operator== (
const pivot_cache_record_value_t& other)
const;
72 bool operator!= (
const pivot_cache_record_value_t& other)
const;
75using pivot_cache_record_t = std::vector<pivot_cache_record_value_t>;
77struct ORCUS_SPM_DLLPUBLIC pivot_cache_item_t
79 using value_type = std::variant<bool, double, std::string_view, date_time_t, error_value_t>;
83 unknown = 0, boolean, date_time, character, numeric, blank, error
90 pivot_cache_item_t(std::string_view s);
91 pivot_cache_item_t(
double numeric);
92 pivot_cache_item_t(
bool boolean);
94 pivot_cache_item_t(error_value_t error);
96 pivot_cache_item_t(
const pivot_cache_item_t& other);
97 pivot_cache_item_t(pivot_cache_item_t&& other);
99 bool operator< (
const pivot_cache_item_t& other)
const;
100 bool operator== (
const pivot_cache_item_t& other)
const;
102 pivot_cache_item_t& operator= (pivot_cache_item_t other);
104 void swap(pivot_cache_item_t& other);
107using pivot_cache_items_t = std::vector<pivot_cache_item_t>;
112struct ORCUS_SPM_DLLPUBLIC pivot_cache_group_data_t
114 struct ORCUS_SPM_DLLPUBLIC range_grouping_type
116 pivot_cache_group_by_t group_by = pivot_cache_group_by_t::range;
118 bool auto_start =
true;
119 bool auto_end =
true;
123 double interval = 1.0;
128 range_grouping_type();
129 range_grouping_type(
const range_grouping_type& other);
137 std::optional<range_grouping_type> range_grouping;
147 pivot_cache_group_data_t(
size_t _base_field);
148 pivot_cache_group_data_t(
const pivot_cache_group_data_t& other);
149 pivot_cache_group_data_t(pivot_cache_group_data_t&& other);
151 pivot_cache_group_data_t() =
delete;
154struct ORCUS_SPM_DLLPUBLIC pivot_cache_field_t
162 pivot_cache_items_t items;
164 std::optional<double> min_value;
165 std::optional<double> max_value;
167 std::optional<date_time_t> min_date;
168 std::optional<date_time_t> max_date;
170 std::unique_ptr<pivot_cache_group_data_t> group_data;
172 pivot_cache_field_t();
173 pivot_cache_field_t(std::string_view _name);
174 pivot_cache_field_t(
const pivot_cache_field_t& other);
175 pivot_cache_field_t(pivot_cache_field_t&& other);
177 pivot_cache_field_t& operator=(pivot_cache_field_t other);
179 void swap(pivot_cache_field_t& other)
noexcept;
182struct ORCUS_SPM_DLLPUBLIC pivot_item_t
184 using value_type = std::variant<std::size_t, pivot_field_item_t>;
198 pivot_item_t(
const pivot_item_t& other);
199 pivot_item_t(pivot_item_t&& other);
200 pivot_item_t(std::size_t i,
bool _hidden);
201 pivot_item_t(pivot_field_item_t t);
204 pivot_item_t& operator=(pivot_item_t other);
206 void swap(pivot_item_t& other)
noexcept;
209using pivot_items_t = std::vector<pivot_item_t>;
211struct ORCUS_SPM_DLLPUBLIC pivot_field_t
213 pivot_axis_t axis = pivot_axis_t::unknown;
217 pivot_field_t(
const pivot_field_t& other);
218 pivot_field_t(pivot_field_t&& other);
221 pivot_field_t& operator=(pivot_field_t other);
223 void swap(pivot_field_t& other)
noexcept;
226using pivot_fields_t = std::vector<pivot_field_t>;
228struct ORCUS_SPM_DLLPUBLIC pivot_ref_rc_field_t
230 enum class value_type { unknown = 0, index, data };
232 value_type type = value_type::unknown;
233 std::size_t index = 0;
235 pivot_ref_rc_field_t();
236 pivot_ref_rc_field_t(
const pivot_ref_rc_field_t& other);
237 pivot_ref_rc_field_t(pivot_ref_rc_field_t&& other);
238 pivot_ref_rc_field_t(std::size_t _index);
239 pivot_ref_rc_field_t(value_type vt);
240 ~pivot_ref_rc_field_t();
242 pivot_ref_rc_field_t& operator=(pivot_ref_rc_field_t other);
244 void swap(pivot_ref_rc_field_t& other)
noexcept;
247using pivot_ref_rc_fields_t = std::vector<pivot_ref_rc_field_t>;
249struct ORCUS_SPM_DLLPUBLIC pivot_ref_page_field_t
251 std::size_t field = 0;
252 std::optional<std::size_t> item;
254 pivot_ref_page_field_t();
255 pivot_ref_page_field_t(
const pivot_ref_page_field_t& other);
256 pivot_ref_page_field_t(pivot_ref_page_field_t&& other);
257 ~pivot_ref_page_field_t();
259 pivot_ref_page_field_t& operator=(pivot_ref_page_field_t other);
261 void swap(pivot_ref_page_field_t& other)
noexcept;
264using pivot_ref_page_fields_t = std::vector<pivot_ref_page_field_t>;
266struct ORCUS_SPM_DLLPUBLIC pivot_ref_data_field_t
268 std::size_t field = 0;
269 std::string_view name;
270 pivot_data_subtotal_t subtotal = pivot_data_subtotal_t::unknown;
272 pivot_data_show_data_as_t show_data_as = pivot_data_show_data_as_t::unknown;
273 std::size_t base_field = 0;
274 std::size_t base_item = 0;
276 pivot_ref_data_field_t();
277 pivot_ref_data_field_t(
const pivot_ref_data_field_t& other);
278 pivot_ref_data_field_t(pivot_ref_data_field_t&& other);
279 ~pivot_ref_data_field_t();
281 pivot_ref_data_field_t& operator=(pivot_ref_data_field_t other);
283 void swap(pivot_ref_data_field_t& other)
noexcept;
286using pivot_ref_data_fields_t = std::vector<pivot_ref_data_field_t>;
294struct ORCUS_SPM_DLLPUBLIC pivot_ref_rc_item_t
296 pivot_field_item_t type = pivot_field_item_t::unknown;
300 std::vector<std::size_t> items;
301 std::optional<std::size_t> data_item;
303 pivot_ref_rc_item_t();
304 pivot_ref_rc_item_t(
const pivot_ref_rc_item_t& other);
305 pivot_ref_rc_item_t(pivot_ref_rc_item_t&& other);
306 ~pivot_ref_rc_item_t();
308 pivot_ref_rc_item_t& operator=(pivot_ref_rc_item_t other);
310 void swap(pivot_ref_rc_item_t& other)
noexcept;
313using pivot_ref_rc_items_t = std::vector<pivot_ref_rc_item_t>;
315class ORCUS_SPM_DLLPUBLIC pivot_cache
317 friend class detail::debug_state_dumper_pivot_cache;
318 friend class detail::debug_state_dumper_pivot_table;
319 friend class pivot_collection;
322 std::unique_ptr<impl> mp_impl;
325 using fields_type = std::vector<pivot_cache_field_t>;
326 using records_type = std::vector<pivot_cache_record_t>;
328 pivot_cache(pivot_cache_id_t cache_id,
string_pool& sp);
339 void insert_records(records_type record);
341 size_t get_field_count()
const;
353 pivot_cache_id_t get_id()
const;
355 const records_type& get_all_records()
const;
358class ORCUS_SPM_DLLPUBLIC pivot_table
360 friend class detail::debug_state_dumper_pivot_table;
361 friend class pivot_collection;
364 std::unique_ptr<impl> mp_impl;
368 pivot_table(
const pivot_table&) =
delete;
369 pivot_table(pivot_table&& other);
372 pivot_table& operator=(
const pivot_table&) =
delete;
373 pivot_table& operator=(pivot_table&& other);
375 std::string_view get_name()
const;
376 void set_name(std::string_view name);
377 void set_cache_id(pivot_cache_id_t cache_id);
378 void set_range(
const ixion::abs_rc_range_t& range);
379 void set_pivot_fields(pivot_fields_t fields);
380 void set_row_fields(pivot_ref_rc_fields_t fields);
381 void set_column_fields(pivot_ref_rc_fields_t fields);
382 void set_page_fields(pivot_ref_page_fields_t fields);
383 void set_data_fields(pivot_ref_data_fields_t fields);
384 void set_row_items(pivot_ref_rc_items_t items);
385 void set_column_items(pivot_ref_rc_items_t items);
388class ORCUS_SPM_DLLPUBLIC pivot_collection
391 std::unique_ptr<impl> mp_impl;
395 pivot_collection(
const pivot_collection&) =
delete;
407 std::string_view sheet_name,
const ixion::abs_range_t& range, std::unique_ptr<pivot_cache>&& cache);
427 std::string_view sheet_name,
const ixion::abs_range_t& range)
const;
431 const pivot_cache* get_cache(pivot_cache_id_t cache_id)
const;
433 void dump_debug_state(std::string_view outdir)
const;
436ORCUS_SPM_DLLPUBLIC std::ostream& operator<<(std::ostream& os,
const pivot_cache_item_t& item);
438ORCUS_SPM_DLLPUBLIC std::ostream& operator<<(std::ostream& os,
const pivot_item_t& v);
Definition document.hpp:55
const pivot_cache_field_t * get_field(size_t index) const
void insert_fields(fields_type fields)
void insert_worksheet_cache(std::string_view sheet_name, const ixion::abs_range_t &range, std::unique_ptr< pivot_cache > &&cache)
size_t get_cache_count() const
void insert_worksheet_cache(std::string_view table_name, std::unique_ptr< pivot_cache > &&cache)
Definition string_pool.hpp:26
std::string_view name
Definition pivot.hpp:160
pivot_cache_indices_t base_to_group_indices
Definition pivot.hpp:135
pivot_cache_items_t items
Definition pivot.hpp:142
size_t base_field
Definition pivot.hpp:145
std::size_t repeat
Definition pivot.hpp:299