IODA Bundle
Reader.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 #include "odc/Reader.h"
12 
13 #include "eckit/io/DataHandle.h"
14 
16 
17 using namespace std;
18 using namespace eckit;
19 
20 namespace odc {
21 
22 Reader::Reader(DataHandle &dh)
23 : dataHandle_(&dh),
24  deleteDataHandle_(false)
25 {}
26 
28 : dataHandle_(0),
29  deleteDataHandle_(true),
30  path_("")
31 {}
32 
34  dataHandle_(rhs.dataHandle_),
35  deleteDataHandle_(rhs.deleteDataHandle_),
36  path_(std::move(rhs.path_)) {
37 
38  rhs.dataHandle_ = 0;
39  rhs.deleteDataHandle_ = false;
40 }
41 
43  std::swap(dataHandle_, rhs.dataHandle_);
44  std::swap(deleteDataHandle_, rhs.deleteDataHandle_);
45  std::swap(path_, rhs.path_);
46  return *this;
47 }
48 
49 Reader::Reader(const std::string& path)
50 : dataHandle_(DataHandleFactory::openForRead(path)),
51  deleteDataHandle_(true),
52  path_(path)
53 {}
54 
56 {
58  {
59  dataHandle_->close();
60  delete dataHandle_;
61  }
62 }
63 
64 ReaderIterator* Reader::createReadIterator(const PathName& pathName)
65 {
66  return new ReaderIterator(*this, pathName);
67 }
68 
70 {
72 }
73 
75 {
76  ReaderIterator * it = new ReaderIterator(*this);
77  it->next();
78  return iterator(it);
79 }
80 
82  return iterator(0);
83 }
84 
86 {
88  {
89  dataHandle_->close();
90  delete dataHandle_;
91  }
92  dataHandle_ = 0;
93 }
94 
95 eckit::DataHandle* Reader::dataHandle()
96 {
97  // Assume the Reader was constructed with a path, and not a DataHandle*
98  if (! dataHandle_)
100  return dataHandle_;
101 }
102 
103 } // namespace odc
static eckit::DataHandle * openForRead(const std::string &)
void noMoreData()
Definition: Reader.cc:85
eckit::DataHandle * dataHandle()
Definition: Reader.cc:95
ReaderIterator * createReadIterator()
Definition: Reader.cc:69
std::string path_
Definition: Reader.h:66
IteratorProxy< ReaderIterator, Reader, const double > iterator
Definition: Reader.h:34
virtual ~Reader()
Definition: Reader.cc:55
bool deleteDataHandle_
Definition: Reader.h:65
eckit::DataHandle * dataHandle_
Definition: Reader.h:64
friend class ReaderIterator
Definition: Reader.h:69
const iterator end() const
Definition: Reader.cc:81
Reader & operator=(Reader &&rhs)
Definition: Reader.cc:42
iterator begin()
Definition: Reader.cc:74
Definition: ColumnInfo.h:23
Definition: encode.cc:30