23 #ifndef NDARRAY_DETAIL_Core_h_INCLUDED
24 #define NDARRAY_DETAIL_Core_h_INCLUDED
32 #include <boost/intrusive_ptr.hpp>
33 #include <boost/mpl/int.hpp>
61 typedef boost::mpl::int_<N>
ND;
63 typedef boost::intrusive_ptr<Core>
Ptr;
64 typedef boost::intrusive_ptr<Core const>
ConstPtr;
73 return Ptr(
new Core(shape, strides, manager),
false);
84 return Ptr(
new Core(shape, manager),
false);
86 return Ptr(
new Core(shape, 1, manager),
false);
94 return Ptr(
new Core(manager),
false);
159 ) :
Super(shape, stride * shape[M-N], manager),
_size(shape[M-N]),
_stride(stride) {}
185 typedef boost::mpl::int_<0>
ND;
186 typedef boost::intrusive_ptr<Core>
Ptr;
194 if ((--core->_rc)==0)
delete core;
227 bool isUnique()
const {
return (_rc == 1) && (_manager->getRC() == 1) && _manager->isUnique(); }
238 ) : _manager(manager), _rc(1) {}
244 ) : _manager(manager), _rc(1) {}
251 ) : _manager(manager), _rc(1) {}
255 ) : _manager(manager), _rc(1) {}
257 Core(
Core const & other) : _manager(other._manager), _rc(1) {}
270 template <
int P,
int N>
271 inline Core<N-P>
const &
279 template <
int P,
int N>
280 inline typename Core<N-P>::Ptr
286 #endif // !NDARRAY_DETAIL_Core_h_INCLUDED
static Ptr create(Vector< int, M > const &shape, Vector< int, M > const &strides, Manager::Ptr const &manager=Manager::Ptr())
Create a Core::Ptr with the given shape, strides, and manager.
Manager::Ptr getManager() const
Return the Manager that determines the lifetime of the array data.
Core(Vector< int, M > const &shape, Manager::Ptr const &manager)
int getNumElements() const
Recursively determine the total number of elements.
int getStride() const
Return the stride of the Nth dimension.
int getSize() const
Return the size of the Nth dimension.
Core(Vector< int, M > const &shape, int stride, Manager::Ptr const &manager)
int getRC() const
Return the reference count (for debugging purposes).
Core(Vector< int, M > const &shape, int stride, Manager::Ptr const &manager)
bool isUnique() const
Return true if the Core and Manager reference counts are 1 and the manager is unique.
boost::intrusive_ptr< Core > Ptr
intrusive_ptr to Core
boost::mpl::int_< N > ND
number of dimensions
boost::intrusive_ptr< Core > Ptr
Definition of Manager, which manages the ownership of array data.
void setManager(Manager::Ptr const &manager)
Set the Manager that determines the lifetime of the array data.
boost::intrusive_ptr< Core const > ConstPtr
const intrusive_ptr to Core
int computeOffset(Vector< int, M > const &index) const
Recursively compute the offset to an element.
Core(Manager::Ptr const &manager)
void fillShape(Vector< int, M > const &shape) const
Recursively fill a shape vector.
Core< N-P > const & getDimension(Core< N > const &core)
Core(Vector< int, M > const &shape, Vector< int, M > const &strides, Manager::Ptr const &manager)
static Ptr create(Vector< int, M > const &shape, DataOrderEnum order, Manager::Ptr const &manager=Manager::Ptr())
Create a Core::Ptr with the given shape and manager with contiguous strides.
static Ptr create(Manager::Ptr const &manager=Manager::Ptr())
Create a Core::Ptr with the given manager and zero shape and strides.
A fixed-size 1D array class.
boost::intrusive_ptr< Manager > Ptr
void setStride(int stride)
Set the stride of the Nth dimension.
Core(Manager::Ptr const &manager)
int computeOffset(Vector< int, M > const &index) const
Recursively compute the offset to an element.
Core(Vector< int, M > const &shape, Vector< int, M > const &strides, Manager::Ptr const &manager)
void setSize(int size)
Set the size of the Nth dimension.
Core(Vector< int, M > const &shape, Manager::Ptr const &manager)
DataOrderEnum
An enumeration for stride computation.
void fillStrides(Vector< int, M > &strides) const
Recursively fill a strides vector.
void fillShape(Vector< int, M > &shape) const
Recursively fill a shape vector.
int getNumElements() const
Recursively determine the total number of elements.
friend void intrusive_ptr_release(Core const *core)
Core< N-1 > Super
base class
friend void intrusive_ptr_add_ref(Core const *core)
void fillStrides(Vector< int, M > const &strides) const
Recursively fill a strides vector.
boost::intrusive_ptr< Core const > ConstPtr