26 #include <type_traits> 33 #include "Portability.h" 35 #include "SerializationFwd.h" 39 #ifndef DOXYGEN_SHOULD_SKIP_THIS 102 std::swap(m_size, other.m_size);
145 return pos.col < m_size.col && pos.row < m_size.row && (std::is_unsigned<I>::value || (0 <= pos.col && 0 <= pos.row));
155 return {
static_cast<I>(index % m_size.col), static_cast<I>(index / m_size.col) };
165 return pos.row * m_size.col + pos.col;
181 return { 0,
static_cast<std::size_t
>(m_size.col) * static_cast<std::size_t>(m_size.row) };
190 return { 0, m_size.row };
199 return { 0, m_size.col };
208 return { getColRange(), getRowRange() };
218 return getNeighborSquareRange(pos, 1);
228 return getNeighborSquareRange(pos, 2);
238 return getNeighborDiamondRange(pos, 1);
248 return getNeighborDiamondRange(pos, 2);
255 assert(isValid(pos));
257 auto colMin = pos.col - std::min(pos.col, n);
258 auto colMax = pos.col + std::min(m_size.col - pos.col - 1, n);
259 auto rowMin = pos.row - std::min(pos.row, n);
260 auto rowMax = pos.row + std::min(m_size.row - pos.row - 1, n);
266 assert(isValid(pos));
268 auto colMin = pos.col - std::min(pos.col, n);
269 auto colMax = pos.col + std::min(m_size.col - pos.col - 1, n);
270 auto rowMin = pos.row - std::min(pos.row, n);
271 auto rowMax = pos.row + std::min(m_size.row - pos.row - 1, n);
307 template<
typename T,
typename I =
unsigned>
328 , m_data(static_cast<
std::size_t>(size.width) * static_cast<
std::size_t>(size.height))
341 , m_data(static_cast<
std::size_t>(size.width) * static_cast<
std::size_t>(size.height), value)
373 std::swap(m_data, other.m_data);
403 return m_data.data();
412 return m_data.size();
424 return m_data.empty();
450 return m_data[index];
469 return m_data[index];
487 return m_data.data();
496 const T *
end() const noexcept {
497 return m_data.data() + m_data.size();
507 return m_data.data();
517 return m_data.data() + m_data.size();
524 return m_data[toIndex(pos)];
528 return m_data[toIndex(pos)];
532 std::vector<T> m_data;
539 template<
typename T,
typename I>
544 if (lhsSize.width != rhsSize.width || lhsSize.height != rhsSize.height) {
555 template<
typename T,
typename I>
558 ar | size.width | size.height;
560 for (
auto& item : array) {
571 template<
typename T,
typename I>
574 ar | size.width | size.height;
578 for (
auto& item : tmp) {
582 array = std::move(tmp);
587 #ifndef DOXYGEN_SHOULD_SKIP_THIS A deserializer from a binary file.
Definition: Serialization.h:153
constexpr bool isValid(Vector< I, 2 > pos) const noexcept
Check if a position is valid.
Definition: Array2D.h:144
constexpr Vector< I, 2 > toPosition(std::size_t index) const noexcept
Transform a 1D position into a 2D position.
Definition: Array2D.h:154
A two-dimensional array.
Definition: Array2D.h:308
Serializer & operator|(Serializer &ar, const Array2D< T, I > &array)
Serialize a 2D array.
Definition: Array2D.h:556
constexpr Range< I > getRowRange() const noexcept
Get the row range.
Definition: Array2D.h:189
A half-open range of values.
Definition: Range.h:43
T * end() noexcept
Get an iterator to the element following the last element of the array.
Definition: Array2D.h:516
Index2D()
Default constructor.
Definition: Array2D.h:59
A two-dimensional array with no data.
Definition: Array2D.h:52
Deserializer & operator|(Deserializer &ar, Array2D< T, I > &array)
Deserialize a 2D array.
Definition: Array2D.h:572
NeighborDiamondRange< I > get4NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 4 neighbors (at most)
Definition: Array2D.h:237
const T * begin() const noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:486
const T * getDataPtr() const noexcept
Get the pointer to raw data.
Definition: Array2D.h:402
constexpr Range< I > getColRange() const noexcept
Get the column range.
Definition: Array2D.h:198
std::size_t getDataSize() const noexcept
Get the raw data size.
Definition: Array2D.h:411
A 2D range.
Definition: Range.h:429
void swap(Array2D &other)
Swap with another array.
Definition: Array2D.h:371
constexpr Vector< I, 2 > getSize() const noexcept
Get the size of the array.
Definition: Array2D.h:115
NeighborSquareRange< I > get24NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 24 neighbors (at most)
Definition: Array2D.h:227
constexpr RangeZ getIndexRange() const noexcept
Get the 1D index range of the array.
Definition: Array2D.h:180
A serializer to a binary file.
Definition: Serialization.h:45
The namespace for gf classes.
Definition: Action.h:35
Array2D()
Default constructor.
Definition: Array2D.h:315
Array2D(Vector< I, 2 > size)
Constructor with a size.
Definition: Array2D.h:326
T & operator()(Vector< I, 2 > pos)
Get the element at a given 2D position.
Definition: Array2D.h:439
const T & operator()(std::size_t index) const
Get the element at a given 1D index.
Definition: Array2D.h:468
A 2D range.
Definition: Range.h:599
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Array2D.h:423
NeighborSquareRange< I > get8NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 8 neighbors (at most)
Definition: Array2D.h:217
constexpr std::size_t toIndex(Vector< I, 2 > pos) const noexcept
Transform a 2D position into a 1D position.
Definition: Array2D.h:164
A 2D range.
Definition: Range.h:280
T * begin() noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:506
Array2D(Vector< I, 2 > size, const T &value)
Constructor with a size and a value.
Definition: Array2D.h:339
NeighborDiamondRange< I > get12NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 12 neighbors (at most)
Definition: Array2D.h:247
constexpr PositionRange< I > getPositionRange() const noexcept
Get the position range.
Definition: Array2D.h:207
bool operator==(const Array2D< T, I > &lhs, const Array2D< T, I > &rhs)
Equality operator for 2D array.
Definition: Array2D.h:540
constexpr I getRows() const noexcept
Get the number of rows.
Definition: Array2D.h:133
T & operator()(std::size_t index)
Get the element at a given 1D index.
Definition: Array2D.h:449
const T & operator()(Vector< I, 2 > pos) const
Get the element at a given 2D position.
Definition: Array2D.h:458
Index2D(Vector< I, 2 > size)
Constructor with a size.
Definition: Array2D.h:70
void swap(Index2D &other)
Swap with another array.
Definition: Array2D.h:101
constexpr I getCols() const noexcept
Get the number of columns.
Definition: Array2D.h:124
const T * end() const noexcept
Get an iterator to the element following the last element of the array.
Definition: Array2D.h:496