From da980e3a2354a885fdea2d9bde5ead5e2579a33e Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Tue, 29 Sep 2009 21:06:27 -0700 Subject: Move 'FixAry.h' -> 'fixary.h', 'FixVec.h' -> 'fixvec.h' for file naming consistency Signed-off-by: Steven Noonan --- crawl-ref/source/FixAry.h | 120 ------------------------------- crawl-ref/source/FixVec.h | 128 --------------------------------- crawl-ref/source/MSVC/crawl-ref.vcproj | 4 +- crawl-ref/source/dungeon.h | 4 +- crawl-ref/source/externs.h | 2 +- crawl-ref/source/files.h | 2 +- crawl-ref/source/fixary.h | 120 +++++++++++++++++++++++++++++++ crawl-ref/source/fixvec.h | 128 +++++++++++++++++++++++++++++++++ crawl-ref/source/mapdef.h | 2 +- crawl-ref/source/maps.h | 2 +- crawl-ref/source/mgrow.h | 2 +- crawl-ref/source/monplace.h | 2 +- crawl-ref/source/spl-book.h | 2 +- crawl-ref/source/tilesdl.h | 2 +- crawl-ref/source/transfor.h | 2 +- crawl-ref/source/travel.cc | 2 +- 16 files changed, 262 insertions(+), 262 deletions(-) delete mode 100644 crawl-ref/source/FixAry.h delete mode 100644 crawl-ref/source/FixVec.h create mode 100644 crawl-ref/source/fixary.h create mode 100644 crawl-ref/source/fixvec.h diff --git a/crawl-ref/source/FixAry.h b/crawl-ref/source/FixAry.h deleted file mode 100644 index 55d32cb55a..0000000000 --- a/crawl-ref/source/FixAry.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * File: FixAry.h - * Summary: Fixed size 2D vector class that asserts if you do something bad. - * Written by: Jesse Jones - * - * Modified for Crawl Reference by $Author$ on $Date$ - */ - -#ifndef FIXARY_H -#define FIXARY_H - -#include "FixVec.h" - - -// ========================================================================== -// class FixedArray -// ========================================================================== -template class FixedArray { - -//----------------------------------- -// 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; - - // operator[] should return one of these to avoid breaking - // client code (if inlining is on there won't be a speed hit) - typedef FixedVector Column; - -//----------------------------------- -// API -// -public: - // ----- Size ----- - bool empty() const { return WIDTH == 0 || HEIGHT == 0; } - int size() const { return WIDTH*HEIGHT; } - int width() const { return WIDTH; } - int height() const { return HEIGHT; } - - // ----- Access ----- - Column& operator[](unsigned long index) { return mData[index]; } - const Column& operator[](unsigned long index) const { - return mData[index]; - } - - template TYPE& operator () (const Indexer &i) { - return mData[i.x][i.y]; - } - - template const TYPE& operator () (const Indexer &i) const { - return mData[i.x][i.y]; - } - - void init(const TYPE& def) { - for ( int i = 0; i < WIDTH; ++i ) - mData[i].init(def); - } - -protected: - FixedVector mData; -}; - -template -class Matrix { -public: - Matrix(int width, int height, const Z &initial); - Matrix(int width, int height); - ~Matrix(); - - void init(const Z &initial); - Z &operator () (int x, int y) - { - return data[x + y * width]; - } - const Z &operator () (int x, int y) const - { - return data[x + y * width]; - } - -private: - Z *data; - int width, height, size; -}; - -template -Matrix::Matrix(int _width, int _height, const Z &initial) - : data(NULL), width(_width), height(_height), size(_width * _height) -{ - data = new Z [ size ]; - init(initial); -} - -template -Matrix::Matrix(int _width, int _height) - : data(NULL), width(_width), height(_height), size(_width * _height) -{ - data = new Z [ size ]; -} - -template -Matrix::~Matrix() -{ - delete [] data; -} - -template -void Matrix::init(const Z &initial) -{ - for (int i = 0; i < size; ++i) - data[i] = initial; -} - -#endif // FIXARY_H diff --git a/crawl-ref/source/FixVec.h b/crawl-ref/source/FixVec.h deleted file mode 100644 index c2647e2cf4..0000000000 --- a/crawl-ref/source/FixVec.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * File: FixVec.h - * Summary: Fixed size vector class that asserts if you do something bad. - * Written by: Jesse Jones - * - * Modified for Crawl Reference by $Author$ on $Date$ - */ - -#ifndef FIXVEC_H -#define FIXVEC_H - -#if _MSC_VER -// Benign: FixedVector has an array in member init list -# pragma warning(disable : 4351) -#endif - -#include -#include - -#include "debug.h" -// ========================================================================== -// class FixedVector -// ========================================================================== - -template class FixedVector -{ - -//----------------------------------- -// 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; - - typedef TYPE* iterator; - typedef const TYPE* const_iterator; - -//----------------------------------- -// Initialization/Destruction -// -public: - ~FixedVector() {} - - FixedVector() {} - - FixedVector(TYPE def) : mData() - { - init(def); - } - - FixedVector(TYPE value0, TYPE value1, ...); - // Allows for something resembling C array initialization, eg - // instead of "int a[3] = {0, 1, 2}" you'd use "FixedVector - // a(0, 1, 2)". Note that there must be SIZE arguments. - -//----------------------------------- -// API -// -public: - // ----- Size ----- - bool empty() const { return SIZE == 0; } - size_t size() const { return SIZE; } - - // ----- Access ----- - TYPE& operator[](unsigned long index) { - ASSERT(index < SIZE); - return mData[index]; - } - - const TYPE& operator[](unsigned long index) const { - ASSERT(index < SIZE); - return mData[index]; - } - - const TYPE* buffer() const { return mData; } - TYPE* buffer() { return mData; } - - // ----- Iterating ----- - iterator begin() { return mData; } - const_iterator begin() const { return mData; } - - iterator end() { return this->begin() + this->size(); } - const_iterator end() const { return this->begin() + this->size(); } - void init(const TYPE& def); - -//----------------------------------- -// Member Data -// -protected: - TYPE mData[SIZE]; -}; - - -// ========================================================================== -// Outlined Methods -// ========================================================================== -template -FixedVector::FixedVector(TYPE value0, TYPE value1, ...) -{ - mData[0] = value0; - mData[1] = value1; - - va_list ap; - va_start(ap, value1); // second argument is last fixed parameter - - for (int index = 2; index < SIZE; index++) - { - TYPE value = va_arg(ap, TYPE); - mData[index] = value; - } - - va_end(ap); -} - -template -void FixedVector::init(const TYPE& def) -{ - for (int i = 0; i < SIZE; ++i) - mData[i] = def; -} - -#endif // FIXVEC_H diff --git a/crawl-ref/source/MSVC/crawl-ref.vcproj b/crawl-ref/source/MSVC/crawl-ref.vcproj index f7570e1680..b81dc28a6c 100644 --- a/crawl-ref/source/MSVC/crawl-ref.vcproj +++ b/crawl-ref/source/MSVC/crawl-ref.vcproj @@ -388,11 +388,11 @@ > #include diff --git a/crawl-ref/source/fixary.h b/crawl-ref/source/fixary.h new file mode 100644 index 0000000000..4c5b3e2b3b --- /dev/null +++ b/crawl-ref/source/fixary.h @@ -0,0 +1,120 @@ +/* + * File: fixary.h + * Summary: Fixed size 2D vector class that asserts if you do something bad. + * Written by: Jesse Jones + * + * Modified for Crawl Reference by $Author$ on $Date$ + */ + +#ifndef FIXARY_H +#define FIXARY_H + +#include "fixvec.h" + + +// ========================================================================== +// class FixedArray +// ========================================================================== +template class FixedArray { + +//----------------------------------- +// 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; + + // operator[] should return one of these to avoid breaking + // client code (if inlining is on there won't be a speed hit) + typedef FixedVector Column; + +//----------------------------------- +// API +// +public: + // ----- Size ----- + bool empty() const { return WIDTH == 0 || HEIGHT == 0; } + int size() const { return WIDTH*HEIGHT; } + int width() const { return WIDTH; } + int height() const { return HEIGHT; } + + // ----- Access ----- + Column& operator[](unsigned long index) { return mData[index]; } + const Column& operator[](unsigned long index) const { + return mData[index]; + } + + template TYPE& operator () (const Indexer &i) { + return mData[i.x][i.y]; + } + + template const TYPE& operator () (const Indexer &i) const { + return mData[i.x][i.y]; + } + + void init(const TYPE& def) { + for ( int i = 0; i < WIDTH; ++i ) + mData[i].init(def); + } + +protected: + FixedVector mData; +}; + +template +class Matrix { +public: + Matrix(int width, int height, const Z &initial); + Matrix(int width, int height); + ~Matrix(); + + void init(const Z &initial); + Z &operator () (int x, int y) + { + return data[x + y * width]; + } + const Z &operator () (int x, int y) const + { + return data[x + y * width]; + } + +private: + Z *data; + int width, height, size; +}; + +template +Matrix::Matrix(int _width, int _height, const Z &initial) + : data(NULL), width(_width), height(_height), size(_width * _height) +{ + data = new Z [ size ]; + init(initial); +} + +template +Matrix::Matrix(int _width, int _height) + : data(NULL), width(_width), height(_height), size(_width * _height) +{ + data = new Z [ size ]; +} + +template +Matrix::~Matrix() +{ + delete [] data; +} + +template +void Matrix::init(const Z &initial) +{ + for (int i = 0; i < size; ++i) + data[i] = initial; +} + +#endif // FIXARY_H diff --git a/crawl-ref/source/fixvec.h b/crawl-ref/source/fixvec.h new file mode 100644 index 0000000000..49c4a9fc4e --- /dev/null +++ b/crawl-ref/source/fixvec.h @@ -0,0 +1,128 @@ +/* + * File: fixvec.h + * Summary: Fixed size vector class that asserts if you do something bad. + * Written by: Jesse Jones + * + * Modified for Crawl Reference by $Author$ on $Date$ + */ + +#ifndef FIXVEC_H +#define FIXVEC_H + +#if _MSC_VER +// Benign: FixedVector has an array in member init list +# pragma warning(disable : 4351) +#endif + +#include +#include + +#include "debug.h" +// ========================================================================== +// class FixedVector +// ========================================================================== + +template class FixedVector +{ + +//----------------------------------- +// 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; + + typedef TYPE* iterator; + typedef const TYPE* const_iterator; + +//----------------------------------- +// Initialization/Destruction +// +public: + ~FixedVector() {} + + FixedVector() {} + + FixedVector(TYPE def) : mData() + { + init(def); + } + + FixedVector(TYPE value0, TYPE value1, ...); + // Allows for something resembling C array initialization, eg + // instead of "int a[3] = {0, 1, 2}" you'd use "FixedVector + // a(0, 1, 2)". Note that there must be SIZE arguments. + +//----------------------------------- +// API +// +public: + // ----- Size ----- + bool empty() const { return SIZE == 0; } + size_t size() const { return SIZE; } + + // ----- Access ----- + TYPE& operator[](unsigned long index) { + ASSERT(index < SIZE); + return mData[index]; + } + + const TYPE& operator[](unsigned long index) const { + ASSERT(index < SIZE); + return mData[index]; + } + + const TYPE* buffer() const { return mData; } + TYPE* buffer() { return mData; } + + // ----- Iterating ----- + iterator begin() { return mData; } + const_iterator begin() const { return mData; } + + iterator end() { return this->begin() + this->size(); } + const_iterator end() const { return this->begin() + this->size(); } + void init(const TYPE& def); + +//----------------------------------- +// Member Data +// +protected: + TYPE mData[SIZE]; +}; + + +// ========================================================================== +// Outlined Methods +// ========================================================================== +template +FixedVector::FixedVector(TYPE value0, TYPE value1, ...) +{ + mData[0] = value0; + mData[1] = value1; + + va_list ap; + va_start(ap, value1); // second argument is last fixed parameter + + for (int index = 2; index < SIZE; index++) + { + TYPE value = va_arg(ap, TYPE); + mData[index] = value; + } + + va_end(ap); +} + +template +void FixedVector::init(const TYPE& def) +{ + for (int i = 0; i < SIZE; ++i) + mData[i] = def; +} + +#endif // FIXVEC_H diff --git a/crawl-ref/source/mapdef.h b/crawl-ref/source/mapdef.h index 3efffadb0f..8fc2695980 100644 --- a/crawl-ref/source/mapdef.h +++ b/crawl-ref/source/mapdef.h @@ -22,7 +22,7 @@ #include "externs.h" #include "makeitem.h" #include "travel.h" -#include "FixAry.h" +#include "fixary.h" // [dshaligram] Maps can be mirrored; for every orientation, there must be // a suitable mirror. diff --git a/crawl-ref/source/maps.h b/crawl-ref/source/maps.h index 6f3d07615a..94294de9ff 100644 --- a/crawl-ref/source/maps.h +++ b/crawl-ref/source/maps.h @@ -10,7 +10,7 @@ #ifndef MAPS_H #define MAPS_H -#include "FixVec.h" +#include "fixvec.h" #include "dungeon.h" #include diff --git a/crawl-ref/source/mgrow.h b/crawl-ref/source/mgrow.h index f21dddc8e1..fb3ba8a2c4 100644 --- a/crawl-ref/source/mgrow.h +++ b/crawl-ref/source/mgrow.h @@ -10,7 +10,7 @@ #define __MGROW_H__ #include "AppHdr.h" -#include "FixVec.h" +#include "fixvec.h" // Monster level-up data. diff --git a/crawl-ref/source/monplace.h b/crawl-ref/source/monplace.h index a895d88423..8dfab01b17 100644 --- a/crawl-ref/source/monplace.h +++ b/crawl-ref/source/monplace.h @@ -12,7 +12,7 @@ #include "enum.h" #include "dungeon.h" -#include "FixVec.h" +#include "fixvec.h" enum band_type { diff --git a/crawl-ref/source/spl-book.h b/crawl-ref/source/spl-book.h index e8373e4e49..a5f896b15b 100644 --- a/crawl-ref/source/spl-book.h +++ b/crawl-ref/source/spl-book.h @@ -11,7 +11,7 @@ #define SPL_BOOK_H #include "externs.h" -#include "FixVec.h" +#include "fixvec.h" #define SPELLBOOK_SIZE 8 diff --git a/crawl-ref/source/tilesdl.h b/crawl-ref/source/tilesdl.h index 69ead08b0d..867c1cf0df 100644 --- a/crawl-ref/source/tilesdl.h +++ b/crawl-ref/source/tilesdl.h @@ -10,7 +10,7 @@ #include "debug.h" #include "externs.h" -#include "FixVec.h" +#include "fixvec.h" #include "tilereg.h" // This struct defines all of the state that any particular rendering needs. diff --git a/crawl-ref/source/transfor.h b/crawl-ref/source/transfor.h index 681f1e84f9..8d3b9bc331 100644 --- a/crawl-ref/source/transfor.h +++ b/crawl-ref/source/transfor.h @@ -12,7 +12,7 @@ #include -#include "FixVec.h" +#include "fixvec.h" #include "enum.h" enum transformation_type diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 275969420b..6b4b25527e 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -13,7 +13,7 @@ REVISION("$Rev$"); #include "files.h" -#include "FixAry.h" +#include "fixary.h" #include "branch.h" #include "command.h" #include "cio.h" -- cgit v1.2.3-54-g00ecf