IODA Bundle
ODAUpdatingIterator.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 ODAUpdatingIterator.cc
13 ///
14 /// @author Piotr Kuchta, June 2009
15 
16 #include "odc/core/MetaData.h"
17 
18 namespace odc {
19 
20 template <typename T>
21 ODAUpdatingIterator<T>::ODAUpdatingIterator (T& ii, const T& end, const std::vector<std::string>& columns, const std::vector<double>& values)
22 : ii_(ii),
23  end_(end),
24  columns_(columns),
25  columnIndices_(columns.size()),
26  values_(values),
27  data_(0),
28  refCount_(0),
29  noMore_(false)
30 {
31  ASSERT(columns.size() == values.size());
32 
33  updateIndices();
34  std::copy(ii_->data(), ii_->data() + ii_->columns().size(), data_);
35  update();
36 }
37 
38 template <typename T>
40 {
41  const core::MetaData& md (ii_->columns());
42 
43  delete [] data_;
44  data_ = new double[md.size()];
45 
46  for (size_t i = 0; i < columns_.size(); ++i)
47  columnIndices_[i] = md.columnIndex(columns_[i]);
48 }
49 
50 template <typename T>
52 : ii_(end),
53  end_(end),
54  columnIndices_(),
55  values_(),
56  data_(0),
57  refCount_(0),
58  noMore_(true)
59 {}
60 
61 template <typename T>
63 
64 template <typename T>
66 {
67  for (size_t i = 0; i < columnIndices_.size(); ++i)
68  data_[columnIndices_[i]] = values_[i];
69 }
70 
71 template <typename T>
73 {
74  return ii_->isNewDataset();
75 }
76 
77 template <typename T>
79 {
80  if (noMore_)
81  return noMore_;
82  ++ii_;
83  bool r = ii_ != end_;
84  if (r)
85  {
86  if (ii_->isNewDataset())
87  updateIndices();
88 
89  std::copy(ii_->data(), ii_->data() + ii_->columns().size(), data_);
90  update();
91  }
92  noMore_ = !r;
93  return r;
94 }
95 
96 } // namespace odc
97 
const core::MetaData & columns()
ODAUpdatingIterator(T &inputIterator, const T &end, const std::vector< std::string > &columns, const std::vector< double > &values)
size_t columnIndex(const std::string &) const
Definition: MetaData.cc:95
IODA_DL void copy(const ObjectSelection &from, ObjectSelection &to, const ScaleMapping &scale_map)
Generic data copying function.
Definition: Copying.cpp:63
Definition: ColumnInfo.h:23