From 8f7f7071259ad0a0ff4262157a7a8b7f1f53530e Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Sun, 8 Nov 2009 09:00:00 +0100 Subject: 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. --- crawl-ref/source/fixary.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'crawl-ref/source/fixary.h') 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::init(const Z &initial) data[i] = initial; } +// A fixed array centered around the origin. +template 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 TYPE& operator () (const Indexer &i) { + return data[i.x+RADIUS][i.y+RADIUS]; + } + + template 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 data; +}; + #endif // FIXARY_H -- cgit v1.2.3-54-g00ecf