40#include <initializer_list>
193 Array(std::initializer_list<T> list);
221 template<
typename InputIterator>
245 template<typename Callable>
415 size_t resizePercentage = 0,
416 bool resizeIfNeeded =
true);
430 size_t resizePercentage = 0,
431 bool resizeIfNeeded =
true);
460 bool throwIfError=
true);
470 bool throwIfError=
true);
580 virtual bool ok()
const override;
663 std::unique_ptr<ArrayPositionIterator>
makeIterator(
size_t byDim)
const override;
700 {
return const_cast<T*
>(
itsPos); }
703 { os << iter.
itsPos;
return os; }
752 {
return *this->
getPos(); }
754 {
return this->
getPos(); }
873 template<
typename Integral>
879 template<
typename InputIterator>
887 throw ArrayError(
"Can not assign from non-copyable object");
892 throw ArrayError(
"Can not coy from non-copyable object");
905 template<
typename ST>
928 std::string(
"Invalid size given to ") +
typeid(*this).name() +
944 throw ArrayError(
"ArrayBase& has incorrect template type");
962 std::shared_ptr<arrays_internal::Storage<T>>
data_p;
993extern template class Array<bool>;
994extern template class Array<char>;
995extern template class Array<unsigned char>;
996extern template class Array<short>;
997extern template class Array<unsigned short>;
998extern template class Array<int>;
999extern template class Array<long long>;
1000extern template class Array<float>;
1001extern template class Array<double>;
Non-templated base class for templated Array class.
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.
const IPosition & shape() const
The length of each axis.
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 > * itsArray
BaseIteratorSTL(const T *end=0)
Create the end const_iterator object for an Array.
void increment()
Increment iterator for a non-contiguous array.
bool operator!=(const BaseIteratorSTL &other) const
friend std::ostream & operator<<(std::ostream &os, const BaseIteratorSTL &iter)
BaseIteratorSTL(const Array< T > &)
Create the begin const_iterator object for an Array.
std::forward_iterator_tag iterator_category
const value_type * pointer
ConstIteratorSTL operator++(int)
const ConstIteratorSTL & operator++()
ConstIteratorSTL(const Array< T > &arr)
Create the begin const_iterator object for an Array.
ptrdiff_t difference_type
const value_type & reference
ConstIteratorSTL(const IteratorSTL &iter)
Create from a non-const iterator.
ConstIteratorSTL(const T *end=0)
Create the end const_iterator object for an Array.
const T & operator*() const
ptrdiff_t difference_type
const IteratorSTL & operator++()
IteratorSTL operator++(int)
IteratorSTL(Array< T > &arr)
Create the begin iterator object for an Array.
std::forward_iterator_tag iterator_category
IteratorSTL(const T *end=0)
Create the end iterator object for an Array.
Array< T > operator()(const IPosition &start, const IPosition &end)
Get a reference to an array section extending from start to end (inclusive).
static void copyToContiguousStorage(T *, Array< T > const &, std::false_type)
void resize(const IPosition &newShape, bool copyValues=false) override
Resize the array and optionally copy the values.
virtual void preTakeStorage(const IPosition &)
pre/post processing hook of takeStorage() for subclasses.
void assign(const Array< T > &other)
Assign the other array to this array.
void freeVStorage(const void *&storage, bool deleteIt) const override
Array(const IPosition &shape, const T *storage)
Create an Array of a given shape from a pointer.
Array(const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
Create an Array of a given shape from a pointer.
T * data()
Get a pointer to the beginning of the array.
size_t nrefs() const
The number of references the underlying storage has assigned 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.
std::shared_ptr< arrays_internal::Storage< T > > data_p
Shared pointer to a Storage that contains the data.
Array(std::initializer_list< T > list)
Construct a one-dimensional array from an initializer list.
Array< T > & operator=(const Array< T > &other)
TODO we should change the semantics.
Array(const IPosition &shape, InputIterator startIter, std::false_type)
Implementation of constructor taking a Shape, a Templated parameter and an allocator.
T * begin_p
This pointer is adjusted to point to the first element of the array.
const Array< T > operator()(const IPosition &start, const IPosition &end) const
iterator begin()
Get the begin iterator object for any array.
void unique()
This ensures that this array does not reference any other storage.
void putVStorage(void *&storage, bool deleteAndCopy) override
Array< T > & assign_conforming(const MaskedArray< T > &marray)
Copy to this those values in marray whose corresponding elements in marray's mask are true.
T & operator()(const IPosition &)
Access a single element of the array.
ConstIteratorSTL const_iterator
Array(const IPosition &shape, uninitializedType)
Constructor to create an uninitialized array.
contiter cbegin()
Get the begin iterator object for a contiguous array.
Array(const IPosition &shape, const T &initialValue)
Create an array of the given shape and initialize it with the initial value.
void freeStorage(const T *&storage, bool deleteIt) const
If deleteIt is set, delete "storage".
Array< T > & operator=(Array< T > &&other)
The move operator takes the storage from the given array.
const T & const_reference
TODO This is how std containers define a reference type, but the name 'reference' is already taken by...
virtual void postTakeStorage()
Array< T > operator[](size_t i) const
Get the subset given by the i-th value of the last axis.
friend void swap(Array< ST > &left, Array< ST > &right)
bool isUnique() const
An Array is unique when the container is shared and when nrefs==1.
void makeSteps()
Fill the steps and the end for a derived class.
const T * const_pointer
Constant pointer to the element type.
Array< T > diagonals(size_t firstAxis=0, long long diag=0) const
Get the diagonal of each matrix part in the full array.
static void copyToContiguousStorage(T *dst, Array< T > const &src)
Array< T > nonDegenerate(const IPosition &ignoreAxes) const
Array(const IPosition &shape, InputIterator startIter)
Construct an array from an iterator and a shape.
void checkBeforeResize(const IPosition &newShape)
This function is called when this array is about to be resized, before any work is done.
Array< T > & assign_conforming_implementation(const Array< T > &, std::false_type)
Implementation for assign for non-copyable types: can not be assigned.
void nonDegenerate(const Array< T > &other, const IPosition &ignoreAxes)
Array< T > copy() const
This makes a copy of the array and returns it.
const T & operator()(const IPosition &) const
void * getVStorage(bool &deleteIt) override
The following functions behave the same as the corresponding getStorage functions in the derived temp...
virtual std::unique_ptr< ArrayBase > makeArray() const override
Make an empty array of the same template type.
const_iterator begin() const
const_contiter cbegin() const
Array< T > & assign_conforming(const Array< T > &other)
Copy the values in other to this.
virtual void doNonDegenerate(const Array< T > &other, const IPosition &ignoreAxes)
Remove the degenerate axes from the Array object.
void removeDegenerate(const IPosition &ignoreAxes)
Array< T > operator()(const IPosition &start, const IPosition &end, const IPosition &inc)
Along the ith axis, every inc[i]'th element is chosen.
Array< T > & operator=(const MaskedArray< T > &marray)
Calls assign_conforming().
const_iterator end() const
virtual bool ok() const override
Check to see if the Array is consistent.
Array< T > operator()(const Slicer &)
Get a reference to an array section using a Slicer.
void setEndIter()
Set the end iterator.
Array(Array< T > &&source) noexcept
Source will be empty after this call.
T * pointer
Pointer to an element type.
virtual size_t fixedDimensionality() const
Subclasses can return their dimensionality.
const Array< T > operator()(const IPosition &start, const IPosition &end, const IPosition &inc) const
bool conform(const Array< T > &other) const
Are the shapes identical?
void tovector(std::vector< T, U > &out) const
Create an STL vector from an Array.
Array(Array< T > &&source, const IPosition &shapeForSource) noexcept
Source will be empty with given shape after this call.
Array< T > & assign_conforming_implementation(const Array< T > &other, std::true_type)
Implementation for assign for copyable types.
void nonDegenerate(const Array< T > &other, size_t startingAxis=0, bool throwIfError=true)
const_contiter cend() const
void resize()
Make this array a different shape.
std::unique_ptr< ArrayPositionIterator > makeIterator(size_t byDim) const override
Create an ArrayIterator object of the correct type.
Array(const Array< T > &other)
After construction, this and other reference the same storage.
static struct casacore::Array::uninitializedType uninitialized
const Array< T > addDegenerate(size_t numAxes) const
This member function returns an Array reference with the specified number of extra axes,...
Array< T > addDegenerate(size_t numAxes)
virtual ~Array() noexcept
Frees up storage only if this array was the last reference to it.
Array< T > nonDegenerate(size_t startingAxis=0, bool throwIfError=true) const
These member functions remove degenerate (ie.
void swap(Array< T > &other)
Swap this array with another array.
bool conform(const MaskedArray< T > &other) const
virtual void takeStorage(const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
Replace the data values with those in the pointer storage.
Array< T > & operator=(const T &value)
Set every element of this array to "value".
Array(const IPosition &shape)
Create an array of the given shape, i.e.
void copyMatchingPart(const Array< T > &from)
This function copies the matching part of from array to this array.
void removeDegenerate(size_t startingAxis=0, bool throwIfError=true)
Remove degenerate axes from this Array object.
virtual void checkAssignableType(ArrayBase &arrayBase) const
void putStorage(T *&storage, bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
const Array< T > operator()(const Slicer &) const
void set(const T &value)
Set every element of the array to "value." Also could use the assignment operator which assigns an ar...
virtual void reference(const Array< T > &other)
After invocation, this array and other reference the same storage.
std::unique_ptr< ArrayBase > getSection(const Slicer &) const override
Get a reference to a section of an array.
void apply(Callable function)
Apply the function to every element of the array.
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.
Array()
Result has dimensionality of zero, and nelements is zero.
Array(const IPosition &shape, Integral startIter, std::true_type)
Implementation of constructor taking a Shape, a Templated parameter and an allocator.
T * end_p
The end for an STL-style iteration.
const T * getStorage(bool &deleteIt) const
std::vector< T > tovector() const
const void * getVStorage(bool &deleteIt) const override
size_t capacity() const
Returns the number of elements allocated.
T value_type
Define the STL-style iterator functions (only forward iterator).
void assignBase(const ArrayBase &other, bool checkType=true) override
Assign the source array to this array.
static void copyToContiguousStorage(T *dst, Array< T > const &src, std::true_type)
Array< T > reform(const IPosition &shape) const
It is occasionally useful to have an array which access the same storage appear to have a different s...
T * getStorage(bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar.
@ COPY
COPY is used when an internal copy of the storage is to be made.
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.
void swap(Array< T > &first, Array< T > &second)
Swap the first array with the second.
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.
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.