// Copyright (c) 2014-2021 Thomas Fussell // Copyright (c) 2010-2015 openpyxl // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #pragma once #include // std::ptrdiff_t #include #include #include #include #include #include namespace xlnt { enum class major_order; class cell; class cell_reference; class range_reference; /// /// A cell iterator iterates over a 1D range by row or by column. /// class XLNT_API cell_iterator { public: /// /// iterator tags required for use with standard algorithms and adapters /// using iterator_category = std::bidirectional_iterator_tag; using value_type = cell; using difference_type = std::ptrdiff_t; using pointer = cell *; using reference = cell; // intentionally value /// /// Default constructs a cell_iterator /// cell_iterator() = default; /// /// Constructs a cell_iterator from a worksheet, range, and iteration settings. /// cell_iterator(worksheet ws, const cell_reference &start_cell, const range_reference &limits, major_order order, bool skip_null, bool wrap); /// /// Constructs a cell_iterator as a copy of an existing cell_iterator. /// cell_iterator(const cell_iterator &) = default; /// /// Assigns this iterator to match the data in rhs. /// cell_iterator &operator=(const cell_iterator &) = default; /// /// Constructs a cell_iterator by moving from a cell_iterator temporary /// cell_iterator(cell_iterator &&) = default; /// /// Assigns this iterator to from a cell_iterator temporary /// cell_iterator &operator=(cell_iterator &&) = default; /// /// destructor for const_cell_iterator /// ~cell_iterator() = default; /// /// Dereferences this iterator to return the cell it points to. /// reference operator*(); /// /// Dereferences this iterator to return the cell it points to. /// const reference operator*() const; /// /// Returns true if this iterator is equivalent to other. /// bool operator==(const cell_iterator &other) const; /// /// Returns true if this iterator isn't equivalent to other. /// bool operator!=(const cell_iterator &other) const; /// /// Pre-decrements the iterator to point to the previous cell and /// returns a reference to the iterator. /// cell_iterator &operator--(); /// /// Post-decrements the iterator to point to the previous cell and /// return a copy of the iterator before the decrement. /// cell_iterator operator--(int); /// /// Pre-increments the iterator to point to the previous cell and /// returns a reference to the iterator. /// cell_iterator &operator++(); /// /// Post-increments the iterator to point to the previous cell and /// return a copy of the iterator before the decrement. /// cell_iterator operator++(int); private: /// /// If true, cells that don't exist in the worksheet will be skipped during iteration. /// bool skip_null_ = false; /// /// If true, when on the last column, the cursor will continue to the next row /// (and vice versa when iterating in column-major order) until reaching the /// bottom right corner of the range. /// bool wrap_ = false; /// /// The order this iterator will move, by column or by row. Note that /// this has the opposite meaning as in a range_iterator because after /// getting a row-major range_iterator, the row-major cell_iterator will /// iterate over a column and vice versa. /// major_order order_ = major_order::column; /// /// The worksheet this iterator will return cells from. /// worksheet ws_; /// /// The current cell the iterator points to /// cell_reference cursor_; /// /// The range of cells this iterator is restricted to /// range_reference bounds_; }; /// /// A cell iterator iterates over a 1D range by row or by column. /// class XLNT_API const_cell_iterator { public: /// /// iterator tags required for use with standard algorithms and adapters /// using iterator_category = std::bidirectional_iterator_tag; using value_type = const cell; using difference_type = std::ptrdiff_t; using pointer = const cell *; using reference = const cell; // intentionally value /// /// Default constructs a cell_iterator /// const_cell_iterator() = default; /// /// Constructs a cell_iterator from a worksheet, range, and iteration settings. /// const_cell_iterator(worksheet ws, const cell_reference &start_cell, const range_reference &limits, major_order order, bool skip_null, bool wrap); /// /// Constructs a const_cell_iterator as a copy of an existing cell_iterator. /// const_cell_iterator(const const_cell_iterator &) = default; /// /// Assigns this iterator to match the data in rhs. /// const_cell_iterator &operator=(const const_cell_iterator &) = default; /// /// Constructs a const_cell_iterator by moving from a const_cell_iterator temporary /// const_cell_iterator(const_cell_iterator &&) = default; /// /// Assigns this iterator to from a const_cell_iterator temporary /// const_cell_iterator &operator=(const_cell_iterator &&) = default; /// /// destructor for const_cell_iterator /// ~const_cell_iterator() = default; /// /// Dereferences this iterator to return the cell it points to. /// const reference operator*() const; /// /// Returns true if this iterator is equivalent to other. /// bool operator==(const const_cell_iterator &other) const; /// /// Returns true if this iterator isn't equivalent to other. /// bool operator!=(const const_cell_iterator &other) const; /// /// Pre-decrements the iterator to point to the previous cell and /// returns a reference to the iterator. /// const_cell_iterator &operator--(); /// /// Post-decrements the iterator to point to the previous cell and /// return a copy of the iterator before the decrement. /// const_cell_iterator operator--(int); /// /// Pre-increments the iterator to point to the previous cell and /// returns a reference to the iterator. /// const_cell_iterator &operator++(); /// /// Post-increments the iterator to point to the previous cell and /// return a copy of the iterator before the decrement. /// const_cell_iterator operator++(int); private: /// /// If true, cells that don't exist in the worksheet will be skipped during iteration. /// bool skip_null_ = false; /// /// If true, when on the last column, the cursor will continue to the next row /// (and vice versa when iterating in column-major order) until reaching the /// bottom right corner of the range. /// bool wrap_ = false; /// /// The order this iterator will move, by column or by row. Note that /// this has the opposite meaning as in a range_iterator because after /// getting a row-major range_iterator, the row-major cell_iterator will /// iterate over a column and vice versa. /// major_order order_ = major_order::column; /// /// The worksheet this iterator will return cells from. /// worksheet ws_; /// /// The current cell the iterator points to /// cell_reference cursor_; /// /// The range of cells this iterator is restricted to /// range_reference bounds_; }; } // namespace xlnt