ParamFieldIterator.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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_