5
// Default/length/array constructor
6
Array1::Array1(int length, long* data) :
7
_ownData(false), _length(0), _buffer(0)
13
Array1::Array1(const Array1 & source) :
14
_length(source._length)
26
// Assignment operator
27
Array1 & Array1::operator=(const Array1 & source)
29
int len = _length < source._length ? _length : source._length;
30
for (int i=0; i < len; ++i)
32
(*this)[i] = source[i];
38
bool Array1::operator==(const Array1 & other) const
40
if (_length != other._length) return false;
41
for (int i=0; i < _length; ++i)
43
if ((*this)[i] != other[i]) return false;
49
int Array1::length() const
55
void Array1::resize(int length, long* data)
57
if (length < 0) throw std::invalid_argument("Array1 length less than 0");
58
if (length == _length) return;
73
long & Array1::operator[](int i)
75
if (i < 0 || i >= _length) throw std::out_of_range("Array1 index out of range");
80
const long & Array1::operator[](int i) const
82
if (i < 0 || i >= _length) throw std::out_of_range("Array1 index out of range");
87
std::string Array1::asString() const
89
std::stringstream result;
91
for (int i=0; i < _length; ++i)
93
result << " " << _buffer[i];
94
if (i < _length-1) result << ",";
101
void Array1::view(long** data, int* length) const
108
void Array1::allocateMemory()
118
_buffer = new long[_length];
122
void Array1::deallocateMemory()
124
if (_ownData && _length && _buffer)