#include <IPosition.h>
Part of API
IPosition is an Index Position in an n-dimensional array.
IPosition is "logically" a Vector<Int> constrained so that it's origin is zero-based, and in fact that used to be the way it was implemented. It was split out into a separate class to make the inheritance from Arrays simpler (since Arrays use IPositions). The template instantiation mechanism is complicated enough that this simplification was felt to be a good idea.
IPosition objects are normally used to index into, and define the shapes of, multi-dimensional arrays. For example, if you have a 5 dimensional array, you need an IPosition of length 5 to index into the array (or to define its shape, etc.).
Unlike Vectors, IPositions always use copy semantics.
IPosition ip1(5); // An IPosition of length 5 ip1(0) = 11; ip1(1) = 5; .\.. ip1(4) = 6; // Indices 0-based IPosition ip2(ip1); // Copy constructor; a COPY
Binary operations must take place either with a conformnat (same size) IPosition or with an integer, which behaves as if it was an IPosition of the same size (i.e., length). All the usual binary arithmetic operations are available, as well as logical operations, which return Booleans. These all operate "element-by-element".
All non-inlined member functions of IPosition check invariants if the preprocessor symbol AIPS_DEBUG is defined. That is, the member functions check that ok() is true (constructors check after construction, other functions on entry to the function). If these tests fail, an AipsError exception is thrown; its message contains the line number and source file of the failure (it is thrown by the lAssert macro defined in aips/Assert.h).
IPosition blc(5), trc(5,1,2,3,4,5); blc = 0; // OR IPosition blc(5,0); //.\.. if (blc > trc) { IPosition tmp; tmp = trc; // Swap trc = blc; blc = tmp; } //.\.. trc += 5; // make the box 5 larger in all dimensions
Definition at line 109 of file IPosition.h.
| IPosition (const Array< Int > &other) | |
| Convert an IPosition to and from an Array<Int>. | |
| Vector< Int > | asVector () const |
Public Types | |
| enum | |
| typedef Int | value_type |
| STL-style typedefs. | |
| typedef Int * | iterator |
| typedef const Int * | const_iterator |
| typedef value_type * | pointer |
| typedef const value_type * | const_pointer |
| typedef value_type & | reference |
| typedef const value_type & | const_reference |
| typedef size_t | size_type |
| typedef ptrdiff_t | difference_type |
Public Member Functions | |
| IPosition () | |
| A zero-length IPosition. | |
| IPosition (uInt length) | |
| An IPosition of size "length." The values in the object are undefined. | |
| IPosition (uInt length, Int val) | |
| An IPosition of size "length." The values in the object get initialized to val. | |
| IPosition (uInt length, Int val0, Int val1, Int val2=MIN_INT, Int val3=MIN_INT, Int val4=MIN_INT, Int val5=MIN_INT, Int val6=MIN_INT, Int val7=MIN_INT, Int val8=MIN_INT, Int val9=MIN_INT) | |
| An IPosition of size "length" with defined values. | |
| IPosition (const IPosition &other) | |
| Makes a copy (copy, NOT reference, semantics) of other. | |
| ~IPosition () | |
| IPosition & | operator= (const IPosition &other) |
| Makes this a copy of other. | |
| IPosition & | operator= (Int value) |
| Copy "value" into every position of this IPosition. | |
| void | resize (uInt newSize, Bool copy=True) |
| Old values are copied on resize if copy==True. | |
| const Int * | storage () const |
| Get the storage. | |
| void | append (const IPosition &other) |
| Append this IPosition with another one (causing a resize). | |
| void | prepend (const IPosition &other) |
| Prepend this IPosition with another one (causing a resize). | |
| IPosition | concatenate (const IPosition &other) const |
| Return an IPosition as the concetanation of this and another IPosition. | |
| void | setFirst (const IPosition &other) |
| Set the first values of this IPosition to another IPosition. | |
| void | setLast (const IPosition &other) |
| Set the last values of this IPosition to another IPosition. | |
| IPosition | getFirst (uInt n) const |
Construct an IPosition from the first n values of this IPosition. | |
| IPosition | getLast (uInt n) const |
Construct an IPosition from the last n values of this IPosition. | |
| Bool | conform (const IPosition &other) const |
| conform returns true if nelements() == other.nelements(). | |
| Int | product () const |
| Returns 0 if nelements() == 0, otherwise it returns the product of its elements. | |
| Bool | isEqual (const IPosition &other) const |
| Element-by-element comparison for equality. | |
| Bool | isEqual (const IPosition &other, Bool skipDegeneratedAxes) const |
| Element-by-element comparison for equality. | |
| Bool | isEqual (const IPosition &other, uInt nrCompare) const |
| Element-by-element comparison for (partial) equality. | |
| Bool | isSubSet (const IPosition &other) const |
| Is the other IPosition a subset of (or equal to) this IPosition? It is a subset if zero or more axes of this IPosition do not occur or are degenerated in the other and if the remaining axes are in the same order. | |
| Bool | ok () const |
| Is this IPosition consistent? | |
| IPosition | nonDegenerate (uInt startingAxis=0) const |
| This member functions return an IPosition which has degenerate (length==1) axes removed and the dimensionality reduced appropriately. | |
| IPosition | nonDegenerate (const IPosition &ignoreAxes) const |
| Int & | operator[] (uInt index) |
| Index into the IPosition. | |
| Int | operator[] (uInt index) const |
| Int & | operator() (uInt index) |
| Int | operator() (uInt index) const |
| uInt | nelements () const |
| The number of elements in this IPosition. | |
| uInt | size () const |
| void | operator+= (const IPosition &other) |
| Element-by-element arithmetic. | |
| void | operator-= (const IPosition &other) |
| void | operator *= (const IPosition &other) |
| void | operator/= (const IPosition &other) |
| void | operator+= (Int val) |
| void | operator-= (Int val) |
| void | operator *= (Int val) |
| void | operator/= (Int val) |
| iterator | begin () |
| Get the begin and end iterator object for this object. | |
| const_iterator | begin () const |
| iterator | end () |
| const_iterator | end () const |
Static Public Member Functions | |
| static IPosition | makeAxisPath (uInt nrdim) |
| Construct a default axis path consisting of the values 0 . | |
| static IPosition | makeAxisPath (uInt nrdim, const IPosition &partialPath) |
| Construct a full axis path from a (partially) given axis path. | |
| static IPosition | otherAxes (uInt nrdim, const IPosition &axes) |
Make a list of axes which are the axes not given in axes up to the given dimension. | |
Private Types | |
| enum | |
Private Member Functions | |
| void | allocateBuffer () |
| Allocate a buffer with length size_p. | |
| void | throwIndexError () const |
| Throw an index error exception. | |
Private Attributes | |
| uInt | size_p |
| Int | buffer_p [BufferLength] |
| Int * | data_p |
| When the iposition is length BufferSize or less data is just buffer_p, avoiding calls to new and delete. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const IPosition &ip) |
| Write an IPosition to an ostream in a simple text form. | |
| AipsIO & | operator<< (AipsIO &aio, const IPosition &ip) |
| Write an IPosition to an AipsIO stream in a binary format. | |
| LogIO & | operator<< (LogIO &io, const IPosition &ip) |
| Write an IPosition to a LogIO stream. | |
| AipsIO & | operator>> (AipsIO &aio, IPosition &ip) |
| Read an IPosition from an AipsIO stream in a binary format. | |
| typedef Int casa::IPosition::value_type |
| typedef Int* casa::IPosition::iterator |
Definition at line 305 of file IPosition.h.
| typedef const Int* casa::IPosition::const_iterator |
Definition at line 306 of file IPosition.h.
| typedef value_type* casa::IPosition::pointer |
Definition at line 307 of file IPosition.h.
| typedef const value_type* casa::IPosition::const_pointer |
Definition at line 308 of file IPosition.h.
| typedef value_type& casa::IPosition::reference |
Definition at line 309 of file IPosition.h.
| typedef const value_type& casa::IPosition::const_reference |
Definition at line 310 of file IPosition.h.
| typedef size_t casa::IPosition::size_type |
Definition at line 311 of file IPosition.h.
| typedef ptrdiff_t casa::IPosition::difference_type |
Definition at line 312 of file IPosition.h.
| anonymous enum |
Definition at line 112 of file IPosition.h.
anonymous enum [private] |
Definition at line 334 of file IPosition.h.
| casa::IPosition::IPosition | ( | ) | [inline] |
| casa::IPosition::IPosition | ( | uInt | length | ) | [inline, explicit] |
An IPosition of size "length." The values in the object are undefined.
Definition at line 456 of file IPosition.h.
References allocateBuffer(), and BufferLength.
An IPosition of size "length." The values in the object get initialized to val.
| casa::IPosition::IPosition | ( | const IPosition & | other | ) |
Makes a copy (copy, NOT reference, semantics) of other.
| casa::IPosition::~IPosition | ( | ) | [inline] |
Convert an IPosition to and from an Array<Int>.
In either case, the array must be one dimensional.
Makes this a copy of other.
"this" and "other" must either be conformant (same size) or this must be 0-length, in which case it will resize itself to be the same length as other.
Copy "value" into every position of this IPosition.
Construct a default axis path consisting of the values 0 .
\. nrdim-1.
Definition at line 472 of file IPosition.h.
References IPosition().
| static IPosition casa::IPosition::makeAxisPath | ( | uInt | nrdim, | |
| const IPosition & | partialPath | |||
| ) | [static] |
Construct a full axis path from a (partially) given axis path.
It fills the path with the non-given axis. It is checked if the given axis path is valid (i.e. if the axis are < nrdim and if they are not doubly defined). E.g.: in the 4D case an axis path [0,2] is returned as [0,2,1,3].
Make a list of axes which are the axes not given in axes up to the given dimension.
This member functions return an IPosition which has degenerate (length==1) axes removed and the dimensionality reduced appropriately.
Only axes greater than startingAxis are considered (normally one wants to remove trailing axes.
The functions with argument ignoreAxes do not consider the axes given in that argument.\.
Old values are copied on resize if copy==True.
\. If the size increases, values beyond the former size are undefined.
Referenced by casa::TSMCube::setLastColSlice().
Index into the IPosition.
Indices are zero-based. If the preprocessor symbol AIPS_ARRAY_INDEX_CHECK is defined, operator() will check "index" to ensure it is not out of bounds. If this check fails, an AipsError will be thrown.
Definition at line 486 of file IPosition.h.
References data_p.
| const Int * casa::IPosition::storage | ( | ) | const [inline] |
| void casa::IPosition::append | ( | const IPosition & | other | ) |
Append this IPosition with another one (causing a resize).
| void casa::IPosition::prepend | ( | const IPosition & | other | ) |
Prepend this IPosition with another one (causing a resize).
Return an IPosition as the concetanation of this and another IPosition.
Referenced by casa::ScaledComplexData< VirtualType, StoredType >::storedShape().
| void casa::IPosition::setFirst | ( | const IPosition & | other | ) |
| void casa::IPosition::setLast | ( | const IPosition & | other | ) |
| uInt casa::IPosition::nelements | ( | ) | const [inline] |
The number of elements in this IPosition.
Since IPosition objects use zero-based indexing, the maximum available index is nelements() - 1.
Definition at line 477 of file IPosition.h.
References size_p.
Referenced by casa::ArrayPositionIterator::dimIter(), casa::Slicer::ndim(), casa::ArrayPositionIterator::ndim(), operator()(), casa::TSMCube::setLastColSlice(), and casa::PixelatedConvFunc< std::complex< Float > >::setSize().
| uInt casa::IPosition::size | ( | ) | const [inline] |
conform returns true if nelements() == other.nelements().
Definition at line 521 of file IPosition.h.
References size_p.
Referenced by casa::TSMShape::conform().
| void casa::IPosition::operator+= | ( | const IPosition & | other | ) |
Element-by-element arithmetic.
| void casa::IPosition::operator-= | ( | const IPosition & | other | ) |
| void casa::IPosition::operator *= | ( | const IPosition & | other | ) |
| void casa::IPosition::operator/= | ( | const IPosition & | other | ) |
| void casa::IPosition::operator+= | ( | Int | val | ) |
| void casa::IPosition::operator-= | ( | Int | val | ) |
| void casa::IPosition::operator *= | ( | Int | val | ) |
| void casa::IPosition::operator/= | ( | Int | val | ) |
| Int casa::IPosition::product | ( | ) | const |
Returns 0 if nelements() == 0, otherwise it returns the product of its elements.
Referenced by casa::fieldSize(), casa::fieldType(), casa::isFieldSet(), and casa::LatticeIndexer::nelements().
Element-by-element comparison for equality.
It returns True if the lengths and all elements are equal.
Note that an important difference between this function and operator==() is that if the two IPositions have different lengths, this function returns False, instead of throwing an exception as operator==() does.
Referenced by casa::LatticeBase::conform(), and casa::ArrayBase::conform2().
Element-by-element comparison for equality.
It returns True if all elements are equal. When skipDegeneratedAxes is True, axes with length 1 are skipped in both operands.
Element-by-element comparison for (partial) equality.
It returns True if the lengths and the first nrCompare elements are equal.
| iterator casa::IPosition::begin | ( | ) | [inline] |
Get the begin and end iterator object for this object.
Definition at line 316 of file IPosition.h.
References data_p.
| const_iterator casa::IPosition::begin | ( | ) | const [inline] |
| iterator casa::IPosition::end | ( | ) | [inline] |
| const_iterator casa::IPosition::end | ( | ) | const [inline] |
| void casa::IPosition::allocateBuffer | ( | ) | [private] |
| void casa::IPosition::throwIndexError | ( | ) | const [private] |
| std::ostream& operator<< | ( | std::ostream & | os, | |
| const IPosition & | ip | |||
| ) | [friend] |
Write an IPosition to an ostream in a simple text form.
uInt casa::IPosition::size_p [private] |
Definition at line 335 of file IPosition.h.
Referenced by conform(), end(), nelements(), and size().
Int casa::IPosition::buffer_p[BufferLength] [private] |
Int* casa::IPosition::data_p [private] |
When the iposition is length BufferSize or less data is just buffer_p, avoiding calls to new and delete.
Definition at line 339 of file IPosition.h.
Referenced by begin(), end(), operator()(), operator[](), storage(), and ~IPosition().
1.5.1