14template <
typename ElementData>
30 size_t width()
const {
return _width; }
35 size_t height()
const {
return _height; }
57 bool isEmpty()
const {
return _height == 0; }
68 std::shared_ptr<ElementData> pNewData(
new ElementData[_width *
height],
69 [](ElementData* p) {
delete[] p; });
71 memcpy(pNewData.get(), _pData.get(), _width * _height *
sizeof(ElementData));
74 _pData = std::move(pNewData);
82 if (_width !=
data.width())
85 if (_capacity - _height <
data.height()) {
88 memcpy(_pData.get() + _height * _width,
data.data(),
89 data.height() *
data.width() *
sizeof(ElementData));
90 _height +=
data.height();
97 const ElementData*
data()
const {
return _pData.get(); }
102 ElementData*
data() {
return _pData.get(); }
112 if (n >= _height * _width || !_pData)
113 throw std::out_of_range(
"invalid subscript");
114 ElementData*
data = _pData.get();
137 const ElementData&
at(uint32_t row, uint32_t col)
const
139 if (row >= _height || col >= _width || !_pData)
140 throw std::out_of_range(
"invalid subscript");
141 ElementData*
data = _pData.get();
142 return data[row * _width + col];
153 ElementData&
at(
size_t row,
size_t col)
155 return const_cast<ElementData&
>(
166 memcpy(copy.
data(),
data(), _height * _width *
sizeof(ElementData));
176 memset(_pData.get(), 0, _height * _width *
sizeof(ElementData));
185 void flip(
bool flipX,
bool flipY)
187 auto*
data = _pData.get();
188 const size_t height = _height;
189 const size_t width = _width;
192 const size_t rowsToFlip =
height / 2;
193 for (
size_t i = 0; i < rowsToFlip; ++i) {
194 const size_t mirrorRow =
height - 1 - i;
196 auto* mirrorRowStart =
data + mirrorRow *
width;
197 std::swap_ranges(rowStart, rowStart +
width, mirrorRowStart);
202 for (
size_t i = 0; i <
height; ++i) {
204 std::reverse(rowStart, rowStart +
width);
213 std::shared_ptr<ElementData> _pData;
Represents the data struct of the profile data.
const ElementData & at(uint32_t row, uint32_t col) const
Returns a const element reference to the specified row and column index in the BatchArray object.
ElementData & operator[](std::size_t n)
Returns an element reference to the specified index in the BatchArray object using the operator [].
void clear()
Clears the data of the BatchArray object.
BatchArray(size_t width)
Describes a constructor.
ElementData * data()
Returns the pointer to the element data.
const ElementData * data() const
Returns the pointer to the element data.
size_t height() const
Returns the height of the BatchArray object.
bool isEmpty() const
Returns true if the BatchArray object has no elements.
size_t width() const
Returns the width of the BatchArray object.
bool append(const BatchArray &data)
Appends the data variable onto the end of this BatchArray object.
BatchArray< ElementData > clone() const
Creates a deep copy of the BatchArray object.
void reserve(size_t height)
Requests for enough capacity of the BatchArray object to contain the number of lines corresponding to...
size_t capacity() const
Returns the size of the storage space currently allocated for the BatchArray object,...
ElementData & at(size_t row, size_t col)
Returns an element reference to the specified row and column index in the BatchArray object.
void flip(bool flipX, bool flipY)
Flips the BatchArray object.
const ElementData & operator[](std::size_t n) const
Returns a const element reference to the specified index in the BatchArray object using the operator ...
~BatchArray()=default
Describes a destructor.
void setHeight(size_t height)
Sets the height of the BatchArray object.