MultiParamFieldIterator.h

Go to the documentation of this file.
00001 /* -*- mode: c++ -*- */
00002 //# MultiParamFielditerator.h: Multiple parameter iterator over Records
00003 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 #ifndef MULTI_PARAM_FIELD_ITERATOR_H_
00028 #define MULTI_PARAM_FIELD_ITERATOR_H_
00029 
00030 #include <synthesis/ImagerObjects/ParamFieldIterator.h>
00031 #include <casa/Containers/Record.h>
00032 #include <iterator>
00033 #include <array>
00034 
00035 namespace casa {
00036 
00037 template<size_t N>
00038 class MultiParamFieldIterator
00039         : public std::iterator<std::forward_iterator_tag, std::array<Record *,N>,
00040                                int> {
00041         std::array<Record *,N> records;
00042         String prefix;
00043         uInt field_index;
00044 
00045 public:
00046         MultiParamFieldIterator()
00047                 : records(std::array<Record *,N> {})
00048                 , prefix(String(""))
00049                 , field_index(0) {};
00050 
00051         MultiParamFieldIterator(
00052                 std::array<Record *,N> &recs, const string prefix = "")
00053                 : records(recs)
00054                 , prefix(String(prefix))
00055                 , field_index(0) {};
00056 
00057         MultiParamFieldIterator(const MultiParamFieldIterator &fit)
00058                 : records(fit.records)
00059                 , prefix(fit.prefix)
00060                 , field_index(fit.field_index) {};
00061 
00062         MultiParamFieldIterator operator++() {
00063                 ++field_index;
00064                 return *this;
00065         };
00066 
00067         MultiParamFieldIterator operator++(int) {
00068                 MultiParamFieldIterator tmp(*this);
00069                 operator++();
00070                 return tmp;
00071         };
00072 
00073         bool operator==(const MultiParamFieldIterator &rhs) {
00074                 return records == rhs.records
00075                         && field_index == rhs.field_index
00076                         && prefix == rhs.prefix;
00077         };
00078 
00079         bool operator!=(const MultiParamFieldIterator &rhs) {
00080                 return !operator==(rhs);
00081         };
00082 
00083         std::array<Record *,N> operator*() {
00084                 std::array<Record *,N> result;
00085                 String field_name = prefix + String::toString(field_index);
00086                 for (size_t i = 0; i < N; ++i)
00087                         result[i] = &records[i]->rwSubRecord(field_name);
00088                 return result;
00089         };
00090 
00091         static MultiParamFieldIterator<N> begin(std::array<Record *,N> &recs,
00092                                                 const string &prefix = "") {
00093                 return MultiParamFieldIterator(recs, prefix);
00094         };
00095 
00096         static MultiParamFieldIterator<N> end(std::array<Record *,N> &recs,
00097                                               const string &prefix = "") {
00098                 MultiParamFieldIterator result(recs, prefix);
00099                 result.field_index = recs[0]->nfields();
00100                 return result;
00101         };
00102 };
00103 
00104 } // namespace casa
00105 
00106 #endif // MULTI_PARAM_FIELD_ITERATOR_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1