IODA Bundle
MDUpdatingIterator.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 ///
12 /// \file MDUpdatingIterator.cc
13 ///
14 /// @author Piotr Kuchta, March 2012
15 
16 namespace odc {
17 
18 template <typename T>
19 MDUpdatingIterator<T>::MDUpdatingIterator (T& ii, const T& end, const std::vector<std::string>& columns, const std::vector<std::string>& types)
20 : ii_(ii),
21  end_(end),
22  columns_(columns),
23  columnIndices_(columns.size()),
24  types_(types),
25  bitfieldDefs_(),
26  md_(ii->columns()),
27  data_(0),
28  refCount_(0),
29  noMore_(false)
30 {
31  ASSERT(columns.size() == types.size());
32  for (size_t i = 0; i < types.size(); ++i)
33  {
34  eckit::Log::info() << columns[i] << " : " << types[i] << std::endl;
35 
36  // Only bitfoelds now:
37  // [active:1;passive:1;rejected:1;blacklisted:1;use_emiskf_only:1;monthly:1;constant:1;experimental:1;whitelist:]
38  ASSERT(types[i].size());
39  ASSERT(types[i][0] == '[');
40  ASSERT(types[i][types[i].size() - 1] == ']');
41 
42  BitfieldDef bf;
43  std::vector<std::string> parts(eckit::StringTools::split(";", types[i].substr(1, types[i].size() - 2)));
44  for (size_t p = 0; p < parts.size(); ++p)
45  {
46  std::vector<std::string> field = eckit::StringTools::split(":", parts[p]);
47  bf.first.push_back(field[0]);
48  bf.second.push_back(atoi(field[1].c_str()));
49  }
50  bitfieldDefs_.push_back(bf);
51  eckit::Log::info() << "" << i << ": " << columns[i] << " - " << bf.first << std::endl; // "[" << bf.second << "]" << std::endl;
52  }
53 
54  update();
55 }
56 
57 template <typename T>
59 : ii_(end),
60  end_(end),
61  columnIndices_(),
62  types_(),
63  md_(0),
64  data_(0),
65  refCount_(0),
66  noMore_(true)
67 {}
68 
69 template <typename T>
71 
72 template <typename T>
74 {
75  md_ = ii_->columns();
76  for (size_t i = 0; i < columns_.size(); ++i)
77  md_[md_.columnIndex(columns_[i])]->bitfieldDef(bitfieldDefs_[i]);
78  return md_;
79 }
80 
81 template <typename T>
83 {
84  columns();
85  data_ = const_cast<double*>(ii_->data());
86 }
87 
88 template <typename T>
89 bool MDUpdatingIterator<T>::isNewDataset() { return ii_->isNewDataset(); }
90 
91 template <typename T>
93 {
94  if (noMore_)
95  return noMore_;
96  ++ii_;
97  bool r = ii_ != end_;
98  if (r)
99  {
100  if (ii_->isNewDataset())
101  update();
102  }
103  noMore_ = !r;
104  return r;
105 }
106 
107 } // namespace odc
108 
std::vector< BitfieldDef > bitfieldDefs_
MDUpdatingIterator(T &inputIterator, const T &end, const std::vector< std::string > &columns, const std::vector< std::string > &types)
Definition: ColumnInfo.h:23