Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
array2d_impl.h
Go to the documentation of this file.
1 
2 #include <type_traits>
3 
4 namespace frechet { namespace data {
5 
6 template<class T>
8  delete[] d;
9  const_cast<int&>(n)=that.n;
10  const_cast<int&>(m)=that.m;
11  const_cast<T*&>(d) = new T[n*m];
12  copy(const_cast<T*&>(d),that.d,n*m);
13  return *this;
14 }
15 
16 template<class T>
18  delete[] d;
19  const_cast<int&>(n)=that.n;
20  const_cast<int&>(m)=that.m;
21  const_cast<T*&>(d)=that.d;
22  that.d=NULL;
23  return *this;
24 }
25 
26 template<class T>
27 Array2D<T>::Array2D(int an, int am) : n(an), m(am), d(NULL)
28 {
29  Q_ASSERT(n>=0 && m>=0);
30  if (n > 0 && m > 0)
31  d = new T[n*m];
32 }
33 
34 template<class T>
35 Array2D<T>::Array2D(Array2D&& that) : n(that.n), m(that.m), d(that.d)
36 {
37  that.d=NULL;
38 }
39 
40 template<class T>
41 Array2D<T>::Array2D(const Array2D& that) : n(that.n), m(that.m), d(new T[that.n*that.m])
42 {
43  copy(d,that.d,n*m);
44 }
45 
46 template<class T>
48 {
49  delete[] d;
50 }
51 
52 template<class T>
53 void Array2D<T>::copy(T* d, T* thatd, int count) {
54  // if T is copyable
55  if (std::is_trivially_copyable<T>()) {
56  memcpy(d,thatd, sizeof(T)*count);
57  }
58  else {
59  while(count-- > 0)
60  *d++ = *thatd++;
61  }
62 }
63 
64 } } // namespace
T * d
array data
Definition: array2d.h:22
global definitions for all algorithms.
Array2D & operator=(const Array2D &that)
assignment operator
Definition: array2d_impl.h:7
Array2D(int an=0, int am=0)
default constructor
Definition: array2d_impl.h:27
A simple two-dimensional array of fixed size.
Definition: array2d.h:19
const int m
number of rows
Definition: array2d.h:27
const int n
number of columns
Definition: array2d.h:25