mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Merge pull request #324 from Crzyrndm/iterator-default-ctors
Default ctors for iterators
This commit is contained in:
commit
ca8c93c696
|
@ -53,6 +53,11 @@ public:
|
|||
using pointer = worksheet *;
|
||||
using reference = worksheet; // intentionally value
|
||||
|
||||
/// <summary>
|
||||
/// Default Constructs a worksheet iterator
|
||||
/// </summary>
|
||||
worksheet_iterator() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a worksheet iterator from a workbook and sheet index.
|
||||
/// </summary>
|
||||
|
@ -135,12 +140,12 @@ private:
|
|||
/// <summary>
|
||||
/// The target workbook of this iterator.
|
||||
/// </summary>
|
||||
workbook *wb_;
|
||||
workbook *wb_ = nullptr;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the worksheet in wb_ this iterator is currently pointing to.
|
||||
/// </summary>
|
||||
std::size_t index_;
|
||||
std::size_t index_ = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -159,6 +164,11 @@ public:
|
|||
using pointer = const worksheet *;
|
||||
using reference = const worksheet; // intentionally value
|
||||
|
||||
/// <summary>
|
||||
/// Default Constructs a worksheet iterator
|
||||
/// </summary>
|
||||
const_worksheet_iterator() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a worksheet iterator from a workbook and sheet index.
|
||||
/// </summary>
|
||||
|
@ -234,12 +244,12 @@ private:
|
|||
/// <summary>
|
||||
/// The target workbook of this iterator.
|
||||
/// </summary>
|
||||
const workbook *wb_;
|
||||
const workbook *wb_ = nullptr;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the worksheet in wb_ this iterator is currently pointing to.
|
||||
/// </summary>
|
||||
std::size_t index_;
|
||||
std::size_t index_ = 0;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <xlnt/xlnt_config.hpp>
|
||||
#include <xlnt/cell/cell_reference.hpp>
|
||||
#include <xlnt/worksheet/range_reference.hpp>
|
||||
#include <xlnt/worksheet/major_order.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
@ -55,6 +56,11 @@ public:
|
|||
using pointer = cell *;
|
||||
using reference = cell; // intentionally value
|
||||
|
||||
/// <summary>
|
||||
/// Default constructs a cell_iterator
|
||||
/// </summary>
|
||||
cell_iterator() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a cell_iterator from a worksheet, range, and iteration settings.
|
||||
/// </summary>
|
||||
|
@ -132,6 +138,27 @@ public:
|
|||
cell_iterator operator++(int);
|
||||
|
||||
private:
|
||||
|
||||
/// <summary>
|
||||
/// If true, cells that don't exist in the worksheet will be skipped during iteration.
|
||||
/// </summary>
|
||||
bool skip_null_ = false;
|
||||
|
||||
/// <summary>
|
||||
/// If true, when on the last column, the cursor will continue to the next row
|
||||
/// (and vice versa when iterating in column-major order) until reaching the
|
||||
/// bottom right corner of the range.
|
||||
/// </summary>
|
||||
bool wrap_ = false;
|
||||
|
||||
/// <summary>
|
||||
/// The order this iterator will move, by column or by row. Note that
|
||||
/// this has the opposite meaning as in a range_iterator because after
|
||||
/// getting a row-major range_iterator, the row-major cell_iterator will
|
||||
/// iterate over a column and vice versa.
|
||||
/// </summary>
|
||||
major_order order_ = major_order::column;
|
||||
|
||||
/// <summary>
|
||||
/// The worksheet this iterator will return cells from.
|
||||
/// </summary>
|
||||
|
@ -146,26 +173,6 @@ private:
|
|||
/// The range of cells this iterator is restricted to
|
||||
/// </summary>
|
||||
range_reference bounds_;
|
||||
|
||||
/// <summary>
|
||||
/// The order this iterator will move, by column or by row. Note that
|
||||
/// this has the opposite meaning as in a range_iterator because after
|
||||
/// getting a row-major range_iterator, the row-major cell_iterator will
|
||||
/// iterate over a column and vice versa.
|
||||
/// </summary>
|
||||
major_order order_;
|
||||
|
||||
/// <summary>
|
||||
/// If true, cells that don't exist in the worksheet will be skipped during iteration.
|
||||
/// </summary>
|
||||
bool skip_null_;
|
||||
|
||||
/// <summary>
|
||||
/// If true, when on the last column, the cursor will continue to the next row
|
||||
/// (and vice versa when iterating in column-major order) until reaching the
|
||||
/// bottom right corner of the range.
|
||||
/// </summary>
|
||||
bool wrap_;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
@ -183,6 +190,11 @@ public:
|
|||
using pointer = const cell *;
|
||||
using reference = const cell; // intentionally value
|
||||
|
||||
/// <summary>
|
||||
/// Default constructs a cell_iterator
|
||||
/// </summary>
|
||||
const_cell_iterator() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a cell_iterator from a worksheet, range, and iteration settings.
|
||||
/// </summary>
|
||||
|
@ -254,6 +266,26 @@ public:
|
|||
const_cell_iterator operator++(int);
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
/// If true, cells that don't exist in the worksheet will be skipped during iteration.
|
||||
/// </summary>
|
||||
bool skip_null_ = false;
|
||||
|
||||
/// <summary>
|
||||
/// If true, when on the last column, the cursor will continue to the next row
|
||||
/// (and vice versa when iterating in column-major order) until reaching the
|
||||
/// bottom right corner of the range.
|
||||
/// </summary>
|
||||
bool wrap_ = false;
|
||||
|
||||
/// <summary>
|
||||
/// The order this iterator will move, by column or by row. Note that
|
||||
/// this has the opposite meaning as in a range_iterator because after
|
||||
/// getting a row-major range_iterator, the row-major cell_iterator will
|
||||
/// iterate over a column and vice versa.
|
||||
/// </summary>
|
||||
major_order order_ = major_order::column;
|
||||
|
||||
/// <summary>
|
||||
/// The worksheet this iterator will return cells from.
|
||||
/// </summary>
|
||||
|
@ -268,26 +300,6 @@ private:
|
|||
/// The range of cells this iterator is restricted to
|
||||
/// </summary>
|
||||
range_reference bounds_;
|
||||
|
||||
/// <summary>
|
||||
/// The order this iterator will move, by column or by row. Note that
|
||||
/// this has the opposite meaning as in a range_iterator because after
|
||||
/// getting a row-major range_iterator, the row-major cell_iterator will
|
||||
/// iterate over a column and vice versa.
|
||||
/// </summary>
|
||||
major_order order_;
|
||||
|
||||
/// <summary>
|
||||
/// If true, cells that don't exist in the worksheet will be skipped during iteration.
|
||||
/// </summary>
|
||||
bool skip_null_;
|
||||
|
||||
/// <summary>
|
||||
/// If true, when on the last column, the cursor will continue to the next row
|
||||
/// (and vice versa when iterating in column-major order) until reaching the
|
||||
/// bottom right corner of the range.
|
||||
/// </summary>
|
||||
bool wrap_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -51,6 +51,11 @@ public:
|
|||
using pointer = cell_vector *;
|
||||
using reference = cell_vector; // intentionally value
|
||||
|
||||
/// <summary>
|
||||
/// Default constructs a range iterator
|
||||
/// </summary>
|
||||
range_iterator() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a range iterator on a worksheet, cell pointing to the current
|
||||
/// row or column, range bounds, an order, and whether or not to skip null column/rows.
|
||||
|
@ -124,6 +129,16 @@ public:
|
|||
range_iterator operator++(int);
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
/// If true, empty rows and cells will be skipped when iterating with this iterator
|
||||
/// </summary>
|
||||
bool skip_null_ = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether rows or columns should be iterated over first
|
||||
/// </summary>
|
||||
major_order order_ = major_order::column;
|
||||
|
||||
/// <summary>
|
||||
/// The worksheet
|
||||
/// </summary>
|
||||
|
@ -138,16 +153,6 @@ private:
|
|||
/// The bounds of the range
|
||||
/// </summary>
|
||||
range_reference bounds_;
|
||||
|
||||
/// <summary>
|
||||
/// Whether rows or columns should be iterated over first
|
||||
/// </summary>
|
||||
major_order order_;
|
||||
|
||||
/// <summary>
|
||||
/// If true, empty rows and cells will be skipped when iterating with this iterator
|
||||
/// </summary>
|
||||
bool skip_null_;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
@ -166,6 +171,11 @@ public:
|
|||
using pointer = const cell_vector *;
|
||||
using reference = const cell_vector; // intentionally value
|
||||
|
||||
/// <summary>
|
||||
/// Default constructs a range iterator
|
||||
/// </summary>
|
||||
const_range_iterator() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a range iterator on a worksheet, cell pointing to the current
|
||||
/// row or column, range bounds, an order, and whether or not to skip null column/rows.
|
||||
|
@ -234,6 +244,16 @@ public:
|
|||
const_range_iterator operator++(int);
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
/// If true, empty rows and cells will be skipped when iterating with this iterator
|
||||
/// </summary>
|
||||
bool skip_null_ = false;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether iteration should move through rows or columns first
|
||||
/// </summary>
|
||||
major_order order_ = major_order::column;
|
||||
|
||||
/// <summary>
|
||||
/// The implementation of the worksheet this iterator points to
|
||||
/// </summary>
|
||||
|
@ -248,16 +268,6 @@ private:
|
|||
/// The range this iterator starts and ends in
|
||||
/// </summary>
|
||||
range_reference bounds_;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether iteration should move through rows or columns first
|
||||
/// </summary>
|
||||
major_order order_;
|
||||
|
||||
/// <summary>
|
||||
/// If true, empty rows and cells will be skipped when iterating with this iterator
|
||||
/// </summary>
|
||||
bool skip_null_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -30,12 +30,12 @@ namespace xlnt {
|
|||
|
||||
cell_iterator::cell_iterator(worksheet ws, const cell_reference &cursor,
|
||||
const range_reference &bounds, major_order order, bool skip_null, bool wrap)
|
||||
: ws_(ws),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds),
|
||||
: skip_null_(skip_null),
|
||||
wrap_(wrap),
|
||||
order_(order),
|
||||
skip_null_(skip_null),
|
||||
wrap_(wrap)
|
||||
ws_(ws),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds)
|
||||
{
|
||||
if (skip_null && !ws.has_cell(cursor_))
|
||||
{
|
||||
|
@ -45,12 +45,12 @@ cell_iterator::cell_iterator(worksheet ws, const cell_reference &cursor,
|
|||
|
||||
const_cell_iterator::const_cell_iterator(worksheet ws, const cell_reference &cursor,
|
||||
const range_reference &bounds, major_order order, bool skip_null, bool wrap)
|
||||
: ws_(ws),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds),
|
||||
: skip_null_(skip_null),
|
||||
wrap_(wrap),
|
||||
order_(order),
|
||||
skip_null_(skip_null),
|
||||
wrap_(wrap)
|
||||
ws_(ws),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds)
|
||||
{
|
||||
if (skip_null && !ws.has_cell(cursor_))
|
||||
{
|
||||
|
|
|
@ -40,11 +40,11 @@ const range_iterator::reference range_iterator::operator*() const
|
|||
|
||||
range_iterator::range_iterator(worksheet &ws, const cell_reference &cursor,
|
||||
const range_reference &bounds, major_order order, bool skip_null)
|
||||
: ws_(ws),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds),
|
||||
: skip_null_(skip_null),
|
||||
order_(order),
|
||||
skip_null_(skip_null)
|
||||
ws_(ws),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds)
|
||||
{
|
||||
if (skip_null_ && (**this).empty())
|
||||
{
|
||||
|
@ -156,11 +156,11 @@ range_iterator range_iterator::operator++(int)
|
|||
|
||||
const_range_iterator::const_range_iterator(const worksheet &ws, const cell_reference &cursor,
|
||||
const range_reference &bounds, major_order order, bool skip_null)
|
||||
: ws_(ws.d_),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds),
|
||||
: skip_null_(skip_null),
|
||||
order_(order),
|
||||
skip_null_(skip_null)
|
||||
ws_(ws.d_),
|
||||
cursor_(cursor),
|
||||
bounds_(bounds)
|
||||
{
|
||||
if (skip_null_ && (**this).empty())
|
||||
{
|
||||
|
|
|
@ -214,6 +214,8 @@ public:
|
|||
iter = temp--;
|
||||
xlnt_assert_equals((*iter).title(), "Sheet2");
|
||||
xlnt_assert_equals((*temp).title(), "Sheet1");
|
||||
|
||||
xlnt_assert_equals(xlnt::worksheet_iterator{}, xlnt::worksheet_iterator{});
|
||||
}
|
||||
|
||||
void test_const_iter()
|
||||
|
@ -255,6 +257,8 @@ public:
|
|||
iter = temp--;
|
||||
xlnt_assert_equals((*iter).title(), "Sheet2");
|
||||
xlnt_assert_equals((*temp).title(), "Sheet1");
|
||||
|
||||
xlnt_assert_equals(xlnt::const_worksheet_iterator{}, xlnt::const_worksheet_iterator{});
|
||||
}
|
||||
|
||||
void test_get_index()
|
||||
|
|
|
@ -27,10 +27,9 @@
|
|||
#include <xlnt/cell/hyperlink.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/worksheet/column_properties.hpp>
|
||||
#include <xlnt/worksheet/row_properties.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/row_properties.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
|
@ -608,6 +607,9 @@ public:
|
|||
xlnt_assert_equals(cell.value<std::string>(), cell.reference().to_string());
|
||||
}
|
||||
}
|
||||
|
||||
xlnt_assert_equals(xlnt::const_cell_iterator{}, xlnt::const_cell_iterator{});
|
||||
xlnt_assert_equals(xlnt::const_range_iterator{}, xlnt::const_range_iterator{});
|
||||
}
|
||||
|
||||
void test_const_reverse_iterators()
|
||||
|
@ -1052,6 +1054,9 @@ public:
|
|||
const_range_iter++;
|
||||
const_range_iter--;
|
||||
xlnt_assert_equals(const_range_iter, const_range.begin());
|
||||
|
||||
xlnt_assert_equals(xlnt::cell_iterator{}, xlnt::cell_iterator{});
|
||||
xlnt_assert_equals(xlnt::range_iterator{}, xlnt::range_iterator{});
|
||||
}
|
||||
|
||||
void test_range_reference()
|
||||
|
|
Loading…
Reference in New Issue
Block a user