26 #include <type_traits> 33 #include "Portability.h" 35 #include "SerializationFwd.h" 39 #ifndef DOXYGEN_SHOULD_SKIP_THIS 100 std::swap(m_size, other.m_size);
143 return pos.col < m_size.col && pos.row < m_size.row && (std::is_unsigned<I>::value || (0 <= pos.col && 0 <= pos.row));
153 return {
static_cast<I>(index % m_size.col), static_cast<I>(index / m_size.col) };
163 return pos.row * m_size.col + pos.col;
179 return { 0,
static_cast<std::size_t
>(m_size.col) * static_cast<std::size_t>(m_size.row) };
188 return { 0, m_size.row };
197 return { 0, m_size.col };
206 return { getColRange(), getRowRange() };
216 return getNeighborSquareRange(pos, 1);
226 return getNeighborSquareRange(pos, 2);
236 return getNeighborDiamondRange(pos, 1);
246 return getNeighborDiamondRange(pos, 2);
253 assert(isValid(pos));
255 auto colMin = pos.col - std::min(pos.col, n);
256 auto colMax = pos.col + std::min(m_size.col - pos.col - 1, n);
257 auto rowMin = pos.row - std::min(pos.row, n);
258 auto rowMax = pos.row + std::min(m_size.row - pos.row - 1, n);
264 assert(isValid(pos));
266 auto colMin = pos.col - std::min(pos.col, n);
267 auto colMax = pos.col + std::min(m_size.col - pos.col - 1, n);
268 auto rowMin = pos.row - std::min(pos.row, n);
269 auto rowMax = pos.row + std::min(m_size.row - pos.row - 1, n);
305 template<
typename T,
typename I =
unsigned>
325 , m_data(static_cast<
std::size_t>(size.width) * static_cast<
std::size_t>(size.height))
337 , m_data(static_cast<
std::size_t>(size.width) * static_cast<
std::size_t>(size.height), value)
368 std::swap(m_data, other.m_data);
398 return m_data.data();
407 return m_data.size();
419 return m_data.empty();
445 return m_data[index];
464 return m_data[index];
482 return m_data.data();
491 const T *
end() const noexcept {
492 return m_data.data() + m_data.size();
502 return m_data.data();
512 return m_data.data() + m_data.size();
519 return m_data[toIndex(pos)];
523 return m_data[toIndex(pos)];
527 std::vector<T> m_data;
534 template<
typename T,
typename I>
539 if (lhsSize.width != rhsSize.width || lhsSize.height != rhsSize.height) {
550 template<
typename T,
typename I>
553 ar | size.width | size.height;
555 for (
auto& item : array) {
566 template<
typename T,
typename I>
569 ar | size.width | size.height;
573 for (
auto& item : tmp) {
577 array = std::move(tmp);
582 #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:142
constexpr Vector< I, 2 > toPosition(std::size_t index) const noexcept
Transform a 1D position into a 2D position.
Definition: Array2D.h:152
A two-dimensional array.
Definition: Array2D.h:306
Serializer & operator|(Serializer &ar, const Array2D< T, I > &array)
Serialize a 2D array.
Definition: Array2D.h:551
constexpr Range< I > getRowRange() const noexcept
Get the row range.
Definition: Array2D.h:187
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:511
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:567
NeighborDiamondRange< I > get4NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 4 neighbors (at most)
Definition: Array2D.h:235
const T * begin() const noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:481
const T * getDataPtr() const noexcept
Get the pointer to raw data.
Definition: Array2D.h:397
constexpr Range< I > getColRange() const noexcept
Get the column range.
Definition: Array2D.h:196
std::size_t getDataSize() const noexcept
Get the raw data size.
Definition: Array2D.h:406
A 2D range.
Definition: Range.h:424
void swap(Array2D &other)
Swap with another array.
Definition: Array2D.h:366
constexpr Vector< I, 2 > getSize() const noexcept
Get the size of the array.
Definition: Array2D.h:113
NeighborSquareRange< I > get24NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 24 neighbors (at most)
Definition: Array2D.h:225
constexpr RangeZ getIndexRange() const noexcept
Get the 1D index range of the array.
Definition: Array2D.h:178
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:313
Array2D(Vector< I, 2 > size)
Constructor with a size.
Definition: Array2D.h:323
T & operator()(Vector< I, 2 > pos)
Get the element at a given 2D position.
Definition: Array2D.h:434
const T & operator()(std::size_t index) const
Get the element at a given 1D index.
Definition: Array2D.h:463
A 2D range.
Definition: Range.h:592
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Array2D.h:418
NeighborSquareRange< I > get8NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 8 neighbors (at most)
Definition: Array2D.h:215
constexpr std::size_t toIndex(Vector< I, 2 > pos) const noexcept
Transform a 2D position into a 1D position.
Definition: Array2D.h:162
constexpr ArrayRef< T > array(const T *data, std::size_t size)
Create a constant reference to an array.
Definition: ArrayRef.h:203
A 2D range.
Definition: Range.h:277
T * begin() noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:501
Array2D(Vector< I, 2 > size, const T &value)
Constructor with a size and a value.
Definition: Array2D.h:335
NeighborDiamondRange< I > get12NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 12 neighbors (at most)
Definition: Array2D.h:245
constexpr PositionRange< I > getPositionRange() const noexcept
Get the position range.
Definition: Array2D.h:205
bool operator==(const Array2D< T, I > &lhs, const Array2D< T, I > &rhs)
Equality operator for 2D array.
Definition: Array2D.h:535
constexpr I getRows() const noexcept
Get the number of rows.
Definition: Array2D.h:131
T & operator()(std::size_t index)
Get the element at a given 1D index.
Definition: Array2D.h:444
const T & operator()(Vector< I, 2 > pos) const
Get the element at a given 2D position.
Definition: Array2D.h:453
Index2D(Vector< I, 2 > size)
Constructor with a size.
Definition: Array2D.h:69
void swap(Index2D &other)
Swap with another array.
Definition: Array2D.h:99
constexpr I getCols() const noexcept
Get the number of columns.
Definition: Array2D.h:122
const T * end() const noexcept
Get an iterator to the element following the last element of the array.
Definition: Array2D.h:491