xlnt
index_types.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2024 xlnt-community
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE
21 //
22 // @license: http://www.opensource.org/licenses/mit-license.php
23 // @author: see AUTHORS file
24 
25 #pragma once
26 
27 #include <algorithm>
28 #include <cstdint>
29 #include <string>
30 
31 #include <xlnt/xlnt_config.hpp>
32 
33 // We might want to change these types for various optimizations in the future
34 // so use typedefs.
35 
36 namespace xlnt {
37 
41 using row_t = std::uint32_t;
42 
48 class XLNT_API column_t
49 {
50 public:
54  using index_t = std::uint32_t;
55 
64  static index_t column_index_from_string(const std::string &column_string);
65 
74  static std::string column_string_from_index(index_t column_index);
75 
79  column_t();
80 
84  column_t(index_t column_index);
85 
89  column_t(const std::string &column_string);
90 
94  column_t(const char *column_string);
95 
99  std::string column_string() const;
100 
104  column_t &operator=(const std::string &rhs);
105 
109  column_t &operator=(const char *rhs);
110 
114  bool operator==(const column_t &other) const;
115 
119  bool operator!=(const column_t &other) const;
120 
124  bool operator==(int other) const;
125 
129  bool operator==(index_t other) const;
130 
134  bool operator==(const std::string &other) const;
135 
139  bool operator==(const char *other) const;
140 
144  bool operator!=(int other) const;
145 
149  bool operator!=(index_t other) const;
150 
154  bool operator!=(const std::string &other) const;
155 
159  bool operator!=(const char *other) const;
160 
164  bool operator>(const column_t &other) const;
165 
169  bool operator>=(const column_t &other) const;
170 
174  bool operator<(const column_t &other) const;
175 
179  bool operator<=(const column_t &other) const;
180 
184  bool operator>(const column_t::index_t &other) const;
185 
189  bool operator>=(const column_t::index_t &other) const;
190 
194  bool operator<(const column_t::index_t &other) const;
195 
199  bool operator<=(const column_t::index_t &other) const;
200 
204  column_t &operator++();
205 
209  column_t &operator--();
210 
214  column_t operator++(int);
215 
219  column_t operator--(int);
220 
224  friend XLNT_API column_t operator+(column_t lhs, const column_t &rhs);
225 
229  friend XLNT_API column_t operator-(column_t lhs, const column_t &rhs);
230 
234  column_t &operator+=(const column_t &rhs);
235 
239  column_t &operator-=(const column_t &rhs);
240 
244  friend XLNT_API bool operator>(const column_t::index_t &left, const column_t &right);
245 
249  friend XLNT_API bool operator>=(const column_t::index_t &left, const column_t &right);
250 
254  friend XLNT_API bool operator<(const column_t::index_t &left, const column_t &right);
255 
259  friend XLNT_API bool operator<=(const column_t::index_t &left, const column_t &right);
260 
264  friend XLNT_API void swap(column_t &left, column_t &right);
265 
270 };
271 
272 enum class row_or_col_t : int
273 {
274  row,
275  column
276 };
277 
282 struct XLNT_API column_hash
283 {
287  std::size_t operator()(const column_t &k) const;
288 };
289 
290 } // namespace xlnt
291 
292 namespace std {
293 
297 template <>
298 struct hash<xlnt::column_t>
299 {
303  size_t operator()(const xlnt::column_t &k) const
304  {
305  static xlnt::column_hash hasher;
306  return hasher(k);
307  }
308 };
309 
310 } // namespace std
index_t index
Internal numeric value of this column index.
Definition: index_types.hpp:269
std::uint32_t index_t
Alias declaration for the internal numeric type of this column.
Definition: index_types.hpp:54
std::uint32_t row_t
All rows should be referred to by an instance of this type.
Definition: index_types.hpp:41
Definition: cell_reference.hpp:262
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
size_t operator()(const xlnt::column_t &k) const
Returns the result of hashing column k.
Definition: index_types.hpp:303
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
Columns can be referred to as a string A,B,...Z,AA,AB,..,ZZ,AAA,...,ZZZ or as a 1-indexed index...
Definition: index_types.hpp:48
bool operator!=(const std::string &reference_string, const range_reference &ref)
Returns true if the string representation of the range is not equivalent to ref.
Functor for hashing a column. Allows for use of std::unordered_set<column_t, column_hash> and similar...
Definition: index_types.hpp:282