casa::IPosition Class Reference
[Arrays]

#include <IPosition.h>

List of all members.


Detailed Description

A Vector of integers, for indexing into Array<T> objects.

Intended use:

Part of API

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Etymology

IPosition is an Index Position in an n-dimensional array.

Synopsis

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).

Example

    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< IntasVector () const

Public Types

enum  
typedef Int value_type
 STL-style typedefs.
typedef Intiterator
typedef const Intconst_iterator
typedef value_typepointer
typedef const value_typeconst_pointer
typedef value_typereference
typedef const value_typeconst_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 ()
IPositionoperator= (const IPosition &other)
 Makes this a copy of other.
IPositionoperator= (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 Intstorage () 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
Intoperator[] (uInt index)
 Index into the IPosition.
Int operator[] (uInt index) const
Intoperator() (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]
Intdata_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.
AipsIOoperator<< (AipsIO &aio, const IPosition &ip)
 Write an IPosition to an AipsIO stream in a binary format.
LogIOoperator<< (LogIO &io, const IPosition &ip)
 Write an IPosition to a LogIO stream.
AipsIOoperator>> (AipsIO &aio, IPosition &ip)
 Read an IPosition from an AipsIO stream in a binary format.


Member Typedef Documentation

typedef Int casa::IPosition::value_type

STL-style typedefs.

Definition at line 304 of file IPosition.h.

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.


Member Enumeration Documentation

anonymous enum

Definition at line 112 of file IPosition.h.

anonymous enum [private]

Definition at line 334 of file IPosition.h.


Constructor & Destructor Documentation

casa::IPosition::IPosition (  )  [inline]

A zero-length IPosition.

Definition at line 452 of file IPosition.h.

Referenced by makeAxisPath().

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.

casa::IPosition::IPosition ( uInt  length,
Int  val 
)

An IPosition of size "length." The values in the object get initialized to val.

casa::IPosition::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.

You need to supply a value for each element of the IPosition (up to 10). [Unfortunately varargs might not be sufficiently portable.]

casa::IPosition::IPosition ( const IPosition other  ) 

Makes a copy (copy, NOT reference, semantics) of other.

casa::IPosition::~IPosition (  )  [inline]

Definition at line 465 of file IPosition.h.

References buffer_p, and data_p.

casa::IPosition::IPosition ( const Array< Int > &  other  ) 

Convert an IPosition to and from an Array<Int>.

In either case, the array must be one dimensional.


Member Function Documentation

IPosition& casa::IPosition::operator= ( const IPosition other  ) 

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.

IPosition& casa::IPosition::operator= ( Int  value  ) 

Copy "value" into every position of this IPosition.

IPosition casa::IPosition::makeAxisPath ( uInt  nrdim  )  [inline, static]

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].

static IPosition casa::IPosition::otherAxes ( uInt  nrdim,
const IPosition axes 
) [static]

Make a list of axes which are the axes not given in axes up to the given dimension.

Vector<Int> casa::IPosition::asVector (  )  const

IPosition casa::IPosition::nonDegenerate ( uInt  startingAxis = 0  )  const

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.\.

IPosition casa::IPosition::nonDegenerate ( const IPosition ignoreAxes  )  const

void casa::IPosition::resize ( uInt  newSize,
Bool  copy = True 
)

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().

Int & casa::IPosition::operator[] ( uInt  index  )  [inline]

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.

Int casa::IPosition::operator[] ( uInt  index  )  const [inline]

Definition at line 491 of file IPosition.h.

References data_p.

Int & casa::IPosition::operator() ( uInt  index  )  [inline]

Definition at line 496 of file IPosition.h.

References data_p, nelements(), and throwIndexError().

Int casa::IPosition::operator() ( uInt  index  )  const [inline]

Definition at line 506 of file IPosition.h.

References data_p, nelements(), and throwIndexError().

const Int * casa::IPosition::storage (  )  const [inline]

Get the storage.

Definition at line 516 of file IPosition.h.

References data_p.

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).

IPosition casa::IPosition::concatenate ( const IPosition other  )  const

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  ) 

Set the first values of this IPosition to another IPosition.

An exception is thrown if the other IPosition is too long.

void casa::IPosition::setLast ( const IPosition other  ) 

Set the last values of this IPosition to another IPosition.

An exception is thrown if the other IPosition is too long.

IPosition casa::IPosition::getFirst ( uInt  n  )  const

Construct an IPosition from the first n values of this IPosition.

An exception is thrown if n is too high.

IPosition casa::IPosition::getLast ( uInt  n  )  const

Construct an IPosition from the last n values of this IPosition.

An exception is thrown if n is too high.

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]

Definition at line 481 of file IPosition.h.

References size_p.

Bool casa::IPosition::conform ( const IPosition other  )  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().

Bool casa::IPosition::isEqual ( const IPosition other  )  const

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().

Bool casa::IPosition::isEqual ( const IPosition other,
Bool  skipDegeneratedAxes 
) const

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.

Bool casa::IPosition::isEqual ( const IPosition other,
uInt  nrCompare 
) const

Element-by-element comparison for (partial) equality.

It returns True if the lengths and the first nrCompare elements are equal.

Bool casa::IPosition::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 casa::IPosition::ok (  )  const

Is this IPosition consistent?

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]

Definition at line 318 of file IPosition.h.

References data_p.

iterator casa::IPosition::end (  )  [inline]

Definition at line 320 of file IPosition.h.

References data_p, and size_p.

const_iterator casa::IPosition::end (  )  const [inline]

Definition at line 322 of file IPosition.h.

References data_p, and size_p.

void casa::IPosition::allocateBuffer (  )  [private]

Allocate a buffer with length size_p.

Referenced by IPosition().

void casa::IPosition::throwIndexError (  )  const [private]

Throw an index error exception.

Referenced by operator()().


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const IPosition ip 
) [friend]

Write an IPosition to an ostream in a simple text form.

AipsIO& operator<< ( AipsIO aio,
const IPosition ip 
) [friend]

Write an IPosition to an AipsIO stream in a binary format.

LogIO& operator<< ( LogIO io,
const IPosition ip 
) [friend]

Write an IPosition to a LogIO stream.

AipsIO& operator>> ( AipsIO aio,
IPosition ip 
) [friend]

Read an IPosition from an AipsIO stream in a binary format.

Will throw an AipsError if the current IPosition Version does not match that of the one on disk.


Member Data Documentation

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]

Definition at line 336 of file IPosition.h.

Referenced by ~IPosition().

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().


The documentation for this class was generated from the following file:
Generated on Mon Sep 1 22:43:40 2008 for NRAOCASA by  doxygen 1.5.1