Mech-Eye API
2.6.0
API reference documentation for Mech-Eye 3D Laser Profiler
Toggle main menu visibility
Loading...
Searching...
No Matches
Array2D.h
1
#pragma once
2
#include <cstdint>
3
#include <cstring>
4
#include <memory>
5
#include <string>
6
#include <stdexcept>
7
8
namespace
mmind {
9
10
namespace
eye {
11
15
template
<
typename
ElementData>
16
class
Array2D
17
{
18
public
:
22
Array2D
() : _width(0), _height(0), _pData(nullptr) {}
26
~Array2D
() {}
27
31
size_t
width
()
const
{
return
_width; }
32
36
size_t
height
()
const
{
return
_height; }
37
41
bool
isEmpty
()
const
{
return
!_pData; }
42
48
const
ElementData*
data
()
const
{
return
_pData.get(); }
49
55
ElementData*
data
()
56
{
57
return
const_cast<
ElementData*
>
(
static_cast<
const
Array2D<ElementData>
&
>
(*this).data());
58
}
59
66
const
ElementData&
operator[]
(std::size_t n)
const
67
{
68
if
(n >= _height * _width || !_pData)
69
throw
std::out_of_range(
"invalid subscript"
);
70
ElementData*
data
= _pData.get();
71
return
data
[n];
72
}
73
80
ElementData&
operator[]
(std::size_t n)
81
{
82
return
const_cast<
ElementData&
>
(
static_cast<
const
Array2D<ElementData>
&
>
(*this)[n]);
83
}
84
93
const
ElementData&
at
(uint32_t row, uint32_t col)
const
94
{
95
if
(row >= _height || col >= _width || !_pData)
96
throw
std::out_of_range(
"invalid subscript"
);
97
ElementData*
data
= _pData.get();
98
return
data
[row * _width + col];
99
}
100
109
ElementData&
at
(uint32_t row, uint32_t col)
110
{
111
return
const_cast<
ElementData&
>
(
112
static_cast<
const
Array2D<ElementData>
&
>
(*this).at(row, col));
113
}
114
118
Array2D<ElementData>
clone
()
const
119
{
120
Array2D<ElementData>
copy;
121
copy.
resize
(_width, _height);
122
memcpy(copy.
data
(),
data
(), _height * _width *
sizeof
(ElementData));
123
return
copy;
124
}
125
131
void
resize
(
size_t
width
,
size_t
height
)
132
{
133
if
(
width
== 0 ||
height
== 0)
134
return
release
();
135
136
if
(_width ==
width
&& _height ==
height
)
137
return
;
138
139
_width =
width
;
140
_height =
height
;
141
_pData.reset(
new
ElementData[_width * _height], [](ElementData* p) {
delete
[] p; });
142
}
143
147
void
release
()
148
{
149
_pData.reset();
150
_width = 0;
151
_height = 0;
152
}
153
154
private
:
155
size_t
_width;
156
size_t
_height;
157
std::shared_ptr<ElementData> _pData;
158
};
159
160
}
// namespace eye
161
}
// namespace mmind
mmind::eye::Array2D::height
size_t height() const
Returns the height of the Array2D object.
Definition
Array2D.h:36
mmind::eye::Array2D::operator[]
ElementData & operator[](std::size_t n)
Returns a reference to the constant element with the specified index in the Array2D object using the ...
Definition
Array2D.h:80
mmind::eye::Array2D::operator[]
const ElementData & operator[](std::size_t n) const
Returns a reference to the constant element with the specified index in the Array2D object using the ...
Definition
Array2D.h:66
mmind::eye::Array2D::data
ElementData * data()
Returns the pointer to an element in the Array2D object. The returned pointer will be invalidated aft...
Definition
Array2D.h:55
mmind::eye::Array2D::at
const ElementData & at(uint32_t row, uint32_t col) const
Returns a reference to the constant element at the specified row and column in the Array2D object.
Definition
Array2D.h:93
mmind::eye::Array2D::clone
Array2D< ElementData > clone() const
Creates a deep copy of the Array2D object.
Definition
Array2D.h:118
mmind::eye::Array2D::resize
void resize(size_t width, size_t height)
Changes the size of the Array2D object. It destroys the existing data and reallocates memory accordin...
Definition
Array2D.h:131
mmind::eye::Array2D::data
const ElementData * data() const
Returns the pointer to an element in the Array2D object. The returned pointer will be invalidated aft...
Definition
Array2D.h:48
mmind::eye::Array2D::Array2D
Array2D()
Constructor.
Definition
Array2D.h:22
mmind::eye::Array2D::at
ElementData & at(uint32_t row, uint32_t col)
Returns a reference to the element at the specified row and column in the Array2D object.
Definition
Array2D.h:109
mmind::eye::Array2D::width
size_t width() const
Returns the width of the Array2D object.
Definition
Array2D.h:31
mmind::eye::Array2D::isEmpty
bool isEmpty() const
Returns true if the Array2D object has no elements.
Definition
Array2D.h:41
mmind::eye::Array2D::release
void release()
Deallocates the data in the Array2D object.
Definition
Array2D.h:147
mmind::eye::Array2D::~Array2D
~Array2D()
Describes a destructor.
Definition
Array2D.h:26
Generated by
1.17.0