Orcus
Loading...
Searching...
No Matches
auto_filter.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_AUTO_FILTER_HPP
9#define INCLUDED_ORCUS_SPREADSHEET_AUTO_FILTER_HPP
10
11#include "types.hpp"
12#include "../env.hpp"
13
14#include <map>
15#include <deque>
16#include <memory>
17#include <variant>
18#include <unordered_set>
19#include <unordered_map>
20
21#include <ixion/address.hpp>
22
23namespace orcus { namespace spreadsheet {
24
29class ORCUS_SPM_DLLPUBLIC filter_value_t
30{
31 using store_type = std::variant<std::monostate, double, std::string_view>;
32 store_type m_store;
33
34public:
35 enum class value_type { empty, numeric, string };
36
37 filter_value_t();
38 filter_value_t(double v);
39 filter_value_t(std::string_view v);
40 filter_value_t(const filter_value_t& other);
41 ~filter_value_t();
42
43 bool operator==(const filter_value_t& other) const;
44 bool operator!=(const filter_value_t& other) const;
45 bool operator<(const filter_value_t& other) const;
46
47 filter_value_t& operator=(const filter_value_t& other);
48
49 value_type type() const noexcept;
50
51 double numeric() const;
52
53 std::string_view string() const;
54
55 void swap(filter_value_t& other) noexcept;
56};
57
58class ORCUS_SPM_DLLPUBLIC filterable
59{
60public:
61 virtual ~filterable();
62};
63
67class ORCUS_SPM_DLLPUBLIC filter_item_t : public filterable
68{
69 col_t m_field = -1;
70 auto_filter_op_t m_op = auto_filter_op_t::unspecified;
71 filter_value_t m_value;
72 bool m_regex = false;
73
74public:
75 filter_item_t();
76 filter_item_t(col_t _field, auto_filter_op_t _op);
77 filter_item_t(col_t _field, auto_filter_op_t _op, double v);
78 filter_item_t(col_t _field, auto_filter_op_t _op, std::string_view v);
79 filter_item_t(col_t _field, auto_filter_op_t _op, std::string_view v, bool _regex);
80 filter_item_t(const filter_item_t& other);
81 ~filter_item_t() override;
82
83 col_t field() const;
84 auto_filter_op_t op() const;
85 filter_value_t value() const;
86 bool regex() const;
87
88 filter_item_t& operator=(const filter_item_t& other);
89
90 void swap(filter_item_t& other) noexcept;
91
92 bool operator==(const filter_item_t& other) const;
93 bool operator!=(const filter_item_t& other) const;
94 bool operator<(const filter_item_t& other) const;
95};
96
97class ORCUS_SPM_DLLPUBLIC filter_item_set_t : public filterable
98{
99 col_t m_field = -1;
100 std::unordered_set<std::string_view> m_values;
101
102public:
103 filter_item_set_t();
104 filter_item_set_t(col_t _field);
105 filter_item_set_t(col_t field, std::initializer_list<std::string_view> values);
106 filter_item_set_t(const filter_item_set_t& other);
107 filter_item_set_t(filter_item_set_t&& other);
108 ~filter_item_set_t() override;
109
110 col_t field() const;
111 const std::unordered_set<std::string_view>& values() const;
112 void insert(std::string_view value);
113
114 filter_item_set_t& operator=(const filter_item_set_t& other);
115 filter_item_set_t& operator=(filter_item_set_t&& other);
116
117 void reset();
118 void swap(filter_item_set_t& other) noexcept;
119
120 bool operator==(const filter_item_set_t& other) const;
121 bool operator!=(const filter_item_set_t& other) const;
122};
123
128class ORCUS_SPM_DLLPUBLIC filter_node_t : public filterable
129{
130 struct impl;
131 std::unique_ptr<impl> m_impl;
132
133public:
134 filter_node_t();
135 filter_node_t(auto_filter_node_op_t _op);
136
137 filter_node_t(const filter_node_t& other) = delete;
138 filter_node_t(filter_node_t&& other);
139 ~filter_node_t() override;
140
141 filter_node_t& operator=(const filter_node_t& other) = delete;
142 filter_node_t& operator=(filter_node_t&& other);
143
144 auto_filter_node_op_t op() const noexcept;
145
149 std::size_t size() const noexcept;
150
151 bool empty() const noexcept;
152
156 const filterable* at(std::size_t pos) const;
157
158 void append(filter_node_t child);
159 void append(filter_item_t child);
160 void append(filter_item_set_t child);
161
162 void reset();
163 void swap(filter_node_t& other) noexcept;
164};
165
170struct ORCUS_SPM_DLLPUBLIC auto_filter_t
171{
172 ixion::abs_rc_range_t range;
173 filter_node_t root;
174
175 auto_filter_t();
176 auto_filter_t(const auto_filter_t& other) = delete;
177 auto_filter_t(auto_filter_t&& other);
178 ~auto_filter_t();
179
180 auto_filter_t& operator=(const auto_filter_t& other) = delete;
181 auto_filter_t& operator=(auto_filter_t&& other);
182
183 void reset();
184 void swap(auto_filter_t& other);
185};
186
187ORCUS_SPM_DLLPUBLIC std::ostream& operator<<(std::ostream& os, const filter_item_t& v);
188
189}}
190
191#endif
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition auto_filter.hpp:98
Definition auto_filter.hpp:68
Definition auto_filter.hpp:129
const filterable * at(std::size_t pos) const
std::size_t size() const noexcept
Definition auto_filter.hpp:30
Definition auto_filter.hpp:59