blob: 3db9d49abd70bc5a632fc74d9169f4f653d9e835 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* 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$
*
* Change History (most recent first):
*
* <1> 6/16/00 JDJ Created
*/
#ifndef FIXARY_H
#define FIXARY_H
#include "FixVec.h"
// ==========================================================================
// class FixedArray
// ==========================================================================
template <class TYPE, int WIDTH, int HEIGHT> 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;
typedef FixedVector<TYPE, HEIGHT> Column; // operator[] needs to return one of these to avoid breaking client code (if inlining is on there won't be a speed hit)
//-----------------------------------
// Initialization/Destruction
//
public:
~FixedArray() {}
FixedArray() {}
//-----------------------------------
// 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<class Indexer> TYPE& operator () (const Indexer &i)
{
return mData[i.x][i.y];
}
template<class Indexer> const TYPE& operator () (const Indexer &i)
const
{
return mData[i.x][i.y];
}
//-----------------------------------
// Member Data
//
protected:
FixedVector<Column, WIDTH> mData;
};
#endif // FIXARY_H
|