// 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 #include namespace xlnt { /// /// A range_reference describes a rectangular area of a worksheet with positive /// width and height defined by a top-left and bottom-right corner. /// class XLNT_API range_reference { public: /// /// Converts relative reference coordinates to absolute coordinates (B12 -> $B$12) /// static range_reference make_absolute(const range_reference &relative_reference); /// /// Constructs a range reference equal to A1:A1 /// range_reference(); /// /// Constructs a range reference equivalent to the provided range_string in the form /// top_left:bottom_right. /// explicit range_reference(const std::string &range_string); /// /// Constructs a range reference equivalent to the provided range_string in the form /// top_left:bottom_right. /// explicit range_reference(const char *range_string); /// /// Constructs a range reference from cell references indicating top /// left and bottom right coordinates of the range. /// range_reference(const cell_reference &start, const cell_reference &end); /// /// Constructs a range reference from column and row indices. /// range_reference(column_t column_index_start, row_t row_index_start, column_t column_index_end, row_t row_index_end); /// /// Returns true if the range has a width and height of 1 cell. /// bool is_single_cell() const; /// /// Returns the number of columns encompassed by this range. /// std::size_t width() const; /// /// Returns the number of rows encompassed by this range. /// std::size_t height() const; /// /// Returns the coordinate of the top left cell of this range. /// cell_reference top_left() const; /// /// Returns the coordinate of the top right cell of this range. /// cell_reference top_right() const; /// /// Returns the coordinate of the bottom left cell of this range. /// cell_reference bottom_left() const; /// /// Returns the coordinate of the bottom right cell of this range. /// cell_reference bottom_right() const; /// /// Returns a new range reference with the same width and height as this /// range but shifted by the given number of columns and rows. /// range_reference make_offset(int column_offset, int row_offset) const; /// /// Returns a string representation of this range. /// std::string to_string() const; /// /// Returns true if the given cell reference is within the bounds of this range reference. /// bool contains(const cell_reference &ref) const; /// /// Returns true if this range is equivalent to the other range. /// bool operator==(const range_reference &comparand) const; /// /// Returns true if this range is equivalent to the string representation /// of the other range. /// bool operator==(const std::string &reference_string) const; /// /// Returns true if this range is equivalent to the string representation /// of the other range. /// bool operator==(const char *reference_string) const; /// /// Returns true if this range is not equivalent to the other range. /// bool operator!=(const range_reference &comparand) const; /// /// Returns true if this range is not equivalent to the string representation /// of the other range. /// bool operator!=(const std::string &reference_string) const; /// /// Returns true if this range is not equivalent to the string representation /// of the other range. /// bool operator!=(const char *reference_string) const; private: /// /// The top left cell in the range /// cell_reference top_left_; /// /// The bottom right cell in the range /// cell_reference bottom_right_; }; /// /// Returns true if the string representation of the range is equivalent to ref. /// XLNT_API bool operator==(const std::string &reference_string, const range_reference &ref); /// /// Returns true if the string representation of the range is equivalent to ref. /// XLNT_API bool operator==(const char *reference_string, const range_reference &ref); /// /// Returns true if the string representation of the range is not equivalent to ref. /// XLNT_API 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. /// XLNT_API bool operator!=(const char *reference_string, const range_reference &ref); } // namespace xlnt