// Copyright (c) 2014-2021 Thomas Fussell // // 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 namespace xlnt { class cell_vector; /// /// An iterator used by worksheet and range for traversing /// a 2D grid of cells by row/column then across that row/column. /// class XLNT_API range_iterator { public: /// /// iterator tags required for use with standard algorithms and adapters /// using iterator_category = std::bidirectional_iterator_tag; using value_type = cell_vector; using difference_type = std::ptrdiff_t; using pointer = cell_vector *; using reference = cell_vector; // intentionally value /// /// Default constructs a range iterator /// range_iterator() = default; /// /// Constructs a range iterator on a worksheet, cell pointing to the current /// row or column, range bounds, an order, and whether or not to skip null column/rows. /// range_iterator(worksheet &ws, const cell_reference &cursor, const range_reference &bounds, major_order order, bool skip_null); /// /// Default copy constructor. /// range_iterator(const range_iterator &) = default; /// /// Default assignment operator. /// range_iterator &operator=(const range_iterator &) = default; /// /// Default move constructor. /// range_iterator(range_iterator &&) = default; /// /// Default move assignment operator. /// range_iterator &operator=(range_iterator &&) = default; /// /// Default destructor /// ~range_iterator() = default; /// /// Dereference the iterator to return a column or row. /// reference operator*(); /// /// Dereference the iterator to return a column or row. /// const reference operator*() const; /// /// Returns true if this iterator is equivalent to other. /// bool operator==(const range_iterator &other) const; /// /// Returns true if this iterator is not equivalent to other. /// bool operator!=(const range_iterator &other) const; /// /// Pre-decrement the iterator to point to the previous row/column. /// range_iterator &operator--(); /// /// Post-decrement the iterator to point to the previous row/column. /// range_iterator operator--(int); /// /// Pre-increment the iterator to point to the next row/column. /// range_iterator &operator++(); /// /// Post-increment the iterator to point to the next row/column. /// range_iterator operator++(int); private: /// /// If true, empty rows and cells will be skipped when iterating with this iterator /// bool skip_null_ = false; /// /// Whether rows or columns should be iterated over first /// major_order order_ = major_order::column; /// /// The worksheet /// worksheet ws_; /// /// The first cell in the current row/column /// cell_reference cursor_; /// /// The bounds of the range /// range_reference bounds_; }; /// /// A const version of range_iterator which does not allow modification /// to the dereferenced cell_vector. /// class XLNT_API const_range_iterator { public: /// /// this iterator meets the interface requirements of bidirection_iterator /// using iterator_category = std::bidirectional_iterator_tag; using value_type = const cell_vector; using difference_type = std::ptrdiff_t; using pointer = const cell_vector *; using reference = const cell_vector; // intentionally value /// /// Default constructs a range iterator /// const_range_iterator() = default; /// /// Constructs a range iterator on a worksheet, cell pointing to the current /// row or column, range bounds, an order, and whether or not to skip null column/rows. /// const_range_iterator(const worksheet &ws, const cell_reference &cursor, const range_reference &bounds, major_order order, bool skip_null); /// /// Default copy constructor. /// const_range_iterator(const const_range_iterator &) = default; /// /// Default assignment operator. /// const_range_iterator &operator=(const const_range_iterator &) = default; /// /// Default move constructor. /// const_range_iterator(const_range_iterator &&) = default; /// /// Default move assignment operator. /// const_range_iterator &operator=(const_range_iterator &&) = default; /// /// Default destructor /// ~const_range_iterator() = default; /// /// Dereferennce the iterator to return the current column/row. /// const reference operator*() const; /// /// Returns true if this iterator is equivalent to other. /// bool operator==(const const_range_iterator &other) const; /// /// Returns true if this iterator is not equivalent to other. /// bool operator!=(const const_range_iterator &other) const; /// /// Pre-decrement the iterator to point to the next row/column. /// const_range_iterator &operator--(); /// /// Post-decrement the iterator to point to the next row/column. /// const_range_iterator operator--(int); /// /// Pre-increment the iterator to point to the next row/column. /// const_range_iterator &operator++(); /// /// Post-increment the iterator to point to the next row/column. /// const_range_iterator operator++(int); private: /// /// If true, empty rows and cells will be skipped when iterating with this iterator /// bool skip_null_ = false; /// /// Determines whether iteration should move through rows or columns first /// major_order order_ = major_order::column; /// /// The implementation of the worksheet this iterator points to /// detail::worksheet_impl *ws_; /// /// The first cell in the current row or column this iterator points to /// cell_reference cursor_; /// /// The range this iterator starts and ends in /// range_reference bounds_; }; } // namespace xlnt