From 74bfdb6f7d0ea60cbfc090eb4d5002bb74c670ea Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sun, 24 Jan 2016 11:15:49 -0500 Subject: [PATCH] clean up iterators --- .../workbook/const_worksheet_iterator.hpp | 56 +++++++ include/xlnt/workbook/workbook.hpp | 45 +----- include/xlnt/workbook/worksheet_iterator.hpp | 56 +++++++ include/xlnt/worksheet/cell_iterator.hpp | 70 +++++++++ include/xlnt/worksheet/cell_vector.hpp | 63 +------- .../xlnt/worksheet/const_cell_iterator.hpp | 70 +++++++++ ...erator_2d.hpp => const_range_iterator.hpp} | 52 ++----- include/xlnt/worksheet/range.hpp | 10 +- include/xlnt/worksheet/range_iterator.hpp | 71 +++++++++ include/xlnt/worksheet/worksheet.hpp | 11 +- include/xlnt/xlnt.hpp | 6 + source/serialization/excel_serializer.cpp | 2 + source/serialization/workbook_serializer.cpp | 1 + source/serialization/worksheet_serializer.cpp | 2 + source/workbook/const_worksheet_iterator.cpp | 61 ++++++++ source/workbook/workbook.cpp | 64 +------- source/workbook/worksheet_iterator.cpp | 61 ++++++++ source/worksheet/cell_iterator.cpp | 97 ++++++++++++ source/worksheet/cell_vector.cpp | 133 +--------------- source/worksheet/const_cell_iterator.cpp | 92 +++++++++++ source/worksheet/const_range_iterator.cpp | 95 ++++++++++++ source/worksheet/range.cpp | 144 +----------------- source/worksheet/range_iterator.cpp | 109 +++++++++++++ source/worksheet/worksheet.cpp | 4 + 24 files changed, 895 insertions(+), 480 deletions(-) create mode 100644 include/xlnt/workbook/const_worksheet_iterator.hpp create mode 100644 include/xlnt/workbook/worksheet_iterator.hpp create mode 100644 include/xlnt/worksheet/cell_iterator.hpp create mode 100644 include/xlnt/worksheet/const_cell_iterator.hpp rename include/xlnt/worksheet/{range_iterator_2d.hpp => const_range_iterator.hpp} (55%) create mode 100644 include/xlnt/worksheet/range_iterator.hpp create mode 100644 source/workbook/const_worksheet_iterator.cpp create mode 100644 source/workbook/worksheet_iterator.cpp create mode 100644 source/worksheet/cell_iterator.cpp create mode 100644 source/worksheet/const_cell_iterator.cpp create mode 100644 source/worksheet/const_range_iterator.cpp create mode 100644 source/worksheet/range_iterator.cpp diff --git a/include/xlnt/workbook/const_worksheet_iterator.hpp b/include/xlnt/workbook/const_worksheet_iterator.hpp new file mode 100644 index 00000000..0696ca3c --- /dev/null +++ b/include/xlnt/workbook/const_worksheet_iterator.hpp @@ -0,0 +1,56 @@ +// Copyright (c) 2014-2016 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, WRISING 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 + +#include + +namespace xlnt { + +class workbook; +class worksheet; + +class XLNT_CLASS const_worksheet_iterator : public std::iterator +{ +public: + const_worksheet_iterator(const workbook &wb, std::size_t index); + const_worksheet_iterator(const const_worksheet_iterator &); + const_worksheet_iterator &operator=(const const_worksheet_iterator &); + const worksheet operator*(); + bool operator==(const const_worksheet_iterator &comparand) const; + bool operator!=(const const_worksheet_iterator &comparand) const + { + return !(*this == comparand); + } + const_worksheet_iterator operator++(int); + const_worksheet_iterator &operator++(); + +private: + const workbook &wb_; + std::size_t index_; +}; + +} // namespace xlnt diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 5d2fcbce..9b5fde92 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -37,6 +37,7 @@ namespace xlnt { class alignment; class border; class color; +class const_worksheet_iterator; class document_properties; class drawing; class fill; @@ -52,6 +53,7 @@ class relationship; class style; class theme; class worksheet; +class worksheet_iterator; class zip_file; enum class encoding; @@ -66,46 +68,9 @@ struct workbook_impl; class XLNT_CLASS workbook { public: - class XLNT_CLASS iterator - { - public: - iterator(workbook &wb, std::size_t index); - iterator(const iterator &); - iterator &operator=(const iterator &); - worksheet operator*(); - bool operator==(const iterator &comparand) const; - bool operator!=(const iterator &comparand) const - { - return !(*this == comparand); - } - iterator operator++(int); - iterator &operator++(); - - private: - workbook &wb_; - std::size_t index_; - }; - - class XLNT_CLASS const_iterator - { - public: - const_iterator(const workbook &wb, std::size_t index); - const_iterator(const const_iterator &); - const_iterator &operator=(const const_iterator &); - const worksheet operator*(); - bool operator==(const const_iterator &comparand) const; - bool operator!=(const const_iterator &comparand) const - { - return !(*this == comparand); - } - const_iterator operator++(int); - const_iterator &operator++(); - - private: - const workbook &wb_; - std::size_t index_; - }; - + using iterator = worksheet_iterator; + using const_iterator = const_worksheet_iterator; + static std::size_t index_from_ws_filename(const std::string &filename); // constructors diff --git a/include/xlnt/workbook/worksheet_iterator.hpp b/include/xlnt/workbook/worksheet_iterator.hpp new file mode 100644 index 00000000..f206d587 --- /dev/null +++ b/include/xlnt/workbook/worksheet_iterator.hpp @@ -0,0 +1,56 @@ +// Copyright (c) 2014-2016 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, WRISING 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 + +#include + +namespace xlnt { + +class workbook; +class worksheet; + +class XLNT_CLASS worksheet_iterator : public std::iterator +{ +public: + worksheet_iterator(workbook &wb, std::size_t index); + worksheet_iterator(const worksheet_iterator &); + worksheet_iterator &operator=(const worksheet_iterator &); + worksheet operator*(); + bool operator==(const worksheet_iterator &comparand) const; + bool operator!=(const worksheet_iterator &comparand) const + { + return !(*this == comparand); + } + worksheet_iterator operator++(int); + worksheet_iterator &operator++(); + +private: + workbook &wb_; + std::size_t index_; +}; + +} // namespace xlnt diff --git a/include/xlnt/worksheet/cell_iterator.hpp b/include/xlnt/worksheet/cell_iterator.hpp new file mode 100644 index 00000000..d2941e3e --- /dev/null +++ b/include/xlnt/worksheet/cell_iterator.hpp @@ -0,0 +1,70 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include + +namespace xlnt { + +class cell; +class cell_reference; +class range_reference; +enum class major_order; + +class XLNT_CLASS cell_iterator : public std::iterator +{ +public: + cell_iterator(worksheet ws, const cell_reference &start_cell); + + cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order); + + cell_iterator(const cell_iterator &other); + + cell operator*(); + + bool operator==(const cell_iterator &other) const; + + bool operator!=(const cell_iterator &other) const; + + cell_iterator &operator--(); + + cell_iterator operator--(int); + + cell_iterator &operator++(); + + cell_iterator operator++(int); + +private: + worksheet ws_; + cell_reference current_cell_; + range_reference range_; + major_order order_; +}; + +} // namespace xlnt diff --git a/include/xlnt/worksheet/cell_vector.hpp b/include/xlnt/worksheet/cell_vector.hpp index a73d4852..917098d5 100644 --- a/include/xlnt/worksheet/cell_vector.hpp +++ b/include/xlnt/worksheet/cell_vector.hpp @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include #include @@ -33,6 +35,8 @@ namespace xlnt { class cell; +class cell_iterator; +class const_cell_iterator; class range_reference; /// @@ -42,62 +46,9 @@ class range_reference; class XLNT_CLASS cell_vector { public: - class XLNT_CLASS iterator : public std::iterator - { - public: - iterator(worksheet ws, const cell_reference &start_cell, major_order order = major_order::row); - - iterator(const iterator &other); - - cell operator*(); - - bool operator==(const iterator &other) const; - - bool operator!=(const iterator &other) const; - - iterator &operator--(); - - iterator operator--(int); - - iterator &operator++(); - - iterator operator++(int); - - private: - worksheet ws_; - cell_reference current_cell_; - range_reference range_; - major_order order_; - }; - - class XLNT_CLASS const_iterator : public std::iterator - { - public: - const_iterator(worksheet ws, const cell_reference &start_cell, major_order order = major_order::row); - - const_iterator(const const_iterator &other); - - const cell operator*(); - - bool operator==(const const_iterator &other) const; - - bool operator!=(const const_iterator &other) const; - - const_iterator &operator--(); - - const_iterator operator--(int); - - const_iterator &operator++(); - - const_iterator operator++(int); - - private: - worksheet ws_; - cell_reference current_cell_; - range_reference range_; - major_order order_; - }; - + using iterator = cell_iterator; + using const_iterator = const_cell_iterator; + cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row); std::size_t num_cells() const; diff --git a/include/xlnt/worksheet/const_cell_iterator.hpp b/include/xlnt/worksheet/const_cell_iterator.hpp new file mode 100644 index 00000000..b5cebe01 --- /dev/null +++ b/include/xlnt/worksheet/const_cell_iterator.hpp @@ -0,0 +1,70 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include + +namespace xlnt { + +class cell; +class cell_reference; +class range_reference; +enum class major_order; + +class XLNT_CLASS const_cell_iterator : public std::iterator +{ +public: + const_cell_iterator(worksheet ws, const cell_reference &start_cell); + + const_cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order); + + const_cell_iterator(const const_cell_iterator &other); + + const cell operator*(); + + bool operator==(const const_cell_iterator &other) const; + + bool operator!=(const const_cell_iterator &other) const; + + const_cell_iterator &operator--(); + + const_cell_iterator operator--(int); + + const_cell_iterator &operator++(); + + const_cell_iterator operator++(int); + +private: + worksheet ws_; + cell_reference current_cell_; + range_reference range_; + major_order order_; +}; + +} // namespace xlnt diff --git a/include/xlnt/worksheet/range_iterator_2d.hpp b/include/xlnt/worksheet/const_range_iterator.hpp similarity index 55% rename from include/xlnt/worksheet/range_iterator_2d.hpp rename to include/xlnt/worksheet/const_range_iterator.hpp index cbfc7315..aa0b4843 100644 --- a/include/xlnt/worksheet/range_iterator_2d.hpp +++ b/include/xlnt/worksheet/const_range_iterator.hpp @@ -37,62 +37,30 @@ struct worksheet_impl; } /// -/// An iterator used by worksheet and range for traversing -/// a 2D grid of cells by row/column then across that row/column. -/// -class XLNT_CLASS range_iterator_2d : public std::iterator -{ -public: - range_iterator_2d(worksheet &ws, const range_reference &start_cell, major_order order = major_order::row); - - range_iterator_2d(const range_iterator_2d &other); - - cell_vector operator*(); - - bool operator==(const range_iterator_2d &other) const; - - bool operator!=(const range_iterator_2d &other) const; - - range_iterator_2d &operator--(); - - range_iterator_2d operator--(int); - - range_iterator_2d &operator++(); - - range_iterator_2d operator++(int); - -private: - detail::worksheet_impl *ws_; - cell_reference current_cell_; - range_reference range_; - major_order order_; -}; - -/// -/// A const version of range_iterator_2d which does not allow modification +/// A const version of range_iterator which does not allow modification /// to the dereferenced cell_vector. /// -class XLNT_CLASS const_range_iterator_2d : public std::iterator +class XLNT_CLASS const_range_iterator : public std::iterator { public: - const_range_iterator_2d( + const_range_iterator( const worksheet &ws, const range_reference &start_cell, major_order order = major_order::row); - const_range_iterator_2d(const const_range_iterator_2d &other); + const_range_iterator(const const_range_iterator &other); const cell_vector operator*(); - bool operator==(const const_range_iterator_2d &other) const; + bool operator==(const const_range_iterator &other) const; - bool operator!=(const const_range_iterator_2d &other) const; + bool operator!=(const const_range_iterator &other) const; - const_range_iterator_2d &operator--(); + const_range_iterator &operator--(); - const_range_iterator_2d operator--(int); + const_range_iterator operator--(int); - const_range_iterator_2d &operator++(); + const_range_iterator &operator++(); - const_range_iterator_2d operator++(int); + const_range_iterator operator++(int); private: detail::worksheet_impl *ws_; diff --git a/include/xlnt/worksheet/range.hpp b/include/xlnt/worksheet/range.hpp index 11ab34e3..6e6d7709 100644 --- a/include/xlnt/worksheet/range.hpp +++ b/include/xlnt/worksheet/range.hpp @@ -30,20 +30,24 @@ #include #include #include -#include +#include +#include #include #include namespace xlnt { +class const_range_iterator; +class range_iterator; + /// /// A range is a 2D collection of cells with defined extens that can be iterated upon. /// class XLNT_CLASS range { public: - using iterator = range_iterator_2d; - using const_iterator = const_range_iterator_2d; + using iterator = range_iterator; + using const_iterator = const_range_iterator; range(worksheet ws, const range_reference &reference, major_order order = major_order::row, bool skip_null = false); diff --git a/include/xlnt/worksheet/range_iterator.hpp b/include/xlnt/worksheet/range_iterator.hpp new file mode 100644 index 00000000..1b305d23 --- /dev/null +++ b/include/xlnt/worksheet/range_iterator.hpp @@ -0,0 +1,71 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include + +namespace xlnt { + +class cell_vector; +class worksheet; + +namespace detail { +struct worksheet_impl; +} + +/// +/// An iterator used by worksheet and range for traversing +/// a 2D grid of cells by row/column then across that row/column. +/// +class XLNT_CLASS range_iterator : public std::iterator +{ +public: + range_iterator(worksheet &ws, const range_reference &start_cell, major_order order = major_order::row); + + range_iterator(const range_iterator &other); + + cell_vector operator*(); + + bool operator==(const range_iterator &other) const; + + bool operator!=(const range_iterator &other) const; + + range_iterator &operator--(); + + range_iterator operator--(int); + + range_iterator &operator++(); + + range_iterator operator++(int); + +private: + detail::worksheet_impl *ws_; + cell_reference current_cell_; + range_reference range_; + major_order order_; +}; + +} // namespace xlnt diff --git a/include/xlnt/worksheet/worksheet.hpp b/include/xlnt/worksheet/worksheet.hpp index 1a3ab48d..2024cdf4 100644 --- a/include/xlnt/worksheet/worksheet.hpp +++ b/include/xlnt/worksheet/worksheet.hpp @@ -34,7 +34,6 @@ #include #include #include -#include namespace xlnt { @@ -43,7 +42,9 @@ class cell_reference; class cell_vector; class column_properties; class comment; +class const_range_iterator; class range; +class range_iterator; class range_reference; class relationship; class row_properties; @@ -62,8 +63,8 @@ struct worksheet_impl; class XLNT_CLASS worksheet { public: - using iterator = range_iterator_2d; - using const_iterator = const_range_iterator_2d; + using iterator = range_iterator; + using const_iterator = const_range_iterator; worksheet(); worksheet(const worksheet &rhs); @@ -219,8 +220,8 @@ public: private: friend class workbook; friend class cell; - friend class range_iterator_2d; - friend class const_range_iterator_2d; + friend class range_iterator; + friend class const_range_iterator; worksheet(detail::worksheet_impl *d); detail::worksheet_impl *d_; diff --git a/include/xlnt/xlnt.hpp b/include/xlnt/xlnt.hpp index de86422d..e6f85bb3 100644 --- a/include/xlnt/xlnt.hpp +++ b/include/xlnt/xlnt.hpp @@ -43,18 +43,24 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include +#include +#include #include #include #include #include #include +#include #include #include #include diff --git a/source/serialization/excel_serializer.cpp b/source/serialization/excel_serializer.cpp index d284ca00..c701dbaf 100644 --- a/source/serialization/excel_serializer.cpp +++ b/source/serialization/excel_serializer.cpp @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include diff --git a/source/serialization/workbook_serializer.cpp b/source/serialization/workbook_serializer.cpp index 24b3e9bc..36bc316f 100644 --- a/source/serialization/workbook_serializer.cpp +++ b/source/serialization/workbook_serializer.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include diff --git a/source/serialization/worksheet_serializer.cpp b/source/serialization/worksheet_serializer.cpp index 048a38a3..9530837c 100644 --- a/source/serialization/worksheet_serializer.cpp +++ b/source/serialization/worksheet_serializer.cpp @@ -31,8 +31,10 @@ #include #include #include +#include #include #include +#include #include #include diff --git a/source/workbook/const_worksheet_iterator.cpp b/source/workbook/const_worksheet_iterator.cpp new file mode 100644 index 00000000..ae767e0d --- /dev/null +++ b/source/workbook/const_worksheet_iterator.cpp @@ -0,0 +1,61 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include + +namespace xlnt { + +const_worksheet_iterator::const_worksheet_iterator(const workbook &wb, std::size_t index) : wb_(wb), index_(index) +{ +} + +const_worksheet_iterator::const_worksheet_iterator(const const_worksheet_iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_) +{ +} + +const worksheet const_worksheet_iterator::operator*() +{ + return wb_.get_sheet_by_index(index_); +} + +const_worksheet_iterator &const_worksheet_iterator::operator++() +{ + index_++; + return *this; +} + +const_worksheet_iterator const_worksheet_iterator::operator++(int) +{ + const_worksheet_iterator old(wb_, index_); + ++*this; + return old; +} + +bool const_worksheet_iterator::operator==(const const_worksheet_iterator &comparand) const +{ + return index_ == comparand.index_ && wb_ == comparand.wb_; +} + +} // namespace xlnt diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index d3cf012d..4378f8ac 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -42,9 +42,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -91,68 +93,6 @@ workbook::workbook(encoding e) : workbook() d_->encoding_ = e; } -workbook::iterator::iterator(workbook &wb, std::size_t index) : wb_(wb), index_(index) -{ -} - -workbook::iterator::iterator(const iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_) -{ -} - -worksheet workbook::iterator::operator*() -{ - return wb_[index_]; -} - -workbook::iterator &workbook::iterator::operator++() -{ - index_++; - return *this; -} - -workbook::iterator workbook::iterator::operator++(int) -{ - iterator old(wb_, index_); - ++*this; - return old; -} - -bool workbook::iterator::operator==(const iterator &comparand) const -{ - return index_ == comparand.index_ && wb_ == comparand.wb_; -} - -workbook::const_iterator::const_iterator(const workbook &wb, std::size_t index) : wb_(wb), index_(index) -{ -} - -workbook::const_iterator::const_iterator(const const_iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_) -{ -} - -const worksheet workbook::const_iterator::operator*() -{ - return wb_.get_sheet_by_index(index_); -} - -workbook::const_iterator &workbook::const_iterator::operator++() -{ - index_++; - return *this; -} - -workbook::const_iterator workbook::const_iterator::operator++(int) -{ - const_iterator old(wb_, index_); - ++*this; - return old; -} - -bool workbook::const_iterator::operator==(const const_iterator &comparand) const -{ - return index_ == comparand.index_ && wb_ == comparand.wb_; -} - worksheet workbook::get_sheet_by_name(const std::string &name) { for (auto &impl : d_->worksheets_) diff --git a/source/workbook/worksheet_iterator.cpp b/source/workbook/worksheet_iterator.cpp new file mode 100644 index 00000000..e547549a --- /dev/null +++ b/source/workbook/worksheet_iterator.cpp @@ -0,0 +1,61 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include + +namespace xlnt { + +worksheet_iterator::worksheet_iterator(workbook &wb, std::size_t index) : wb_(wb), index_(index) +{ +} + +worksheet_iterator::worksheet_iterator(const worksheet_iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_) +{ +} + +worksheet worksheet_iterator::operator*() +{ + return wb_[index_]; +} + +worksheet_iterator &worksheet_iterator::operator++() +{ + index_++; + return *this; +} + +worksheet_iterator worksheet_iterator::operator++(int) +{ + worksheet_iterator old(wb_, index_); + ++*this; + return old; +} + +bool worksheet_iterator::operator==(const worksheet_iterator &comparand) const +{ + return index_ == comparand.index_ && wb_ == comparand.wb_; +} + +} // namespace xlnt diff --git a/source/worksheet/cell_iterator.cpp b/source/worksheet/cell_iterator.cpp new file mode 100644 index 00000000..fb631bd4 --- /dev/null +++ b/source/worksheet/cell_iterator.cpp @@ -0,0 +1,97 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include +#include + +namespace xlnt { + +cell_iterator::cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order) + : ws_(ws), current_cell_(start_cell), range_(start_cell.to_range()), order_(order) +{ +} + +cell_iterator::cell_iterator(const cell_iterator &other) +{ + *this = other; +} + +bool cell_iterator::operator==(const cell_iterator &other) const +{ + return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; +} + +bool cell_iterator::operator!=(const cell_iterator &other) const +{ + return !(*this == other); +} + +cell_iterator &cell_iterator::operator--() +{ + if (order_ == major_order::row) + { + current_cell_.set_column_index(current_cell_.get_column_index() - 1); + } + else + { + current_cell_.set_row(current_cell_.get_row() - 1); + } + + return *this; +} + +cell_iterator cell_iterator::operator--(int) +{ + cell_iterator old = *this; + --*this; + return old; +} + +cell_iterator &cell_iterator::operator++() +{ + if (order_ == major_order::row) + { + current_cell_.set_column_index(current_cell_.get_column_index() + 1); + } + else + { + current_cell_.set_row(current_cell_.get_row() + 1); + } + + return *this; +} + +cell_iterator cell_iterator::operator++(int) +{ + cell_iterator old = *this; + ++*this; + return old; +} + +cell cell_iterator::operator*() +{ + return ws_[current_cell_]; +} + +} // namespace xlnt diff --git a/source/worksheet/cell_vector.cpp b/source/worksheet/cell_vector.cpp index 5a432373..9d16543e 100644 --- a/source/worksheet/cell_vector.cpp +++ b/source/worksheet/cell_vector.cpp @@ -20,140 +20,13 @@ // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file -#include #include +#include +#include +#include namespace xlnt { -cell_vector::iterator::iterator(worksheet ws, const cell_reference &start_cell, major_order order) - : ws_(ws), current_cell_(start_cell), range_(start_cell.to_range()), order_(order) -{ -} - -cell_vector::iterator::iterator(const iterator &other) -{ - *this = other; -} - -bool cell_vector::iterator::operator==(const iterator &other) const -{ - return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; -} - -bool cell_vector::iterator::operator!=(const iterator &other) const -{ - return !(*this == other); -} - -cell_vector::iterator &cell_vector::iterator::operator--() -{ - if (order_ == major_order::row) - { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); - } - else - { - current_cell_.set_row(current_cell_.get_row() - 1); - } - - return *this; -} - -cell_vector::iterator cell_vector::iterator::operator--(int) -{ - iterator old = *this; - --*this; - return old; -} - -cell_vector::iterator &cell_vector::iterator::operator++() -{ - if (order_ == major_order::row) - { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); - } - else - { - current_cell_.set_row(current_cell_.get_row() + 1); - } - - return *this; -} - -cell_vector::iterator cell_vector::iterator::operator++(int) -{ - iterator old = *this; - ++*this; - return old; -} - -cell_vector::const_iterator::const_iterator(worksheet ws, const cell_reference &start_cell, major_order order) - : ws_(ws), current_cell_(start_cell), range_(start_cell.to_range()), order_(order) -{ -} - -cell_vector::const_iterator::const_iterator(const const_iterator &other) -{ - *this = other; -} - -bool cell_vector::const_iterator::operator==(const const_iterator &other) const -{ - return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; -} - -bool cell_vector::const_iterator::operator!=(const const_iterator &other) const -{ - return !(*this == other); -} - -cell_vector::const_iterator &cell_vector::const_iterator::operator--() -{ - if (order_ == major_order::row) - { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); - } - else - { - current_cell_.set_row(current_cell_.get_row() - 1); - } - - return *this; -} - -cell_vector::const_iterator cell_vector::const_iterator::operator--(int) -{ - const_iterator old = *this; - --*this; - return old; -} - -cell_vector::const_iterator &cell_vector::const_iterator::operator++() -{ - if (order_ == major_order::row) - { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); - } - else - { - current_cell_.set_row(current_cell_.get_row() + 1); - } - - return *this; -} - -cell_vector::const_iterator cell_vector::const_iterator::operator++(int) -{ - const_iterator old = *this; - ++*this; - return old; -} - -cell cell_vector::iterator::operator*() -{ - return ws_[current_cell_]; -} - cell_vector::iterator cell_vector::begin() { return iterator(ws_, ref_.get_top_left(), order_); diff --git a/source/worksheet/const_cell_iterator.cpp b/source/worksheet/const_cell_iterator.cpp new file mode 100644 index 00000000..14b1e9b6 --- /dev/null +++ b/source/worksheet/const_cell_iterator.cpp @@ -0,0 +1,92 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include +#include + +namespace xlnt { + +const_cell_iterator::const_cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order) + : ws_(ws), current_cell_(start_cell), range_(start_cell.to_range()), order_(order) +{ +} + +const_cell_iterator::const_cell_iterator(const const_cell_iterator &other) +{ + *this = other; +} + +bool const_cell_iterator::operator==(const const_cell_iterator &other) const +{ + return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; +} + +bool const_cell_iterator::operator!=(const const_cell_iterator &other) const +{ + return !(*this == other); +} + +const_cell_iterator &const_cell_iterator::operator--() +{ + if (order_ == major_order::row) + { + current_cell_.set_column_index(current_cell_.get_column_index() - 1); + } + else + { + current_cell_.set_row(current_cell_.get_row() - 1); + } + + return *this; +} + +const_cell_iterator const_cell_iterator::operator--(int) +{ + const_cell_iterator old = *this; + --*this; + return old; +} + +const_cell_iterator &const_cell_iterator::operator++() +{ + if (order_ == major_order::row) + { + current_cell_.set_column_index(current_cell_.get_column_index() + 1); + } + else + { + current_cell_.set_row(current_cell_.get_row() + 1); + } + + return *this; +} + +const_cell_iterator const_cell_iterator::operator++(int) +{ + const_cell_iterator old = *this; + ++*this; + return old; +} + +} // namespace xlnt diff --git a/source/worksheet/const_range_iterator.cpp b/source/worksheet/const_range_iterator.cpp new file mode 100644 index 00000000..8a50edc8 --- /dev/null +++ b/source/worksheet/const_range_iterator.cpp @@ -0,0 +1,95 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include +#include +#include + +namespace xlnt { + +const_range_iterator::const_range_iterator(const worksheet &ws, const range_reference &start_cell, major_order order) + : ws_(ws.d_), current_cell_(start_cell.get_top_left()), range_(start_cell), order_(order) +{ +} + +const_range_iterator::const_range_iterator(const const_range_iterator &other) +{ + *this = other; +} + +bool const_range_iterator::operator==(const const_range_iterator &other) const +{ + return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; +} + +bool const_range_iterator::operator!=(const const_range_iterator &other) const +{ + return !(*this == other); +} + +const_range_iterator &const_range_iterator::operator--() +{ + if (order_ == major_order::row) + { + current_cell_.set_row(current_cell_.get_row() - 1); + } + else + { + current_cell_.set_column_index(current_cell_.get_column_index() - 1); + } + + return *this; +} + +const_range_iterator const_range_iterator::operator--(int) +{ + const_range_iterator old = *this; + --*this; + + return old; +} + +const_range_iterator &const_range_iterator::operator++() +{ + if (order_ == major_order::row) + { + current_cell_.set_row(current_cell_.get_row() + 1); + } + else + { + current_cell_.set_column_index(current_cell_.get_column_index() + 1); + } + + return *this; +} + +const_range_iterator const_range_iterator::operator++(int) +{ + const_range_iterator old = *this; + ++*this; + + return old; +} + +} // namespace xlnt diff --git a/source/worksheet/range.cpp b/source/worksheet/range.cpp index 18951b2f..c1e1ac4c 100644 --- a/source/worksheet/range.cpp +++ b/source/worksheet/range.cpp @@ -22,6 +22,8 @@ // @author: see AUTHORS file #include #include +#include +#include #include #include @@ -155,148 +157,6 @@ range::const_iterator range::cend() const return const_iterator(ws_, range_reference(top_right, bottom_right), order_); } -cell_vector range::iterator::operator*() -{ - if (order_ == major_order::row) - { - range_reference reference(range_.get_top_left().get_column_index(), current_cell_.get_row(), - range_.get_bottom_right().get_column_index(), current_cell_.get_row()); - return cell_vector(ws_, reference, order_); - } - - range_reference reference(current_cell_.get_column_index(), range_.get_top_left().get_row(), - current_cell_.get_column_index(), range_.get_bottom_right().get_row()); - return cell_vector(ws_, reference, order_); -} - -range_iterator_2d::range_iterator_2d(worksheet &ws, const range_reference &start_cell, major_order order) - : ws_(ws.d_), current_cell_(start_cell.get_top_left()), range_(start_cell), order_(order) -{ -} - -range_iterator_2d::range_iterator_2d(const range_iterator_2d &other) -{ - *this = other; -} - -bool range_iterator_2d::operator==(const range_iterator_2d &other) const -{ - return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; -} - -bool range_iterator_2d::operator!=(const range_iterator_2d &other) const -{ - return !(*this == other); -} - -range_iterator_2d &range_iterator_2d::operator--() -{ - if (order_ == major_order::row) - { - current_cell_.set_row(current_cell_.get_row() - 1); - } - else - { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); - } - - return *this; -} - -range_iterator_2d range_iterator_2d::operator--(int) -{ - range_iterator_2d old = *this; - --*this; - - return old; -} - -range_iterator_2d &range_iterator_2d::operator++() -{ - if (order_ == major_order::row) - { - current_cell_.set_row(current_cell_.get_row() + 1); - } - else - { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); - } - - return *this; -} - -range_iterator_2d range_iterator_2d::operator++(int) -{ - range_iterator_2d old = *this; - ++*this; - - return old; -} - -const_range_iterator_2d::const_range_iterator_2d(const worksheet &ws, const range_reference &start_cell, major_order order) - : ws_(ws.d_), current_cell_(start_cell.get_top_left()), range_(start_cell), order_(order) -{ -} - -const_range_iterator_2d::const_range_iterator_2d(const const_range_iterator_2d &other) -{ - *this = other; -} - -bool const_range_iterator_2d::operator==(const const_range_iterator_2d &other) const -{ - return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; -} - -bool const_range_iterator_2d::operator!=(const const_range_iterator_2d &other) const -{ - return !(*this == other); -} - -range::const_iterator &range::const_iterator::operator--() -{ - if (order_ == major_order::row) - { - current_cell_.set_row(current_cell_.get_row() - 1); - } - else - { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); - } - - return *this; -} - -range::const_iterator range::const_iterator::operator--(int) -{ - const_range_iterator_2d old = *this; - --*this; - - return old; -} - -range::const_iterator &range::const_iterator::operator++() -{ - if (order_ == major_order::row) - { - current_cell_.set_row(current_cell_.get_row() + 1); - } - else - { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); - } - - return *this; -} - -range::const_iterator range::const_iterator::operator++(int) -{ - const_range_iterator_2d old = *this; - ++*this; - - return old; -} - bool range::operator!=(const range &comparand) const { return !(*this == comparand); diff --git a/source/worksheet/range_iterator.cpp b/source/worksheet/range_iterator.cpp new file mode 100644 index 00000000..e6048003 --- /dev/null +++ b/source/worksheet/range_iterator.cpp @@ -0,0 +1,109 @@ +// Copyright (c) 2014-2016 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, WRISING 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 +#include +#include +#include +#include +#include + +namespace xlnt { + +cell_vector range_iterator::operator*() +{ + if (order_ == major_order::row) + { + range_reference reference(range_.get_top_left().get_column_index(), current_cell_.get_row(), + range_.get_bottom_right().get_column_index(), current_cell_.get_row()); + return cell_vector(ws_, reference, order_); + } + + range_reference reference(current_cell_.get_column_index(), range_.get_top_left().get_row(), + current_cell_.get_column_index(), range_.get_bottom_right().get_row()); + return cell_vector(ws_, reference, order_); +} + +range_iterator::range_iterator(worksheet &ws, const range_reference &start_cell, major_order order) + : ws_(ws.d_), current_cell_(start_cell.get_top_left()), range_(start_cell), order_(order) +{ +} + +range_iterator::range_iterator(const range_iterator &other) +{ + *this = other; +} + +bool range_iterator::operator==(const range_iterator &other) const +{ + return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; +} + +bool range_iterator::operator!=(const range_iterator &other) const +{ + return !(*this == other); +} + +range_iterator &range_iterator::operator--() +{ + if (order_ == major_order::row) + { + current_cell_.set_row(current_cell_.get_row() - 1); + } + else + { + current_cell_.set_column_index(current_cell_.get_column_index() - 1); + } + + return *this; +} + +range_iterator range_iterator::operator--(int) +{ + range_iterator old = *this; + --*this; + + return old; +} + +range_iterator &range_iterator::operator++() +{ + if (order_ == major_order::row) + { + current_cell_.set_row(current_cell_.get_row() + 1); + } + else + { + current_cell_.set_column_index(current_cell_.get_column_index() + 1); + } + + return *this; +} + +range_iterator range_iterator::operator++(int) +{ + range_iterator old = *this; + ++*this; + + return old; +} + +} // namespace xlnt diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index 90c85aef..2eb9b216 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -33,7 +33,11 @@ #include #include #include +#include +#include +#include #include +#include #include #include