30 #ifndef CASA_ARRAY_2_H
31 #define CASA_ARRAY_2_H
42 #include <initializer_list>
43 #include <type_traits>
223 template<
typename InputIterator>
253 template<
typename Callable>
296 template<
typename MaskAlloc>
304 template<
typename MaskAlloc>
342 return copy(Alloc());
427 size_t resizePercentage = 0,
428 bool resizeIfNeeded =
true);
442 size_t resizePercentage = 0,
443 bool resizeIfNeeded =
true);
472 bool throwIfError=
true);
482 bool throwIfError=
true);
592 virtual bool ok()
const override;
676 std::unique_ptr<ArrayPositionIterator>
makeIterator(
size_t byDim)
const override;
713 {
return const_cast<T*
>(
itsPos); }
716 { os << iter.
itsPos;
return os; }
765 {
return *this->
getPos(); }
767 {
return this->
getPos(); }
888 template<
typename Integral>
894 template<
typename InputIterator>
905 throw ArrayError(
"Can not assign from non-copyable object");
910 throw ArrayError(
"Can not coy from non-copyable object");
923 template<
typename ST,
typename SAlloc>
946 std::string(
"Invalid size given to ") +
typeid(*this).name() +
962 throw ArrayError(
"ArrayBase& has incorrect template type");
980 std::shared_ptr<arrays_internal::Storage<T, Alloc>>
data_p;
1004 template<
typename T,
typename Alloc>
1011 extern template class Array<bool, std::allocator<bool>>;
1012 extern template class Array<char, std::allocator<char>>;
1013 extern template class Array<unsigned char, std::allocator<unsigned char>>;
1014 extern template class Array<short, std::allocator<short>>;
1015 extern template class Array<unsigned short, std::allocator<unsigned short>>;
1016 extern template class Array<int, std::allocator<int>>;
1017 extern template class Array<long long, std::allocator<long long>>;
1018 extern template class Array<float, std::allocator<float>>;
1019 extern template class Array<double, std::allocator<double>>;
1024 #include "Array.tcc"
Non-templated base class for templated Array class.
const IPosition & shape() const
The length of each axis.
size_t ndim() const
The dimensionality of this array.
size_t nels_p
Number of elements in the array.
bool contiguous_p
Are the data contiguous?
void baseMakeSteps()
Make the indexing step sizes.
IPosition length_p
Used to hold the shape, increment into the underlying storage and originalLength of the array.
IPosition steps_p
Used to hold the step to next element in each dimension.
bool conform2(const ArrayBase &other) const
Are the shapes identical?
Thrown when two arrays have different dimensionality.
bool operator!=(const BaseIteratorSTL &other) const
const Array< T, Alloc > * itsArray
void increment()
Increment iterator for a non-contiguous array.
bool operator==(const BaseIteratorSTL &other) const
BaseIteratorSTL(const Array< T, Alloc > &)
Create the begin const_iterator object for an Array.
friend std::ostream & operator<<(std::ostream &os, const BaseIteratorSTL &iter)
ConstIteratorSTL(const T *end=0)
Create the end const_iterator object for an Array.
ConstIteratorSTL(const IteratorSTL &iter)
Create from a non-const iterator.
std::forward_iterator_tag iterator_category
const value_type & reference
const ConstIteratorSTL & operator++()
const T & operator*() const
ConstIteratorSTL operator++(int)
const value_type * pointer
ptrdiff_t difference_type
ConstIteratorSTL(const Array< T, Alloc > &arr)
Create the begin const_iterator object for an Array.
ptrdiff_t difference_type
std::forward_iterator_tag iterator_category
IteratorSTL operator++(int)
IteratorSTL(Array< T, Alloc > &arr)
Create the begin iterator object for an Array.
const IteratorSTL & operator++()
IteratorSTL(const T *end=0)
Create the end iterator object for an Array.
Array< T, Alloc > & operator=(const MaskedArray< T, Alloc, MaskAlloc > &marray)
Calls assign_conforming().
void resize(const IPosition &newShape, bool copyValues=false) override
Resize the array and optionally copy the values.
virtual size_t fixedDimensionality() const
Subclasses can return their dimensionality.
friend void swap(Array< ST, SAlloc > &left, Array< ST, SAlloc > &right)
void * getVStorage(bool &deleteIt) override
The following functions behave the same as the corresponding getStorage functions in the derived temp...
Array< T, Alloc > diagonals(size_t firstAxis=0, long long diag=0) const
Get the diagonal of each matrix part in the full array.
virtual void takeStorage(const IPosition &shape, T *storage, StorageInitPolicy policy=COPY, const Alloc &allocator=Alloc())
Replace the data values with those in the pointer storage.
virtual void reference(const Array< T, Alloc > &other)
After invocation, this array and other reference the same storage.
void freeVStorage(const void *&storage, bool deleteIt) const override
T * getStorage(bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar.
size_t capacity() const
Returns the number of elements allocated.
Array(const IPosition &shape, const T *storage)
Create an Array of a given shape from a pointer.
const_iterator end() const
Alloc allocator_type
Define the STL-style iterator functions (only forward iterator).
void set(const T &value)
Set every element of the array to "value." Also could use the assignment operator which assigns an ar...
void putVStorage(void *&storage, bool deleteAndCopy) override
void checkBeforeResize(const IPosition &newShape)
This function is called when this array is about to be resized, before any work is done.
static struct casacore::Array::uninitializedType uninitialized
void freeStorage(const T *&storage, bool deleteIt) const
If deleteIt is set, delete "storage".
void tovector(std::vector< T, U > &out) const
Create an STL vector from an Array.
Array(const IPosition &shape, T *storage, StorageInitPolicy policy=COPY, const Alloc &allocator=Alloc())
Create an Array of a given shape from a pointer.
virtual ~Array() noexcept
Frees up storage only if this array was the last reference to it.
bool adjustLastAxis(const IPosition &newShape, size_t resizePercentage=0, bool resizeIfNeeded=true)
Use this method to extend or reduce the last dimension of an array.
void putStorage(T *&storage, bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
Array< T, Alloc > & assign_conforming_implementation(const Array< T, Alloc > &, std::false_type)
Implementation for assign for non-copyable types: can not be assigned.
Array(const IPosition &shape, Integral startIter, const Alloc &allocator, std::true_type)
Implementation of constructor taking a Shape, a Templated parameter and an allocator.
const Array< T, Alloc > addDegenerate(size_t numAxes) const
This member function returns an Array reference with the specified number of extra axes,...
void copyMatchingPart(const Array< T, Alloc > &from)
This function copies the matching part of from array to this array.
T & operator()(const IPosition &)
Access a single element of the array.
static void copyToContiguousStorage(T *dst, Array< T, Alloc > const &src)
Array(const Alloc &allocator=Alloc())
Result has dimensionality of zero, and nelements is zero.
virtual std::unique_ptr< ArrayBase > makeArray() const override
Make an empty array of the same template type.
Array< T, Alloc > operator()(const IPosition &start, const IPosition &end, const IPosition &inc)
Along the ith axis, every inc[i]'th element is chosen.
void apply(Callable function)
Apply the function to every element of the array.
Array< T, Alloc > nonDegenerate(const IPosition &ignoreAxes) const
std::vector< T > tovector() const
virtual void postTakeStorage()
const T & operator()(const IPosition &) const
const Array< T, Alloc > operator()(const Slicer &) const
Array< T, Alloc > nonDegenerate(size_t startingAxis=0, bool throwIfError=true) const
These member functions remove degenerate (ie.
Array(Array< T, Alloc > &&source, const IPosition &shapeForSource) noexcept
Source will be empty with given shape after this call.
void removeDegenerate(const IPosition &ignoreAxes)
bool conform(const MaskedArray< T > &other) const
Array< T, Alloc > & operator=(const T &value)
Set every element of this array to "value".
void resize()
Make this array a different shape.
T * pointer
Pointer to an element type.
contiter cbegin()
Get the begin iterator object for a contiguous array.
void swap(Array< T, Alloc > &other)
Swap this array with another array.
Array(std::initializer_list< T > list, const Alloc &allocator=Alloc())
Construct a one-dimensional array from an initializer list.
Array(const IPosition &shape, InputIterator startIter, const Alloc &allocator=Alloc())
Construct an array from an iterator and a shape.
T value_type
Element type.
Array< T, Alloc > addDegenerate(size_t numAxes)
Array< T, Alloc > copy(const Alloc &allocator) const
Makes a copy using the allocator.
T * begin_p
This pointer is adjusted to point to the first element of the array.
Array< T, Alloc > copy() const
This makes a copy of the array and returns it.
std::unique_ptr< ArrayBase > getSection(const Slicer &) const override
Get a reference to a section of an array.
Array(const IPosition &shape, uninitializedType, const Alloc &allocator=Alloc())
Constructor to create an uninitialized array.
const_contiter cbegin() const
Array< T, Alloc > operator()(const Slicer &)
Get a reference to an array section using a Slicer.
Array(const IPosition &shape, const T &initialValue, const Alloc &allocator=Alloc())
Create an array of the given shape and initialize it with the initial value.
const void * getVStorage(bool &deleteIt) const override
const T * getStorage(bool &deleteIt) const
virtual void doNonDegenerate(const Array< T, Alloc > &other, const IPosition &ignoreAxes)
Remove the degenerate axes from the Array object.
const Array< T, Alloc > operator()(const IPosition &start, const IPosition &end) const
iterator begin()
Get the begin iterator object for any array.
void assign(const Array< T, Alloc > &other)
Assign the other array to this array.
const T & const_reference
TODO This is how std containers define a reference type, but the name 'reference' is already taken by...
void unique()
This ensures that this array does not reference any other storage.
Array(const IPosition &shape, InputIterator startIter, const Alloc &allocator, std::false_type)
Implementation of constructor taking a Shape, a Templated parameter and an allocator.
Array< T, Alloc > & assign_conforming_implementation(const Array< T, Alloc > &other, std::true_type)
Implementation for assign for copyable types.
const_contiter cend() const
Array(Array< T, Alloc > &&source) noexcept
Source will be empty after this call.
Array< T, Alloc > operator()(const IPosition &start, const IPosition &end)
Get a reference to an array section extending from start to end (inclusive).
const T * const_pointer
Constant pointer to the element type.
Array(const IPosition &shape, const Alloc &allocator=Alloc())
Create an array of the given shape, i.e.
virtual void checkAssignableType(ArrayBase &arrayBase) const
void nonDegenerate(const Array< T, Alloc > &other, size_t startingAxis=0, bool throwIfError=true)
const Array< T, Alloc > operator()(const IPosition &start, const IPosition &end, const IPosition &inc) const
Array< T, Alloc > operator[](size_t i) const
Get the subset given by the i-th value of the last axis.
T * end_p
The end for an STL-style iteration.
Alloc & allocator()
Retrieve the allocator associated with this array.
bool conform(const Array< T, Alloc > &other) const
Are the shapes identical?
void setEndIter()
Set the end iterator.
bool reformOrResize(const IPosition &newShape, size_t resizePercentage=0, bool resizeIfNeeded=true)
Having an array that can be reused without requiring reallocation can be useful for large arrays.
void assignBase(const ArrayBase &other, bool checkType=true) override
Assign the source array to this array.
void removeDegenerate(size_t startingAxis=0, bool throwIfError=true)
Remove degenerate axes from this Array object.
Array< T, Alloc > & operator=(const Array< T, Alloc > &other)
TODO we should change the semantics.
size_t nrefs() const
The number of references the underlying storage has assigned to it.
static void copyToContiguousStorage(T *, Array< T, Alloc > const &, std::false_type)
T * data()
Get a pointer to the beginning of the array.
std::shared_ptr< arrays_internal::Storage< T, Alloc > > data_p
Shared pointer to a Storage that contains the data.
Array< T, Alloc > & operator=(Array< T, Alloc > &&other)
The move operator takes the storage from the given array.
static void copyToContiguousStorage(T *dst, Array< T, Alloc > const &src, std::true_type)
virtual void preTakeStorage(const IPosition &)
pre/post processing hook of takeStorage() for subclasses.
Array< T, Alloc > reform(const IPosition &shape) const
It is occasionally useful to have an array which access the same storage appear to have a different s...
const Alloc & allocator() const
Array< T, Alloc > & assign_conforming(const MaskedArray< T, Alloc, MaskAlloc > &marray)
Copy to this those values in marray whose corresponding elements in marray's mask are true.
Array< T, Alloc > & assign_conforming(const Array< T, Alloc > &other)
Copy the values in other to this.
void makeSteps()
Fill the steps and the end for a derived class.
std::unique_ptr< ArrayPositionIterator > makeIterator(size_t byDim) const override
Create an ArrayIterator object of the correct type.
virtual bool ok() const override
Check to see if the Array is consistent.
void nonDegenerate(const Array< T, Alloc > &other, const IPosition &ignoreAxes)
const_iterator begin() const
bool isUnique() const
An Array is unique when the container is shared and when nrefs==1.
Array(const Array< T, Alloc > &other)
After construction, this and other reference the same storage.
ConstIteratorSTL const_iterator
@ COPY
COPY is used when an internal copy of the storage is to be made.
const Double second
Time interval [T]:
this file contains all the compiler specific defines
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
std::string to_string(const IPosition &ip)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
TableExprNode marray(const TableExprNode &array, const TableExprNode &mask)
Form a masked array.
void swap(Array< T, Alloc > &first, Array< T, Alloc > &second)
Swap the first array with the second.
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
This is a tag for the constructor that may be used to construct an uninitialized Array.