ParamFieldIterator.h

Go to the documentation of this file.
00001 /* -*- mode: c++ -*- */
00002 //# ParamFieldIterator.h: Single field 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 PARAM_FIELD_ITERATOR_H_
00028 #define PARAM_FIELD_ITERATOR_H_
00029 
00030 #include <casa/Containers/Record.h>
00031 #include <iterator>
00032 
00033 namespace casa {
00034 
00035 class ParamFieldIterator
00036         : public std::iterator<std::forward_iterator_tag, Record *, int> {
00037         Record *record;
00038         String prefix;
00039         uInt field_index;
00040 
00041 public:
00042         ParamFieldIterator()
00043                 : record(nullptr)
00044                 , prefix("")
00045                 , field_index(0) {};
00046 
00047         ParamFieldIterator(Record *rec, const string &prefix = "")
00048                 : record(rec)
00049                 , prefix(String(prefix))
00050                 , field_index(0) {};
00051 
00052         ParamFieldIterator(const ParamFieldIterator &fit)
00053                 : record(fit.record)
00054                 , prefix(fit.prefix)
00055                 , field_index(fit.field_index) {};
00056 
00057         ParamFieldIterator & operator++() {
00058                 ++field_index;
00059                 return *this;
00060         };
00061 
00062         ParamFieldIterator operator++(int) {
00063                 ParamFieldIterator tmp(*this);
00064                 operator++();
00065                 return tmp;
00066         };
00067 
00068         bool operator==(const ParamFieldIterator &rhs) {
00069                 return record == rhs.record
00070                         && field_index == rhs.field_index
00071                         && prefix == rhs.prefix;
00072         };
00073 
00074         bool operator!=(const ParamFieldIterator &rhs) {
00075                 return !operator==(rhs);
00076         };
00077 
00078         Record & operator*() {
00079                 return record->rwSubRecord(prefix + String::toString(field_index));
00080         };
00081 
00082         static ParamFieldIterator begin(Record *rec, const string &prefix = "") {
00083                 return ParamFieldIterator(rec, prefix);
00084         };
00085 
00086         static ParamFieldIterator end(Record *rec, const string &prefix = "") {
00087                 ParamFieldIterator result(rec, prefix);
00088                 result.field_index = rec->nfields();
00089                 return result;
00090         };
00091 };
00092 
00093 }
00094 
00095 #endif // 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