casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiParamFieldIterator.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 //# MultiParamFielditerator.h: Multiple parameter iterator over Records
3 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
4 //# Associated Universities, Inc. Washington DC, USA.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 #ifndef MULTI_PARAM_FIELD_ITERATOR_H_
28 #define MULTI_PARAM_FIELD_ITERATOR_H_
29 
31 #include <casa/Containers/Record.h>
32 #include <iterator>
33 #include <array>
34 
35 namespace casa {
36 
37 template<size_t N>
39  : public std::iterator<std::forward_iterator_tag, std::array<casacore::Record *,N>,
40  int> {
41  std::array<casacore::Record *,N> records;
44 
45 public:
47  : records(std::array<casacore::Record *,N> {})
49  , field_index(0) {};
50 
52  std::array<casacore::Record *,N> &recs, const string prefix = "")
53  : records(recs)
55  , field_index(0) {};
56 
58  : records(fit.records)
59  , prefix(fit.prefix)
60  , field_index(fit.field_index) {};
61 
63  ++field_index;
64  return *this;
65  };
66 
68  MultiParamFieldIterator tmp(*this);
69  operator++();
70  return tmp;
71  };
72 
74  return records == rhs.records
75  && field_index == rhs.field_index
76  && prefix == rhs.prefix;
77  };
78 
80  return !operator==(rhs);
81  };
82 
83  std::array<casacore::Record *,N> operator*() {
84  std::array<casacore::Record *,N> result;
86  for (size_t i = 0; i < N; ++i)
87  result[i] = &records[i]->rwSubRecord(field_name);
88  return result;
89  };
90 
91  static MultiParamFieldIterator<N> begin(std::array<casacore::Record *,N> &recs,
92  const string &prefix = "") {
93  return MultiParamFieldIterator(recs, prefix);
94  };
95 
96  static MultiParamFieldIterator<N> end(std::array<casacore::Record *,N> &recs,
97  const string &prefix = "") {
98  MultiParamFieldIterator result(recs, prefix);
99  result.field_index = recs[0]->nfields();
100  return result;
101  };
102 };
103 
104 } // namespace casa
105 
106 #endif // MULTI_PARAM_FIELD_ITERATOR_H_
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
static MultiParamFieldIterator< N > end(std::array< casacore::Record *, N > &recs, const string &prefix="")
bool operator!=(const MultiParamFieldIterator &rhs)
MultiParamFieldIterator(const MultiParamFieldIterator &fit)
static MultiParamFieldIterator< N > begin(std::array< casacore::Record *, N > &recs, const string &prefix="")
A hierarchical collection of named fields of various types.
Definition: Record.h:180
std::array< casacore::Record *, N > records
uInt N
Axis number.
Definition: ArrayAccessor.h:60
std::array< casacore::Record *, N > operator*()
MultiParamFieldIterator operator++()
String: the storage and methods of handling collections of characters.
Definition: String.h:223
bool operator==(const MultiParamFieldIterator &rhs)
MultiParamFieldIterator operator++(int)
unsigned int uInt
Definition: aipstype.h:51
static String toString(const T &value)
Convert a value to a String.
Definition: String.h:614
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
MultiParamFieldIterator(std::array< casacore::Record *, N > &recs, const string prefix="")