summaryrefslogtreecommitdiff
path: root/src/grid.h
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2018-06-16 12:52:48 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-08-12 11:13:53 +0200
commit8ad5f7c39db55cab3f78fdefab323435261941fd (patch)
treefb5a3f4a29716a83e18a96b70ec9162d9e93b8c6 /src/grid.h
parent20bdae6c72192c87bf95c6ac86c8cc049aa1ab5a (diff)
Add hovering to visualization.
Diffstat (limited to 'src/grid.h')
-rw-r--r--src/grid.h23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/grid.h b/src/grid.h
index 6d3933b..85c7465 100644
--- a/src/grid.h
+++ b/src/grid.h
@@ -53,15 +53,18 @@ public:
T operator()(Index x, Index y) const;
T& operator()(Pos pos);
T& operator()(Index x, Index y);
+ std::vector<T> const& getAllEntries() const;
void resize(Index width, Index height);
void assign(Index width, Index height, T value);
+ void setDefaultValue(T value);
private:
Index _width;
Index _height;
std::vector<T> _entries;
+ T default_value;
};
template <typename T>
@@ -99,25 +102,31 @@ auto Grid<T>::height() const -> Index
template <typename T>
T Grid<T>::operator()(Pos pos) const
{
- return _entries.at(pos.x + _width*pos.y);
+ return is_valid(pos) ? _entries[pos.x + _width*pos.y] : default_value;
}
template <typename T>
T Grid<T>::operator()(Index x, Index y) const
{
- return _entries.at(x + _width*y);
+ return is_valid(x, y) ? _entries[x + _width*y] : default_value;
}
template <typename T>
T& Grid<T>::operator()(Pos pos)
{
- return _entries.at(pos.x + _width*pos.y);
+ return is_valid(pos) ? _entries[pos.x + _width*pos.y] : default_value;
}
template <typename T>
T& Grid<T>::operator()(Index x, Index y)
{
- return _entries.at(x + _width*y);
+ return is_valid(x, y) ? _entries[x + _width*y] : default_value;
+}
+
+template <typename T>
+std::vector<T> const& Grid<T>::getAllEntries() const
+{
+ return _entries;
}
template <typename T>
@@ -135,3 +144,9 @@ void Grid<T>::assign(Index width, Index height, T value)
_height = height;
_entries.assign(_width*_height, value);
}
+
+template <typename T>
+void Grid<T>::setDefaultValue(T value)
+{
+ default_value = value;
+}