30 #ifndef CASA_ARRAY_2_H
31 #define CASA_ARRAY_2_H
42 #include <initializer_list>
43 #include <type_traits>
195 Array(std::initializer_list<T> list,
const Alloc&
allocator = Alloc());
223 template<typename InputIterator>
227 virtual ~
Array() noexcept;
253 template<
typename Callable>
254 void apply(Callable
function);
296 template<
typename MaskAlloc>
304 template<
typename MaskAlloc>
342 return copy(Alloc());
381 void tovector(std::vector<T, U>& out)
const;
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);
512 void resize(
const IPosition &newShape,
bool copyValues=
false)
override;
587 size_t nrefs()
const;
592 virtual bool ok()
const override;
638 const void *
getVStorage(
bool &deleteIt)
const override;
643 void putStorage(T *&storage,
bool deleteAndCopy);
644 void putVStorage(
void *&storage,
bool deleteAndCopy)
override;
651 void freeStorage(
const T *&storage,
bool deleteIt)
const;
652 void freeVStorage(
const void *&storage,
bool deleteIt)
const override;
676 std::unique_ptr<ArrayPositionIterator>
makeIterator(
size_t byDim)
const override;
681 class BaseIteratorSTL
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"
const Array< T, Alloc > * itsArray
A Vector of integers, for indexing into Array<T> objects.
bool conform2(const ArrayBase &other) const
Are the shapes identical?
void set(const T &value)
Set every element of the array to "value." Also could use the assignment operator which assigns an ar...
void * getVStorage(bool &deleteIt) override
The following functions behave the same as the corresponding getStorage functions in the derived temp...
T * pointer
Pointer to an element type.
void increment()
Increment iterator for a non-contiguous array.
const ConstIteratorSTL & operator++()
void checkBeforeResize(const IPosition &newShape)
This function is called when this array is about to be resized, before any work is done...
Non-templated base class for templated Array class.
const IteratorSTL & operator++()
bool contiguous_p
Are the data contiguous?
This is a tag for the constructor that may be used to construct an uninitialized Array.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
IteratorSTL operator++(int)
IteratorSTL(Array< T, Alloc > &arr)
Create the begin iterator object for an Array.
IPosition steps_p
Used to hold the step to next element in each dimension.
Array< T, Alloc > & operator=(const Array< T, Alloc > &other)
TODO we should change the semantics.
const T & operator*() const
static struct casacore::Array::uninitializedType uninitialized
const_iterator begin() const
StorageInitPolicy
A global enum used by some Array constructors.
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...
Array(const Alloc &allocator=Alloc())
Result has dimensionality of zero, and nelements is zero.
size_t nels_p
Number of elements in the array.
Array< T, Alloc > diagonals(size_t firstAxis=0, long long diag=0) const
Get the diagonal of each matrix part in the full array.
The base class for all Array exception classes.
void putStorage(T *&storage, bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
See the function begin() and end() for a detailed description of the STL iterator capability...
virtual std::unique_ptr< ArrayBase > makeArray() const override
Make an empty array of the same template type.
const value_type & reference
virtual size_t fixedDimensionality() const
Subclasses can return their dimensionality.
TableExprNode marray(const TableExprNode &array, const TableExprNode &mask)
Form a masked array.
size_t ndim() const
The dimensionality of this array.
void makeSteps()
Fill the steps and the end for a derived class.
T * end_p
The end for an STL-style iteration.
ptrdiff_t difference_type
size_t nrefs() const
The number of references the underlying storage has assigned to it.
friend std::ostream & operator<<(std::ostream &os, const BaseIteratorSTL &iter)
const_contiter cend() const
Iterate an Array cursor through another Array.
IPosition length_p
Used to hold the shape, increment into the underlying storage and originalLength of the array...
void copyMatchingPart(const Array< T, Alloc > &from)
This function copies the matching part of from array to this array.
Array< T, Alloc > operator[](size_t i) const
Get the subset given by the i-th value of the last axis.
friend void swap(Array< ST, SAlloc > &left, Array< ST, SAlloc > &right)
Class for masking an Array for operations on that Array.
const T * const_pointer
Constant pointer to the element type.
T & operator()(const IPosition &)
Access a single element of the array.
static void copyToContiguousStorage(T *dst, Array< T, Alloc > const &src, std::true_type)
bool operator!=(const BaseIteratorSTL &other) const
void assign(const Array< T, Alloc > &other)
Assign the other array to this array.
BaseIteratorSTL(const Array< T, Alloc > &)
Create the begin const_iterator object for an Array.
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
void freeStorage(const T *&storage, bool deleteIt) const
If deleteIt is set, delete "storage".
Array< T, Alloc > nonDegenerate(size_t startingAxis=0, bool throwIfError=true) const
These member functions remove degenerate (ie.
std::forward_iterator_tag iterator_category
void assignBase(const ArrayBase &other, bool checkType=true) override
Assign the source array to this array.
ConstIteratorSTL operator++(int)
ConstIteratorSTL(const T *end=0)
Create the end const_iterator object for an Array.
T * begin_p
This pointer is adjusted to point to the first element of the array.
void removeDegenerate(size_t startingAxis=0, bool throwIfError=true)
Remove degenerate axes from this Array object.
std::string to_string(const IPosition &ip)
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...
Alloc & allocator()
Retrieve the allocator associated with this array.
const Array< T, Alloc > addDegenerate(size_t numAxes) const
This member function returns an Array reference with the specified number of extra axes...
Array< T, Alloc > copy() const
This makes a copy of the array and returns it.
void swap(Array< T, Alloc > &first, Array< T, Alloc > &second)
Swap the first array with the second.
Array< T, Alloc > & assign_conforming_implementation(const Array< T, Alloc > &other, std::true_type)
Implementation for assign for copyable types.
void nonDegenerate(const Array< T, Alloc > &other, const IPosition &ignoreAxes)
const_contiter cbegin() const
std::shared_ptr< arrays_internal::Storage< T, Alloc > > data_p
Shared pointer to a Storage that contains the data.
bool isUnique() const
An Array is unique when the container is shared and when nrefs==1.
A templated N-D Array class with zero origin. Array<T, Alloc> is a templated, N-dimensional, Array class. The origin is zero, but by default indices are zero-based. This Array class is the base class for the Vector, Matrix, and Cube subclasses.
void baseMakeSteps()
Make the indexing step sizes.
void freeVStorage(const void *&storage, bool deleteIt) const override
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.
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.
Specify which elements to extract from an n-dimensional array.
const Double second
Time interval [T]:
Array< T, Alloc > & assign_conforming(const Array< T, Alloc > &other)
Copy the values in other to this.
std::vector< T > tovector() const
virtual void doNonDegenerate(const Array< T, Alloc > &other, const IPosition &ignoreAxes)
Remove the degenerate axes from the Array object.
COPY is used when an internal copy of the storage is to be made.
virtual void reference(const Array< T, Alloc > &other)
After invocation, this array and other reference the same storage.
virtual bool ok() const override
Check to see if the Array is consistent.
IteratorSTL(const T *end=0)
Create the end iterator object for an Array.
std::unique_ptr< ArrayBase > getSection(const Slicer &) const override
Get a reference to a section of an array.
ConstIteratorSTL const_iterator
void unique()
This ensures that this array does not reference any other storage.
void setEndIter()
Set the end iterator.
bool conform(const Array< T, Alloc > &other) const
Are the shapes identical?
void resize()
Make this array a different shape.
Array< T, Alloc > & assign_conforming_implementation(const Array< T, Alloc > &, std::false_type)
Implementation for assign for non-copyable types: can not be assigned.
static void copyToContiguousStorage(T *, Array< T, Alloc > const &, std::false_type)
const Alloc & allocator() const
iterator begin()
Get the begin iterator object for any array.
std::forward_iterator_tag iterator_category
Thrown when two arrays have different dimensionality.
T * getStorage(bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar...
void apply(Callable function)
Apply the function to every element of the array.
contiter cbegin()
Get the begin iterator object for a contiguous array.
const value_type * pointer
virtual void checkAssignableType(ArrayBase &arrayBase) const
Array< T, Alloc > & operator=(const MaskedArray< T, Alloc, MaskAlloc > &marray)
Calls assign_conforming().
static void copyToContiguousStorage(T *dst, Array< T, Alloc > const &src)
bool operator==(const BaseIteratorSTL &other) const
const T & const_reference
TODO This is how std containers define a reference type, but the name 'reference' is already taken by...
virtual void preTakeStorage(const IPosition &)
pre/post processing hook of takeStorage() for subclasses.
std::unique_ptr< ArrayPositionIterator > makeIterator(size_t byDim) const override
Create an ArrayIterator object of the correct type.
ConstIteratorSTL(const Array< T, Alloc > &arr)
Create the begin const_iterator object for an Array.
Alloc allocator_type
Define the STL-style iterator functions (only forward iterator).
const_iterator end() const
ptrdiff_t difference_type
T * data()
Get a pointer to the beginning of the array.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
size_t capacity() const
Returns the number of elements allocated.
virtual void postTakeStorage()
T value_type
Element type.
ConstIteratorSTL(const IteratorSTL &iter)
Create from a non-const iterator.
const IPosition & shape() const
The length of each axis.
void putVStorage(void *&storage, bool deleteAndCopy) override
const T * getStorage(bool &deleteIt) const