summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/fixary.h
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-11-08 09:00:00 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-08 09:15:47 +0100
commit8f7f7071259ad0a0ff4262157a7a8b7f1f53530e (patch)
tree371dd4c3a4b762b97494e2b544b9311e37311ba2 /crawl-ref/source/fixary.h
parent9255dd6cfa9e29b6c4b5802c04639576f25f7144 (diff)
downloadcrawl-ref-8f7f7071259ad0a0ff4262157a7a8b7f1f53530e.tar.gz
crawl-ref-8f7f7071259ad0a0ff4262157a7a8b7f1f53530e.zip
Add variant SquareArray of FixedArray.
SquareArray is indexed in local coordinates and is specified by RADIUS. Valid indices are (-RADIUS,-RADIUS) to (RADIUS,RADIUS), size 2*RADIUS+1 x 2*RADIUS+1.
Diffstat (limited to 'crawl-ref/source/fixary.h')
-rw-r--r--crawl-ref/source/fixary.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/crawl-ref/source/fixary.h b/crawl-ref/source/fixary.h
index 61318a58b0..8743e4573a 100644
--- a/crawl-ref/source/fixary.h
+++ b/crawl-ref/source/fixary.h
@@ -128,4 +128,59 @@ void Matrix<Z>::init(const Z &initial)
data[i] = initial;
}
+// A fixed array centered around the origin.
+template <class TYPE, int RADIUS> class SquareArray {
+//-----------------------------------
+// Types
+//
+public:
+ typedef TYPE value_type;
+ typedef TYPE& reference;
+ typedef const TYPE& const_reference;
+ typedef TYPE* pointer;
+ typedef const TYPE* const_pointer;
+
+ typedef unsigned long size_type;
+ typedef long difference_type;
+
+//-----------------------------------
+// Initialization/Destruction
+//
+public:
+ ~SquareArray() {}
+
+ SquareArray() {}
+
+ SquareArray(TYPE def)
+ {
+ init(def);
+ }
+
+//-----------------------------------
+// API
+//
+public:
+ // ----- Size -----
+ bool empty() const { return data.empty(); }
+ int size() const { return data.size(); }
+ int width() const { return data.width(); }
+ int height() const { return data.height(); }
+
+ // ----- Access -----
+ template<class Indexer> TYPE& operator () (const Indexer &i) {
+ return data[i.x+RADIUS][i.y+RADIUS];
+ }
+
+ template<class Indexer> const TYPE& operator () (const Indexer &i) const {
+ return data[i.x+RADIUS][i.y+RADIUS];
+ }
+
+ void init(const TYPE& def) {
+ data.init(def);
+ }
+
+protected:
+ FixedArray<TYPE, 2*RADIUS+1, 2*RADIUS+1> data;
+};
+
#endif // FIXARY_H