18 #ifndef ION_BASE_ARRAY2_H_
19 #define ION_BASE_ARRAY2_H_
39 : width_(width), height_(height), data_(
GetAllocator()) {
40 data_.resize(width * height);
55 size_t GetSize()
const {
return data_.size(); }
59 bool Set(
size_t column,
size_t row,
const T& val) {
60 const size_t index = GetIndex(column, row);
71 const T&
Get(
size_t column,
size_t row)
const {
72 const size_t index = GetIndex(column, row);
74 base::InvalidReference<T>() : data_[index];
80 const size_t index = GetIndex(column, row);
87 size_t GetIndex(
size_t column,
size_t row)
const {
88 if (column >= width_ || row >= height_) {
89 LOG(
ERROR) <<
"Bad indices (" << column <<
", " << row
90 <<
") for Array2 of size " << width_ <<
" x " << height_;
93 return row * width_ + column;
104 #endif // ION_BASE_ARRAY2_H_
const T & Get(size_t column, size_t row) const
Returns the indexed element of the array.
const size_t kInvalidIndex
kInvalidIndex is a size_t value that is very unlikely to be a valid index.
#define LOG(severity)
Logs the streamed message unconditionally with a severity of severity.
Simple rectangular 2D array class with range-checked indexing, templatized by the element type...
Array2()
The default constructor creates an empty (0x0) array.
Allocatable is an abstract base class for classes whose memory is managed by an Allocator.
bool Set(size_t column, size_t row, const T &val)
Sets one element of the array.
T * GetMutable(size_t column, size_t row)
Returns a pointer the indexed element of the array.
Copyright 2016 Google Inc.
Array2(size_t width, size_t height, const T &initial_value)
Constructor that creates an array of specified size with elements all set to initial_value.
const AllocatorPtr & GetAllocator() const
Returns the Allocator that was used for the instance.
Array2(size_t width, size_t height)
Constructor that creates an array of specified size with undefined elements.