casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IDIndex.h
Go to the documentation of this file.
1 //# IDIndex.h: this defines IDIndex, which maps one indexing system into another
2 //# Copyright (C) 2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id: IDIndex.h,v 1.2 2009/09/03 23:28:32 pteuben Exp $
28 
29 #ifndef BIMA_IDINDEX_H
30 #define BIMA_IDINDEX_H
31 
33 
34 #include <casa/namespace.h>
35 // <summary>
36 // a simple mapping from one indexing system to another
37 // </summary>
38 //
39 // <use visibility=export>
40 //
41 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
42 // </reviewed>
43 //
44 // <etymology>
45 // This class is puts an index on an ordered list of IDs.
46 // </etymology>
47 //
48 // <synopsis>
49 // Suppose that you have a list of things accessed via an index (i.e. an
50 // integer ID), say spectral windows. Suppose further you want to map them
51 // into some other index system, perhaps because you are reordering them.
52 // This simple class can keep track of the mapping between the two systems. <p>
53 //
54 // The mapping is set up through sequenced calls to the <src>add()</src>
55 // function, to which indices from the "input" system are passed. The order
56 // that the indices are passed indicate their order in the output system.
57 // One can then map to the output system by passing the input index to the
58 // () operator. <p>
59 //
60 // One sets the index that the first input index will be mapped to via the
61 // constructor, allowing one to map, for example, {1, 3, 2} into {4, 5, 6}.
62 // </synopsis>
63 //
64 // <example>
65 // Suppose only selected windows will be written out. Here's how we can keep
66 // track of the mapping:
67 // <srcblock>
68 // IDIndex idx(1); // the first index mapped into is 1
69 // for(casacore::Int i=0; i < nspect; i++) {
70 // if (windowSelected(i)) idx.add(i) // 0 -> 1 if selected
71 // }
72 //
73 // // which output window is the second window mapped to?
74 // casacore::Int outwin = idx(2); // outwin = -1 if not selected
75 // </srcblock>
76 // </example>
77 //
78 // <motivation>
79 // The MirFiller class needs to keep track of which Miriad windows get mapped
80 // into which casacore::MS spectral windows. Since the user can select which windows
81 // will be loaded, its not easy to predict otherwise how the windows will get
82 // mapped. Furthermore, Miriad wideband channels are loaded as seperate
83 // windows in the output casacore::MS, thus the mapping from channel number to window
84 // will not necessarily start with 0.
85 // </motivation>
86 
87 class IDIndex {
88 private:
90  std::map<casacore::Int, casacore::Int> idmap;
91 public:
92  // create an ID set. <src>first</src> is the output index that the first
93  // input ID passed to <src>add()</src> will be mapped to.
94  //PJT
95  // explicit IDIndex(casacore::Int first=0);
97 
98  // create a copy of another IDIndex
99  IDIndex(IDIndex& that);
100 
101  // destroy this index
102  ~IDIndex();
103 
104  // add an ID to the set;
105  void add(casacore::Int id) { idmap.define(id, next()); }
106 
107  // return the ID mapping
109 
110  // return the output index that the first input ID is mapped to. This is the
111  // value returned by operator(0);
112  casacore::Int first() { return offset; }
113 
114  // return the next index to be mapped to when add is next called.
115  casacore::Int next() { return offset+idmap.ndefined(); }
116 
117  // return the number of input IDs mapped
118  casacore::Int size() { return idmap.ndefined(); }
119 
120  // remove all ID mappings. This returns the index to its state just
121  // after construction.
122  void clear() { idmap.clear(); }
123 };
124 
125 
126 
127 #endif
128 
129 
int Int
Definition: aipstype.h:50
void add(casacore::Int id)
add an ID to the set;
Definition: IDIndex.h:105
casacore::Int next()
return the next index to be mapped to when add is next called.
Definition: IDIndex.h:115
IDIndex(casacore::Int first=0)
create an ID set.
casacore::Int offset
Definition: IDIndex.h:89
casacore::Int first()
return the output index that the first input ID is mapped to.
Definition: IDIndex.h:112
casacore::Int size()
return the number of input IDs mapped
Definition: IDIndex.h:118
void clear()
remove all ID mappings.
Definition: IDIndex.h:122
std::map< casacore::Int, casacore::Int > idmap
Definition: IDIndex.h:90
casacore::Int operator()(casacore::Int id)
return the ID mapping
Definition: IDIndex.h:108
~IDIndex()
destroy this index
a simple mapping from one indexing system to another
Definition: IDIndex.h:87