-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmulti_array.cpp
73 lines (63 loc) · 2.31 KB
/
multi_array.cpp
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
71
72
73
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "multi_array.h"
#include "clcontextloader.h"
template<class _T>
BidimArray<_T>& BidimArray<_T>::operator=(const BidimArray& r)
{
if (m_dimx*m_dimy != r.m_dimx*r.m_dimy)
{
delete []_data;
_data = reinterpret_cast<_T*>(new char [sizeof (_T)*r.m_dimx*r.m_dimy]);
std::uninitialized_copy(r._data,r._data+r.m_dimx*r.m_dimy,_data);
}
else
std::copy(r._data,r._data+r.m_dimx*r.m_dimy,_data);
m_dimx = r.m_dimx;
m_dimy = r.m_dimy;
return *this;
}
template<class _T>
BidimArray<_T>::BidimArray(const BidimArray & r) : m_dimx(r.m_dimx),m_dimy(r.m_dimy),_data(
reinterpret_cast<_T*>(new char [sizeof(_T)*m_dimx*m_dimy]))
{
std::uninitialized_copy(r._data,r._data+m_dimx*m_dimy,_data);
}
template<class _T>
TridimArray<_T>& TridimArray<_T>::operator=(const TridimArray& r)
{
if (m_dimx*m_dimy*m_dimz != r.m_dimx*r.m_dimy*r.m_dimz)
{
delete []_data;
_data = reinterpret_cast<_T*>(new char [sizeof (_T)*r.m_dimx*r.m_dimy*m_dimz]);
std::uninitialized_copy(r._data,r._data+r.m_dimx*r.m_dimy*m_dimz,_data);
}
else
std::copy(r._data,r._data+r.m_dimx*r.m_dimy*r.m_dimz,_data);
m_dimx = r.m_dimx;
m_dimy = r.m_dimy;
m_dimz = r.m_dimz;
return *this;
}
template<class _T>
TridimArray<_T>::TridimArray(const TridimArray & r) : m_dimx(r.m_dimx),m_dimy(r.m_dimy),m_dimz(r.m_dimz),
_data(reinterpret_cast<_T*>(new char [sizeof(_T)*m_dimx*m_dimy*m_dimz]))
{
std::uninitialized_copy(r._data,r._data+m_dimx*m_dimy*m_dimz,_data);
}
template class BidimArray<real>;
template class TridimArray<real>;
template class BidimArray<char>;
template class TridimArray<char>;