xlnt - community edition
index_types.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2024-2026 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 <cstdint>
28 #include <string>
29 
30 #include <xlnt/xlnt_config.hpp>
31 
32 // We might want to change these types for various optimizations in the future
33 // so use typedefs.
34 
35 namespace xlnt {
36 
43 using row_t = std::uint32_t;
44 
53 class XLNT_API column_t
54 {
55 public:
59  using index_t = std::uint32_t;
60 
69  static index_t column_index_from_string(const std::string &column_string);
70 
79  static std::string column_string_from_index(index_t column_index);
80 
84  column_t();
85 
89  column_t(index_t column_index);
90 
97  column_t(const std::string &column_string);
98 
105  column_t(const char *column_string);
106 
110  std::string column_string() const;
111 
115  column_t &operator=(const std::string &rhs);
116 
120  column_t &operator=(const char *rhs);
121 
125  bool operator==(const column_t &other) const;
126 
130  bool operator!=(const column_t &other) const;
131 
135  bool operator==(int other) const;
136 
140  bool operator==(index_t other) const;
141 
145  bool operator==(const std::string &other) const;
146 
150  bool operator==(const char *other) const;
151 
155  bool operator!=(int other) const;
156 
160  bool operator!=(index_t other) const;
161 
165  bool operator!=(const std::string &other) const;
166 
170  bool operator!=(const char *other) const;
171 
175  bool operator>(const column_t &other) const;
176 
180  bool operator>=(const column_t &other) const;
181 
185  bool operator<(const column_t &other) const;
186 
190  bool operator<=(const column_t &other) const;
191 
195  bool operator>(const column_t::index_t &other) const;
196 
200  bool operator>=(const column_t::index_t &other) const;
201 
205  bool operator<(const column_t::index_t &other) const;
206 
210  bool operator<=(const column_t::index_t &other) const;
211 
215  column_t &operator++();
216 
220  column_t &operator--();
221 
225  column_t operator++(int);
226 
230  column_t operator--(int);
231 
235  friend XLNT_API column_t operator+(column_t lhs, const column_t &rhs);
236 
240  friend XLNT_API column_t operator-(column_t lhs, const column_t &rhs);
241 
245  column_t &operator+=(const column_t &rhs);
246 
250  column_t &operator-=(const column_t &rhs);
251 
255  friend XLNT_API bool operator>(const column_t::index_t &left, const column_t &right);
256 
260  friend XLNT_API bool operator>=(const column_t::index_t &left, const column_t &right);
261 
265  friend XLNT_API bool operator<(const column_t::index_t &left, const column_t &right);
266 
270  friend XLNT_API bool operator<=(const column_t::index_t &left, const column_t &right);
271 
275  friend XLNT_API void swap(column_t &left, column_t &right);
276 
281 };
282 
283 enum class row_or_col_t : int
284 {
285  row,
286  column
287 };
288 
293 struct XLNT_API column_hash
294 {
298  std::size_t operator()(const column_t &k) const;
299 };
300 
301 } // namespace xlnt
302 
303 namespace std {
304 
308 template <>
309 struct hash<xlnt::column_t>
310 {
314  size_t operator()(const xlnt::column_t &k) const
315  {
316  static xlnt::column_hash hasher;
317  return hasher(k);
318  }
319 };
320 
321 } // namespace std
index_t index
Internal numeric value of this column index.
Definition: index_types.hpp:280
std::uint32_t index_t
Alias declaration for the internal numeric type of this column.
Definition: index_types.hpp:59
std::uint32_t row_t
All rows should be referred to by an instance of this type. By default, row references range from 1 t...
Definition: index_types.hpp:43
Definition: cell_reference.hpp:288
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:36
bool operator!=(std::nullptr_t, const cell &cell)
Returns true if this cell is initialized.
size_t operator()(const xlnt::column_t &k) const
Returns the result of hashing column k.
Definition: index_types.hpp:314
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,...,XFD or as a 1-indexed index (indi...
Definition: index_types.hpp:53
Functor for hashing a column. Allows for use of std::unordered_set<column_t, column_hash> and similar...
Definition: index_types.hpp:293