summaryrefslogtreecommitdiffstats
path: root/debian/fireflies/fireflies-2.08/libgfx/include/gfx/array.h
blob: 66189e4b90ab2cc8185f04a9c889243bce05520d (plain)
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
#ifndef GFXARRAY_INCLUDED // -*- C++ -*-
#define GFXARRAY_INCLUDED
#if !defined(__GNUC__)
#  pragma once
#endif

/************************************************************************

  These array classes extend the STL vector<> template to provide
  convenient 2-D and 3-D arrays.

  NOTE: This package used to provide array<T> and varray<T> templates
  that were alternatives to the STL vector<T> template.  Its purpose was
  to support some legacy code written in the days when few compilers
  understood STL.  Now that STL support is common, that code has been
  removed.

  $Id: array.h 427 2004-09-27 04:45:31Z garland $

 ************************************************************************/

#include "gfx.h"
#include <vector>

namespace gfx
{

template<class T>
class array2 : public std::vector<T>
{
private:
    int W, H;

protected:
    array2() { }

public:
    array2(int w, int h) : std::vector<T>(w*h), W(w), H(h) { }

    T&       operator()(int i, int j)       { return (*this)[j*W+i]; }
    const T& operator()(int i, int j) const { return (*this)[j*W+i]; }

    int width() const { return W; }
    int height() const { return H; }
};

template<class T>
class array3 : public std::vector<T>
{
private:
    int W, H, D;

protected:
    array3() { }

public:
    array3(int w, int h, int d) : std::vector<T>(w*h*d), W(w), H(h), D(d) { }

    T& operator()(int i, int j, int k) { return (*this)[k*W*H + j*W+i]; }
    const T& operator()(int i,int j,int k) const {return (*this)[k*W*H+j*W+i];}

    int width() const { return W; }
    int height() const { return H; }
    int depth() const { return D; }
};

} // namespace gfx

// GFXARRAY_INCLUDED
#endif