casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
IDIndex Class Reference

a simple mapping from one indexing system to another More...

#include <IDIndex.h>

Public Member Functions

 IDIndex (casacore::Int first=0)
 create an ID set. More...
 
 IDIndex (IDIndex &that)
 create a copy of another IDIndex More...
 
 ~IDIndex ()
 destroy this index More...
 
void add (casacore::Int id)
 add an ID to the set; More...
 
casacore::Int operator() (casacore::Int id)
 return the ID mapping More...
 
casacore::Int first ()
 return the output index that the first input ID is mapped to. More...
 
casacore::Int next ()
 return the next index to be mapped to when add is next called. More...
 
casacore::Int size ()
 return the number of input IDs mapped More...
 
void clear ()
 remove all ID mappings. More...
 

Private Attributes

casacore::Int offset
 
std::map< casacore::Int,
casacore::Int
idmap
 

Detailed Description

a simple mapping from one indexing system to another

Intended use:

Public interface

Review Status

Date Reviewed:
yyyy/mm/dd

Etymology

This class is puts an index on an ordered list of IDs.

Synopsis

Suppose that you have a list of things accessed via an index (i.e. an integer ID), say spectral windows. Suppose further you want to map them into some other index system, perhaps because you are reordering them. This simple class can keep track of the mapping between the two systems.

The mapping is set up through sequenced calls to the add() function, to which indices from the "input" system are passed. The order that the indices are passed indicate their order in the output system. One can then map to the output system by passing the input index to the () operator.

One sets the index that the first input index will be mapped to via the constructor, allowing one to map, for example, {1, 3, 2} into {4, 5, 6}.

Example

Suppose only selected windows will be written out. Here's how we can keep track of the mapping:

IDIndex idx(1); // the first index mapped into is 1
for(casacore::Int i=0; i < nspect; i++) {
if (windowSelected(i)) idx.add(i) // 0 -> 1 if selected
}
// which output window is the second window mapped to?
casacore::Int outwin = idx(2); // outwin = -1 if not selected

Motivation

The MirFiller class needs to keep track of which Miriad windows get mapped into which casacore::MS spectral windows. Since the user can select which windows will be loaded, its not easy to predict otherwise how the windows will get mapped. Furthermore, Miriad wideband channels are loaded as seperate windows in the output casacore::MS, thus the mapping from channel number to window will not necessarily start with 0.

Definition at line 87 of file IDIndex.h.

Constructor & Destructor Documentation

IDIndex::IDIndex ( casacore::Int  first = 0)

create an ID set.

first is the output index that the first input ID passed to add() will be mapped to. PJT explicit IDIndex(casacore::Int first=0);

IDIndex::IDIndex ( IDIndex that)

create a copy of another IDIndex

IDIndex::~IDIndex ( )

destroy this index

Member Function Documentation

void IDIndex::add ( casacore::Int  id)
inline

add an ID to the set;

Definition at line 105 of file IDIndex.h.

References idmap, and next().

void IDIndex::clear ( )
inline

remove all ID mappings.

This returns the index to its state just after construction.

Definition at line 122 of file IDIndex.h.

References idmap.

Referenced by MirFreqSetup::clear().

casacore::Int IDIndex::first ( )
inline

return the output index that the first input ID is mapped to.

This is the value returned by operator(0);

Definition at line 112 of file IDIndex.h.

References offset.

casacore::Int IDIndex::next ( )
inline

return the next index to be mapped to when add is next called.

Definition at line 115 of file IDIndex.h.

References idmap, and offset.

Referenced by add().

casacore::Int IDIndex::operator() ( casacore::Int  id)
inline

return the ID mapping

Definition at line 108 of file IDIndex.h.

References idmap.

casacore::Int IDIndex::size ( )
inline

return the number of input IDs mapped

Definition at line 118 of file IDIndex.h.

References idmap.

Member Data Documentation

std::map<casacore::Int, casacore::Int> IDIndex::idmap
private

Definition at line 90 of file IDIndex.h.

Referenced by add(), clear(), next(), operator()(), and size().

casacore::Int IDIndex::offset
private

Definition at line 89 of file IDIndex.h.

Referenced by first(), and next().


The documentation for this class was generated from the following file: