IDIndex.h

Go to the documentation of this file.
00001 //# IDIndex.h: this defines IDIndex, which maps one indexing system into another
00002 //# Copyright (C) 2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: IDIndex.h,v 1.2 2009/09/03 23:28:32 pteuben Exp $
00028 
00029 #ifndef BIMA_IDINDEX_H
00030 #define BIMA_IDINDEX_H
00031 
00032 #include <casa/Containers/SimOrdMap.h>
00033 
00034 #include <casa/namespace.h>
00035 // <summary>
00036 // a simple mapping from one indexing system to another
00037 // </summary>
00038 // 
00039 // <use visibility=export>
00040 // 
00041 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00042 // </reviewed>
00043 // 
00044 // <etymology>
00045 // This class is puts an index on an ordered list of IDs.
00046 // </etymology>
00047 //
00048 // <synopsis>
00049 // Suppose that you have a list of things accessed via an index (i.e. an 
00050 // integer ID), say spectral windows.  Suppose further you want to map them 
00051 // into some other index system, perhaps because you are reordering them.  
00052 // This simple class can keep track of the mapping between the two systems.  <p>
00053 // 
00054 // The mapping is set up through sequenced calls to the <src>add()</src> 
00055 // function, to which indices from the "input" system are passed.  The order 
00056 // that the indices are passed indicate their order in the output system.  
00057 // One can then map to the output system by passing the input index to the 
00058 // () operator.  <p>
00059 //
00060 // One sets the index that the first input index will be mapped to via the 
00061 // constructor, allowing one to map, for example, {1, 3, 2} into {4, 5, 6}.  
00062 // </synopsis>
00063 //
00064 // <example>
00065 // Suppose only selected windows will be written out.  Here's how we can keep
00066 // track of the mapping:
00067 // <srcblock>
00068 //   IDIndex idx(1);   // the first index mapped into is 1
00069 //   for(Int i=0; i < nspect; i++) {
00070 //       if (windowSelected(i)) idx.add(i)   // 0 -> 1 if selected
00071 //   }
00072 //   
00073 //   // which output window is the second window mapped to? 
00074 //   Int outwin = idx(2);     // outwin = -1 if not selected
00075 // </srcblock>
00076 // </example>
00077 //
00078 // <motivation>
00079 // The MirFiller class needs to keep track of which Miriad windows get mapped 
00080 // into which MS spectral windows.  Since the user can select which windows 
00081 // will be loaded, its not easy to predict otherwise how the windows will get 
00082 // mapped.  Furthermore, Miriad wideband channels are loaded as seperate 
00083 // windows in the output MS, thus the mapping from channel number to window 
00084 // will not necessarily start with 0.  
00085 // </motivation>
00086 
00087 class IDIndex {
00088 private:
00089     Int offset;
00090     SimpleOrderedMap<Int, Int> idmap;
00091 public:    
00092     // create an ID set.  <src>first</src> is the output index that the first
00093     // input ID passed to <src>add()</src> will be mapped to.
00094     //PJT
00095     //    explicit IDIndex(Int first=0);
00096     IDIndex(Int first=0);
00097 
00098     // create a copy of another IDIndex
00099     IDIndex(IDIndex& that);
00100 
00101     // destroy this index
00102     ~IDIndex();
00103 
00104     // add an ID to the set;
00105     void add(Int id) { idmap.define(id, next()); }
00106 
00107     // return the ID mapping
00108     Int operator()(Int id) { return idmap(id); }
00109 
00110     // return the output index that the first input ID is mapped to.  This is the 
00111     // value returned by operator(0);
00112     Int first() { return offset; }
00113 
00114     // return the next index to be mapped to when add is next called.
00115     Int next() { return offset+idmap.ndefined(); }
00116 
00117     // return the number of input IDs mapped
00118     Int size() { return idmap.ndefined(); }
00119 
00120     // remove all ID mappings.  This returns the index to its state just 
00121     // after construction.
00122     void clear() { idmap.clear(); }
00123 };
00124 
00125 
00126 
00127 #endif
00128 
00129 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1