clean up iterators

This commit is contained in:
Thomas Fussell 2016-01-24 11:15:49 -05:00
parent 34aa24bdd6
commit 74bfdb6f7d
24 changed files with 895 additions and 480 deletions

View File

@ -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 <cstddef>
#include <iterator>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
class workbook;
class worksheet;
class XLNT_CLASS const_worksheet_iterator : public std::iterator<std::bidirectional_iterator_tag, const worksheet>
{
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

View File

@ -37,6 +37,7 @@ namespace xlnt {
class alignment; class alignment;
class border; class border;
class color; class color;
class const_worksheet_iterator;
class document_properties; class document_properties;
class drawing; class drawing;
class fill; class fill;
@ -52,6 +53,7 @@ class relationship;
class style; class style;
class theme; class theme;
class worksheet; class worksheet;
class worksheet_iterator;
class zip_file; class zip_file;
enum class encoding; enum class encoding;
@ -66,46 +68,9 @@ struct workbook_impl;
class XLNT_CLASS workbook class XLNT_CLASS workbook
{ {
public: public:
class XLNT_CLASS iterator using iterator = worksheet_iterator;
{ using const_iterator = const_worksheet_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_;
};
static std::size_t index_from_ws_filename(const std::string &filename); static std::size_t index_from_ws_filename(const std::string &filename);
// constructors // constructors

View File

@ -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 <cstddef>
#include <iterator>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
class workbook;
class worksheet;
class XLNT_CLASS worksheet_iterator : public std::iterator<std::bidirectional_iterator_tag, worksheet>
{
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

View File

@ -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 <iterator>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/cell_reference.hpp>
#include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp>
namespace xlnt {
class cell;
class cell_reference;
class range_reference;
enum class major_order;
class XLNT_CLASS cell_iterator : public std::iterator<std::bidirectional_iterator_tag, cell>
{
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

View File

@ -26,6 +26,8 @@
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/cell_reference.hpp> #include <xlnt/cell/cell_reference.hpp>
#include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
#include <xlnt/worksheet/major_order.hpp> #include <xlnt/worksheet/major_order.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
@ -33,6 +35,8 @@
namespace xlnt { namespace xlnt {
class cell; class cell;
class cell_iterator;
class const_cell_iterator;
class range_reference; class range_reference;
/// <summary> /// <summary>
@ -42,62 +46,9 @@ class range_reference;
class XLNT_CLASS cell_vector class XLNT_CLASS cell_vector
{ {
public: public:
class XLNT_CLASS iterator : public std::iterator<std::bidirectional_iterator_tag, cell> using iterator = cell_iterator;
{ using const_iterator = const_cell_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<std::bidirectional_iterator_tag, const cell>
{
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_;
};
cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row); cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row);
std::size_t num_cells() const; std::size_t num_cells() const;

View File

@ -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 <iterator>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/cell_reference.hpp>
#include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp>
namespace xlnt {
class cell;
class cell_reference;
class range_reference;
enum class major_order;
class XLNT_CLASS const_cell_iterator : public std::iterator<std::bidirectional_iterator_tag, const cell>
{
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

View File

@ -37,62 +37,30 @@ struct worksheet_impl;
} }
/// <summary> /// <summary>
/// An iterator used by worksheet and range for traversing /// A const version of range_iterator which does not allow modification
/// a 2D grid of cells by row/column then across that row/column.
/// </summary>
class XLNT_CLASS range_iterator_2d : public std::iterator<std::bidirectional_iterator_tag, cell_vector>
{
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_;
};
/// <summary>
/// A const version of range_iterator_2d which does not allow modification
/// to the dereferenced cell_vector. /// to the dereferenced cell_vector.
/// </summary> /// </summary>
class XLNT_CLASS const_range_iterator_2d : public std::iterator<std::bidirectional_iterator_tag, const cell_vector> class XLNT_CLASS const_range_iterator : public std::iterator<std::bidirectional_iterator_tag, const cell_vector>
{ {
public: public:
const_range_iterator_2d( const_range_iterator(
const worksheet &ws, const range_reference &start_cell, major_order order = major_order::row); 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*(); 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: private:
detail::worksheet_impl *ws_; detail::worksheet_impl *ws_;

View File

@ -30,20 +30,24 @@
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/worksheet/cell_vector.hpp> #include <xlnt/worksheet/cell_vector.hpp>
#include <xlnt/worksheet/major_order.hpp> #include <xlnt/worksheet/major_order.hpp>
#include <xlnt/worksheet/range_iterator_2d.hpp> #include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
namespace xlnt { namespace xlnt {
class const_range_iterator;
class range_iterator;
/// <summary> /// <summary>
/// A range is a 2D collection of cells with defined extens that can be iterated upon. /// A range is a 2D collection of cells with defined extens that can be iterated upon.
/// </summary> /// </summary>
class XLNT_CLASS range class XLNT_CLASS range
{ {
public: public:
using iterator = range_iterator_2d; using iterator = range_iterator;
using const_iterator = const_range_iterator_2d; using const_iterator = const_range_iterator;
range(worksheet ws, const range_reference &reference, major_order order = major_order::row, bool skip_null = false); range(worksheet ws, const range_reference &reference, major_order order = major_order::row, bool skip_null = false);

View File

@ -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 <xlnt/xlnt_config.hpp>
#include <xlnt/cell/cell_reference.hpp>
#include <xlnt/worksheet/major_order.hpp>
#include <xlnt/worksheet/range_reference.hpp>
namespace xlnt {
class cell_vector;
class worksheet;
namespace detail {
struct worksheet_impl;
}
/// <summary>
/// An iterator used by worksheet and range for traversing
/// a 2D grid of cells by row/column then across that row/column.
/// </summary>
class XLNT_CLASS range_iterator : public std::iterator<std::bidirectional_iterator_tag, cell_vector>
{
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

View File

@ -34,7 +34,6 @@
#include <xlnt/worksheet/header_footer.hpp> #include <xlnt/worksheet/header_footer.hpp>
#include <xlnt/worksheet/page_margins.hpp> #include <xlnt/worksheet/page_margins.hpp>
#include <xlnt/worksheet/page_setup.hpp> #include <xlnt/worksheet/page_setup.hpp>
#include <xlnt/worksheet/range_iterator_2d.hpp>
namespace xlnt { namespace xlnt {
@ -43,7 +42,9 @@ class cell_reference;
class cell_vector; class cell_vector;
class column_properties; class column_properties;
class comment; class comment;
class const_range_iterator;
class range; class range;
class range_iterator;
class range_reference; class range_reference;
class relationship; class relationship;
class row_properties; class row_properties;
@ -62,8 +63,8 @@ struct worksheet_impl;
class XLNT_CLASS worksheet class XLNT_CLASS worksheet
{ {
public: public:
using iterator = range_iterator_2d; using iterator = range_iterator;
using const_iterator = const_range_iterator_2d; using const_iterator = const_range_iterator;
worksheet(); worksheet();
worksheet(const worksheet &rhs); worksheet(const worksheet &rhs);
@ -219,8 +220,8 @@ public:
private: private:
friend class workbook; friend class workbook;
friend class cell; friend class cell;
friend class range_iterator_2d; friend class range_iterator;
friend class const_range_iterator_2d; friend class const_range_iterator;
worksheet(detail::worksheet_impl *d); worksheet(detail::worksheet_impl *d);
detail::worksheet_impl *d_; detail::worksheet_impl *d_;

View File

@ -43,18 +43,24 @@
#include <xlnt/styles/style.hpp> #include <xlnt/styles/style.hpp>
#include <xlnt/utils/datetime.hpp> #include <xlnt/utils/datetime.hpp>
#include <xlnt/utils/exceptions.hpp> #include <xlnt/utils/exceptions.hpp>
#include <xlnt/workbook/const_worksheet_iterator.hpp>
#include <xlnt/workbook/document_security.hpp> #include <xlnt/workbook/document_security.hpp>
#include <xlnt/workbook/external_book.hpp> #include <xlnt/workbook/external_book.hpp>
#include <xlnt/workbook/named_range.hpp> #include <xlnt/workbook/named_range.hpp>
#include <xlnt/workbook/theme.hpp> #include <xlnt/workbook/theme.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/worksheet_iterator.hpp>
#include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/cell_vector.hpp> #include <xlnt/worksheet/cell_vector.hpp>
#include <xlnt/worksheet/column_properties.hpp> #include <xlnt/worksheet/column_properties.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/major_order.hpp> #include <xlnt/worksheet/major_order.hpp>
#include <xlnt/worksheet/page_margins.hpp> #include <xlnt/worksheet/page_margins.hpp>
#include <xlnt/worksheet/page_setup.hpp> #include <xlnt/worksheet/page_setup.hpp>
#include <xlnt/worksheet/pane.hpp> #include <xlnt/worksheet/pane.hpp>
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/row_properties.hpp> #include <xlnt/worksheet/row_properties.hpp>
#include <xlnt/worksheet/selection.hpp> #include <xlnt/worksheet/selection.hpp>

View File

@ -39,6 +39,8 @@
#include <xlnt/packaging/manifest.hpp> #include <xlnt/packaging/manifest.hpp>
#include <xlnt/utils/exceptions.hpp> #include <xlnt/utils/exceptions.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/worksheet_iterator.hpp>
#include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
#include <detail/constants.hpp> #include <detail/constants.hpp>

View File

@ -33,6 +33,7 @@
#include <xlnt/utils/exceptions.hpp> #include <xlnt/utils/exceptions.hpp>
#include <xlnt/workbook/named_range.hpp> #include <xlnt/workbook/named_range.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/worksheet_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>

View File

@ -31,8 +31,10 @@
#include <xlnt/serialization/xml_document.hpp> #include <xlnt/serialization/xml_document.hpp>
#include <xlnt/serialization/xml_node.hpp> #include <xlnt/serialization/xml_node.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/column_properties.hpp> #include <xlnt/worksheet/column_properties.hpp>
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/row_properties.hpp> #include <xlnt/worksheet/row_properties.hpp>

View File

@ -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 <xlnt/workbook/const_worksheet_iterator.hpp>
#include <xlnt/workbook/workbook.hpp>
#include <xlnt/worksheet/worksheet.hpp>
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

View File

@ -42,9 +42,11 @@
#include <xlnt/styles/protection.hpp> #include <xlnt/styles/protection.hpp>
#include <xlnt/styles/style.hpp> #include <xlnt/styles/style.hpp>
#include <xlnt/utils/exceptions.hpp> #include <xlnt/utils/exceptions.hpp>
#include <xlnt/workbook/const_worksheet_iterator.hpp>
#include <xlnt/workbook/named_range.hpp> #include <xlnt/workbook/named_range.hpp>
#include <xlnt/workbook/theme.hpp> #include <xlnt/workbook/theme.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/worksheet_iterator.hpp>
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
@ -91,68 +93,6 @@ workbook::workbook(encoding e) : workbook()
d_->encoding_ = e; 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) worksheet workbook::get_sheet_by_name(const std::string &name)
{ {
for (auto &impl : d_->worksheets_) for (auto &impl : d_->worksheets_)

View File

@ -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 <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/worksheet_iterator.hpp>
#include <xlnt/worksheet/worksheet.hpp>
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

View File

@ -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 <xlnt/cell/cell.hpp>
#include <xlnt/cell/cell_reference.hpp>
#include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/major_order.hpp>
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

View File

@ -20,140 +20,13 @@
// //
// @license: http://www.opensource.org/licenses/mit-license.php // @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file // @author: see AUTHORS file
#include <xlnt/worksheet/cell_vector.hpp>
#include <xlnt/cell/cell.hpp> #include <xlnt/cell/cell.hpp>
#include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/cell_vector.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
namespace xlnt { 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() cell_vector::iterator cell_vector::begin()
{ {
return iterator(ws_, ref_.get_top_left(), order_); return iterator(ws_, ref_.get_top_left(), order_);

View File

@ -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 <xlnt/cell/cell.hpp>
#include <xlnt/cell/cell_reference.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
#include <xlnt/worksheet/major_order.hpp>
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

View File

@ -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 <xlnt/worksheet/range.hpp>
#include <xlnt/cell/cell.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp>
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

View File

@ -22,6 +22,8 @@
// @author: see AUTHORS file // @author: see AUTHORS file
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/cell/cell.hpp> #include <xlnt/cell/cell.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
@ -155,148 +157,6 @@ range::const_iterator range::cend() const
return const_iterator(ws_, range_reference(top_right, bottom_right), order_); 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 bool range::operator!=(const range &comparand) const
{ {
return !(*this == comparand); return !(*this == comparand);

View File

@ -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 <xlnt/worksheet/range.hpp>
#include <xlnt/cell/cell.hpp>
#include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp>
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

View File

@ -33,7 +33,11 @@
#include <xlnt/utils/exceptions.hpp> #include <xlnt/utils/exceptions.hpp>
#include <xlnt/workbook/named_range.hpp> #include <xlnt/workbook/named_range.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>