39 Array3D(std::size_t z, std::size_t y, std::size_t x) : sz_(z), sy_(y), sx_(x) { data_.resize(sz_ * sy_ * sx_, T()); }
48 void Resize(std::size_t z, std::size_t y, std::size_t x) {
52 data_.resize(sz_ * sy_ * sx_, T{});
59 std::size_t
SizeZ() const noexcept {
return sz_; }
65 std::size_t
SizeY() const noexcept {
return sy_; }
71 std::size_t
SizeX() const noexcept {
return sx_; }
80 T&
At(std::size_t z, std::size_t y, std::size_t x) {
81 std::size_t index = GetIndex(z, y, x);
82 if (index >= data_.size())
NNL_THROW(
RangeError(NNL_SRCTAG(
"index out of range: " + std::to_string(index))));
83 return data_.at(index);
93 const T&
At(std::size_t z, std::size_t y, std::size_t x)
const {
94 std::size_t index = GetIndex(z, y, x);
95 if (index >= data_.size())
NNL_THROW(
RangeError(NNL_SRCTAG(
"index out of range: " + std::to_string(index))));
96 return data_.at(index);
106 T&
operator()(std::size_t z, std::size_t y, std::size_t x)
noexcept {
108 return data_[GetIndex(z, y, x)];
118 const T&
operator()(std::size_t z, std::size_t y, std::size_t x)
const noexcept {
120 return data_[GetIndex(z, y, x)];
124 inline std::size_t GetIndex(std::size_t z, std::size_t y, std::size_t x)
const noexcept {
125 return x + y * sx_ + sx_ * sy_ * z;
128 std::vector<T> data_;
Defines macros for Design-by-Contract verification.
Defines the library-wide exception hierarchy and error handling macros.
#define NNL_EXPECTS_DBG(precondition)
Debug-only precondition check.
Definition contract.hpp:59
Exception thrown for out-of-range errors.
Definition exception.hpp:111
#define NNL_THROW(object)
Throws an exception or terminates the program if exceptions are disabled.
Definition exception.hpp:46
void Resize(std::size_t z, std::size_t y, std::size_t x)
Resizes the 3D array to specified dimensions.
Definition array3d.hpp:48
std::size_t SizeX() const noexcept
Returns the size of the array in the x dimension.
Definition array3d.hpp:71
const T & At(std::size_t z, std::size_t y, std::size_t x) const
Accesses an element at specified coordinates with bounds checking.
Definition array3d.hpp:93
std::size_t SizeZ() const noexcept
Returns the size of the array in the z dimension.
Definition array3d.hpp:59
std::size_t SizeY() const noexcept
Returns the size of the array in the y dimension.
Definition array3d.hpp:65
const T & operator()(std::size_t z, std::size_t y, std::size_t x) const noexcept
Accesses an element at specified coordinates (no bounds checking).
Definition array3d.hpp:118
T & At(std::size_t z, std::size_t y, std::size_t x)
Accesses an element at specified coordinates with bounds checking.
Definition array3d.hpp:80
T & operator()(std::size_t z, std::size_t y, std::size_t x) noexcept
Accesses an element at specified coordinates (no bounds checking).
Definition array3d.hpp:106
Array3D(std::size_t z, std::size_t y, std::size_t x)
Constructs a 3D array with specified dimensions.
Definition array3d.hpp:39
Definition exception.hpp:56