78 lines
1.1 KiB
C++
78 lines
1.1 KiB
C++
|
/*
|
||
|
* Array2.cpp
|
||
|
*
|
||
|
* Created on: May 5, 2013
|
||
|
* Author: chibi_000
|
||
|
*/
|
||
|
|
||
|
#include "Array2.h"
|
||
|
#include <cstring>
|
||
|
|
||
|
Array2::Array2(int w, int h)
|
||
|
{
|
||
|
this->w = w;
|
||
|
this->h = h;
|
||
|
this->data = new int[w * h];
|
||
|
|
||
|
memset(this->data, 0, w * h * sizeof(int));
|
||
|
}
|
||
|
|
||
|
Array2::Array2(int w, int h, const int* vals)
|
||
|
{
|
||
|
this->w = w;
|
||
|
this->h = h;
|
||
|
this->data = new int[w * h];
|
||
|
|
||
|
memcpy(this->data, vals, w * h * sizeof(int));
|
||
|
}
|
||
|
|
||
|
Array2::Array2(const Array2& a)
|
||
|
{
|
||
|
this->w = a.w;
|
||
|
this->h = a.h;
|
||
|
this->data = new int[w * h];
|
||
|
|
||
|
memcpy(this->data, a.data, w * h * sizeof(int));
|
||
|
}
|
||
|
|
||
|
Array2& Array2::operator= (const Array2& a)
|
||
|
{
|
||
|
if (this != &a)
|
||
|
{
|
||
|
delete this->data;
|
||
|
|
||
|
this->w = a.w;
|
||
|
this->h = a.h;
|
||
|
this->data = new int[w * h];
|
||
|
|
||
|
memcpy(this->data, a.data, w * h * sizeof(int));
|
||
|
}
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
Array2::~Array2()
|
||
|
{
|
||
|
delete this->data;
|
||
|
}
|
||
|
|
||
|
int Array2::get(int x, int y) const
|
||
|
{
|
||
|
return this->data[y * this->w + x];
|
||
|
}
|
||
|
|
||
|
void Array2::set(int x, int y, int value)
|
||
|
{
|
||
|
this->data[y * this->w + x] = value;
|
||
|
}
|
||
|
|
||
|
int Array2::getWidth() const
|
||
|
{
|
||
|
return this->w;
|
||
|
}
|
||
|
|
||
|
int Array2::getHeight() const
|
||
|
{
|
||
|
return this->h;
|
||
|
}
|