LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Array.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef NDARRAY_Array_h_INCLUDED
24 #define NDARRAY_Array_h_INCLUDED
25 
32 #include "ndarray_fwd.h"
33 #include "ndarray/ArrayTraits.h"
34 #include "ndarray/ArrayBaseN.h"
35 #include "ndarray/Vector.h"
36 #include "ndarray/detail/Core.h"
37 #include "ndarray/views.h"
38 
39 namespace ndarray {
40 
46 template <typename T, int N, int C>
47 class Array : public ArrayBaseN< Array<T,N,C> > {
49  typedef typename Super::Core Core;
50  typedef typename Super::CorePtr CorePtr;
51 public:
52 
58  Array() : Super(0, Core::create()) {}
59 
63  Array(Array const & other) : Super(other._data, other._core) {}
64 
71  template <typename T_, int C_>
73  Array<T_,N,C_> const & other
74 #ifndef DOXYGEN
75  , typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>,void*>::type=0
76 #endif
77  ) : Super(other._data, other._core) {}
78 
85  template <typename T_, int C_>
87  ArrayRef<T_,N,C_> const & other
88 #ifndef DOXYGEN
89  , typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>,void*>::type=0
90 #endif
91  ) : Super(other._data, other._core) {}
92 
96  Array & operator=(Array const & other) {
97  if (&other != this) {
98  this->_data = other._data;
99  this->_core = other._core;
100  }
101  return *this;
102  }
103 
110  template <typename T_, int C_>
111 #ifndef DOXYGEN
112  typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>, Array &>::type
113 #else
114  Array &
115 #endif
116  operator=(Array<T_,N,C_> const & other) {
117  this->_data = other._data;
118  this->_core = other._core;
119  return *this;
120  }
121 
128  template <typename T_, int C_>
129 #ifndef DOXYGEN
130  typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>, Array &>::type
131 #else
132  Array &
133 #endif
134  operator=(ArrayRef<T_,N,C_> const & other) {
135  this->_data = other._data;
136  this->_core = other._core;
137  return *this;
138  }
139 
144  template <typename T_, int N_, int C_>
145  bool operator==(Array<T_,N_,C_> const & other) const {
146  return this->getData() == other.getData()
147  && this->getShape() == other.getShape()
148  && this->getStrides() == other.getStrides();
149  }
150 
154  template <typename T_, int N_, int C_>
155  bool operator!=(Array<T_,N_,C_> const & other) const {
156  return !this->operator==(other);
157  }
158 
160  void swap(Array & other) {
161  std::swap(this->_data, other._data);
162  this->_core.swap(other._core);
163  }
164 
172  bool isUnique() const { return this->_core->isUnique(); }
173 
174 private:
175  template <typename T_, int N_, int C_> friend class Array;
176  template <typename T_, int N_, int C_> friend class ArrayRef;
177  template <typename T_, int N_, int C_> friend struct ArrayTraits;
178  template <typename Derived> friend class ArrayBase;
179  template <typename Array_> friend class detail::ArrayAccess;
180 
182  Array(T * data, CorePtr const & core) : Super(data, core) {}
183 };
184 
185 } // namespace ndarray
186 
187 #endif // !NDARRAY_Array_h_INCLUDED
A proxy class for Array with deep assignment operators.
Definition: ArrayRef.h:46
Dimension-specialized traits shared by Array and ArrayRef.
Definition: ArrayTraits.h:56
Definition for Vector.
Index getStrides() const
Return a Vector of the strides of all dimensions.
Definition: ArrayBase.h:139
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:291
Array(Array const &other)
Non-converting copy constructor.
Definition: Array.h:63
void swap(Array &other)
Lightweight shallow swap.
Definition: Array.h:160
Super::CorePtr CorePtr
Definition: Array.h:50
Traits for Array.
ArrayBaseN< Array > Super
Definition: Array.h:48
Traits::Core Core
Definition: ArrayBase.h:59
bool operator!=(Array< T_, N_, C_ > const &other) const
Shallow inequality comparison.
Definition: Array.h:155
Array(Array< T_, N, C_ > const &other)
Converting copy constructor.
Definition: Array.h:72
Array & operator=(ArrayRef< T_, N, C_ > const &other)
Converting shallow assignment.
Definition: Array.h:134
Forward declarations and default template parameters for ndarray.
bool isUnique() const
Return true if the Array is definitely unique.
Definition: Array.h:172
Array(ArrayRef< T_, N, C_ > const &other)
Converting copy constructor.
Definition: Array.h:86
Super::Core Core
Definition: Array.h:49
Array(T *data, CorePtr const &core)
Definition: Array.h:182
Index getShape() const
Return a Vector of the sizes of all dimensions.
Definition: ArrayBase.h:136
An intermediate CRTP base class for Array and ArrayRef.
Definition: ArrayBaseN.h:40
bool operator==(Array< T_, N_, C_ > const &other) const
Shallow equality comparison: return true if the arrays share data and have the same shape and strides...
Definition: Array.h:145
CRTP implementation for Array and ArrayRef.
Definition: ArrayBase.h:56
Element * getData() const
Return a raw pointer to the first element of the array.
Definition: ArrayBase.h:117
Traits::CorePtr CorePtr
Definition: ArrayBase.h:60
Array & operator=(Array const &other)
Non-converting shallow assignment.
Definition: Array.h:96
A multidimensional strided array.
Definition: Array.h:47
Array & operator=(Array< T_, N, C_ > const &other)
Converting shallow assignment.
Definition: Array.h:116
Definitions for Core.
Public interface for arbitrary views into arrays.
Definition of ArrayBaseN, a dimension-specialized CRTP base class for Array and ArrayRef.
Array()
Default constructor.
Definition: Array.h:58