Go to the documentation of this file.
6 #ifndef CNOID_UTIL_ARRAY_2D_H
7 #define CNOID_UTIL_ARRAY_2D_H
14 template <
typename ElementType,
typename Allocator = std::allocator<ElementType> >
21 typedef typename std::vector<ElementType, Allocator>
Container;
27 typename Container::iterator top;
28 typename Container::iterator end_;
39 size_ = owner.colSize_;
68 ElementType&
at(
int index) {
86 class iterator :
public std::iterator<std::bidirectional_iterator_tag, ElementType, int> {
87 typename Container::iterator current;
92 iterator(
typename Container::iterator current,
int colSize)
93 : current(current), colSize(colSize) {
105 return (current == other.current);
108 return (current != other.current);
113 typename Container::iterator top;
124 colSize = owner.colSize_;
125 size_ = owner.rowSize_;
126 end_ =
iterator(top + colSize * size_, colSize);
138 return top[index * colSize];
142 return top[index * colSize];
145 ElementType&
at(
int index) {
146 return top[index * colSize];
169 : container(org.container) {
170 rowSize_ = org.rowSize_;
171 colSize_ = org.colSize_;
176 container = rhs.container;
177 rowSize_ = rhs.rowSize_;
178 colSize_ = rhs.colSize_;
186 return container.empty();
189 void resize(
int newRowSize,
int newColSize) {
190 container.resize(newRowSize * newColSize);
191 rowSize_ = newRowSize;
192 colSize_ = newColSize;
200 resize(rowSize_, newColSize);
208 resize(newRowSize, colSize_);
215 const ElementType&
operator()(
int rowIndex,
int colIndex)
const {
216 return container[rowIndex * colSize_ + colIndex];
220 return container[rowIndex * colSize_ + colIndex];
223 const ElementType&
at(
int rowIndex,
int colIndex)
const {
224 return container[rowIndex * colSize_ + colIndex];
227 ElementType&
at(
int rowIndex,
int colIndex) {
228 return container[rowIndex * colSize_ + colIndex];
232 return Row(*
this, rowIndex);
236 return Row(*
this, rowIndex);
240 return Row(*
this, rowIndex);
243 const Row
row(
int rowIndex)
const {
244 return Row(*
this, rowIndex);
248 return Column(*
this, colIndex);
251 const Column
column(
int colIndex)
const {
252 return Column(*
this, colIndex);
256 return container.begin();
260 return container.end();
Array2D(int rowSize, int colSize)
Definition: Array2D.h:162
int size() const
Definition: Array2D.h:133
ElementType & at(int index)
Definition: Array2D.h:145
int colSize() const
Definition: Array2D.h:211
bool empty() const
Definition: Array2D.h:52
virtual ~Array2D()
Definition: Array2D.h:183
Row operator[](int rowIndex)
Definition: Array2D.h:231
iterator begin()
Definition: Array2D.h:149
iterator end()
Definition: Array2D.h:152
const ElementType & operator[](int index) const
Definition: Array2D.h:64
const ElementType & operator[](int index) const
Definition: Array2D.h:141
void resizeColumn(int newColSize)
Definition: Array2D.h:199
void operator--()
Definition: Array2D.h:101
Array2DType & operator=(const Array2DType &rhs)
Definition: Array2D.h:174
iterator begin()
Definition: Array2D.h:255
iterator(typename Container::iterator current, int colSize)
Definition: Array2D.h:92
Column column(int colIndex)
Definition: Array2D.h:247
bool empty() const
Definition: Array2D.h:129
bool operator!=(iterator other) const
Definition: Array2D.h:107
const Row operator[](int rowIndex) const
Definition: Array2D.h:235
ElementType & operator[](int index)
Definition: Array2D.h:137
iterator()
Definition: Array2D.h:90
Container::iterator iterator
Definition: Array2D.h:32
ElementType & at(int rowIndex, int colIndex)
Definition: Array2D.h:227
iterator end()
Definition: Array2D.h:76
void resize(int newRowSize, int newColSize)
Definition: Array2D.h:189
std::vector< ElementType, Allocator > Container
Definition: Array2D.h:21
const ElementType & at(int rowIndex, int colIndex) const
Definition: Array2D.h:223
Definition: AbstractSceneLoader.h:11
bool operator==(iterator other) const
Definition: Array2D.h:104
Column(const Array2D< ElementType, Allocator > &owner, int part)
Definition: Array2D.h:121
Array2D(const Array2DType &org)
Definition: Array2D.h:168
void resizeRow(int newRowSize)
Definition: Array2D.h:207
Container::iterator iterator
Definition: Array2D.h:22
const ElementType & operator()(int rowIndex, int colIndex) const
Definition: Array2D.h:215
bool empty() const
Definition: Array2D.h:185
void operator++()
Definition: Array2D.h:98
Row(const Array2D< ElementType, Allocator > &owner, int frame)
Definition: Array2D.h:38
Array2D()
Definition: Array2D.h:157
const Column column(int colIndex) const
Definition: Array2D.h:251
Row row(int rowIndex)
Definition: Array2D.h:239
ElementType & operator*()
Definition: Array2D.h:95
int size() const
Definition: Array2D.h:56
ElementType & operator[](int index)
Definition: Array2D.h:60
int rowSize() const
Definition: Array2D.h:203
const Row row(int rowIndex) const
Definition: Array2D.h:243
ElementType Element
Definition: Array2D.h:20
Row()
Definition: Array2D.h:34
ElementType & operator()(int rowIndex, int colIndex)
Definition: Array2D.h:219
iterator end()
Definition: Array2D.h:259
iterator begin()
Definition: Array2D.h:72
ElementType & at(int index)
Definition: Array2D.h:68
void clear()
Definition: Array2D.h:195
Row & operator=(const Row &rhs)
Definition: Array2D.h:45