YAPOG  0.0.1
Yet Another Pokemon Online Game
Matrix.hxx
Go to the documentation of this file.
1 #ifndef YAPOG_MATRIX_HXX
2 # define YAPOG_MATRIX_HXX
3 
4 namespace yap
5 {
6  namespace collection
7  {
8  template <typename T>
10  SizeType width,
11  SizeType height,
12  const DataType& data)
13  : width_ (width)
14  , height_ (height)
15  , data_ (width_ * height_, data)
16  {
17  }
18 
19  template <typename T>
20  inline Matrix<T>::Matrix (const Matrix<T>& copy)
21  : width_ (copy.width_)
22  , height_ (copy.height_)
23  , data_ (copy.data_)
24  {
25  }
26 
27  template <typename T>
29  {
30  if (&copy == this)
31  return *this;
32 
33  width_ = copy.width_;
34  height_ = copy.height_;
35  data_ = copy.data_;
36 
37  return *this;
38  }
39 
40  template <typename T>
42  {
43  return data_.begin ();
44  }
45 
46  template <typename T>
47  inline typename Matrix<T>::ConstItType Matrix<T>::begin () const
48  {
49  return data_.begin ();
50  }
51 
52  template <typename T>
54  {
55  return begin ();
56  }
57 
58  template <typename T>
59  inline typename Matrix<T>::ConstItType Matrix<T>::Begin () const
60  {
61  return begin ();
62  }
63 
64  template <typename T>
65  inline typename Matrix<T>::ItType Matrix<T>::end ()
66  {
67  return data_.end ();
68  }
69 
70  template <typename T>
71  inline typename Matrix<T>::ConstItType Matrix<T>::end () const
72  {
73  return data_.end ();
74  }
75 
76  template <typename T>
77  inline typename Matrix<T>::ItType Matrix<T>::End ()
78  {
79  return end ();
80  }
81 
82  template <typename T>
83  inline typename Matrix<T>::ConstItType Matrix<T>::End () const
84  {
85  return end ();
86  }
87 
88  template <typename T>
89  inline void Matrix<T>::Resize (
90  SizeType width,
91  SizeType height,
92  const T& data)
93  {
94  Matrix<T> resized (width, height, data);
95 
96  for (SizeType y = 0; y < height_; ++y)
97  for (SizeType x = 0; x < width_; ++x)
98  resized (x, y) = this->operator() (x, y);
99 
100  *this = resized;
101  }
102 
103  template <typename T>
104  inline void Matrix<T>::Set (SizeType x, SizeType y, const T& data)
105  {
106  data_[GetIndex (x, y)] = data;
107  }
108 
109  template <typename T>
110  inline const T& Matrix<T>::operator() (SizeType x, SizeType y) const
111  {
112  return data_[GetIndex (x, y)];
113  }
114 
115  template <typename T>
117  {
118  return data_[GetIndex (x, y)];
119  }
120 
121  template <typename T>
123  SizeType x,
124  SizeType y) const
125  {
126  return y * width_ + x;
127  }
128  } // collection
129 } // namespace yap
130 
131 #endif // YAPOG_MATRIX_HXX