33 #ifndef __H__UG_field_impl__
34 #define __H__UG_field_impl__
51 Field(
size_t width,
size_t height) :
55 m_capacity = m_width * m_height;
56 m_data =
new T[m_capacity];
60 Field(
size_t width,
size_t height,
const T& value) :
73 m_capacity = m_width * m_height;
74 m_data =
new T[m_capacity];
75 memcpy(m_data, f.
data(), m_capacity *
sizeof(T));
88 if(m_data && (m_capacity != m_width * m_height)){
92 m_capacity = m_width * m_height;
94 m_data =
new T[m_capacity];
95 memcpy(m_data, f.
data(), m_capacity *
sizeof(T));
102 if(width * height > m_capacity){
105 m_capacity += width * height;
106 m_data =
new T[m_capacity];
113 at(
size_t x,
size_t y){
114 return m_data[array_index(x, y)];
118 at(
size_t x,
size_t y)
const{
119 return m_data[array_index(x, y)];
123 fill(
size_t x,
size_t y,
size_t w,
size_t h,
const T& value)
128 const size_t xEnd = max(x + w, m_width);
129 const size_t yEnd = max(y + h, m_height);
131 for(
size_t iy = max(y,
size_t(0)); iy < yEnd; ++iy){
132 for(
size_t ix = max(x,
size_t(0)); ix < xEnd; ++ix){
133 m_data[array_index(ix, iy)] = value;
141 const size_t dataSize = size();
142 for(
size_t i = 0; i < dataSize; ++i)
147 copy(
size_t x,
size_t y,
const Field& f){
151 const size_t xEnd = max(x + f.
width(), m_width);
152 const size_t yEnd = max(y + f.
height(), m_height);
154 for(
size_t iy = max(y,
size_t(0)); iy < yEnd; ++iy){
155 for(
size_t ix = max(x,
size_t(0)); ix < xEnd; ++ix){
156 m_data[array_index(ix, iy)] = f.
at(ix, iy);
173 return x + y * m_width;
178 template <
class Archive>
180 save( Archive& ar,
const unsigned int version)
const
184 const size_t s = size();
185 for(
size_t i = 0; i <
s; ++i){
191 template <
class Archive>
193 load( Archive& ar,
const unsigned int version)
198 resize_no_copy(w, h);
199 const size_t s = size();
200 for(
size_t i = 0; i <
s; ++i){
size_t width() const
Definition: field.h:57
T * m_data
Definition: field.h:87
size_t m_height
Definition: field.h:85
~Field()
Definition: field_impl.hpp:79
T & at(size_t x, size_t y)
Definition: field_impl.hpp:113
void save(Archive &ar, const unsigned int version) const
Definition: field_impl.hpp:180
void copy(size_t x, size_t y, const Field &f)
Definition: field_impl.hpp:147
size_t array_index(size_t x, size_t y) const
Definition: field_impl.hpp:172
size_t m_width
Definition: field.h:84
void fill_all(const T &value)
Definition: field_impl.hpp:139
size_t height() const
Definition: field.h:58
void fill(size_t x, size_t y, size_t w, size_t h, const T &value)
Definition: field_impl.hpp:123
Field()
Definition: field_impl.hpp:42
T * data()
Definition: field.h:61
size_t m_capacity
Definition: field.h:86
void load(Archive &ar, const unsigned int version)
Definition: field_impl.hpp:193
void swap(Field &f)
Definition: field_impl.hpp:162
void resize_no_copy(size_t width, size_t height)
Definition: field_impl.hpp:100
Field & operator=(const Field &field)
Definition: field_impl.hpp:85