IODA Bundle
SelectIterator.h
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 /// @author Piotr Kuchta
12 /// @author Simon Smart
13 /// @date Feb 2009
14 
15 #ifndef odc_SelectIterator_H
16 #define odc_SelectIterator_H
17 
18 #include "eckit/sql/expression/SQLExpressions.h"
19 #include "odc/api/ColumnType.h"
21 #include "eckit/sql/SQLSession.h"
22 
23 
24 // Forward declarations
25 
26 namespace odc {
27  class Select;
28  template <typename I, typename O, typename D> class IteratorProxy;
29  namespace core {
30  class MetaData;
31  }
32 }
33 
34 namespace eckit {
35  namespace SQL {
36  class SQLSelect;
37  }
38 }
39 
40 
41 namespace odc {
42 
43 //----------------------------------------------------------------------------------------------------------------------
44 
45 class SelectIterator : private eckit::NonCopyable {
46 public:
47 
48  SelectIterator (const std::string& select, eckit::sql::SQLSession& session, sql::SQLSelectOutput& output);
50 
51  // TODO: New dataset
52  bool isNewDataset() { return false; }
53  const double* data() const { return output_.data(); }
54 // double* data() { return data_; }
55  double& data(size_t i) { return output_.data(i); }
56 
57  const core::MetaData& columns() const { return output_.metadata(); }
58  const core::MetaData& columns(const core::MetaData&) { NOTIMP; }
59  void setNumberOfColumns(size_t) { NOTIMP; }
60 
61  const std::map<std::string, std::string>& properties() const { NOTIMP; }
62 
63  int close() { NOTIMP; }
64  int setColumn(size_t index, std::string name, api::ColumnType type) { NOTIMP; }
65  void writeHeader() { NOTIMP; }
66  int setBitfieldColumn(size_t index, std::string name, api::ColumnType type, eckit::sql::BitfieldDef b) { NOTIMP; }
67  void missingValue(size_t, double) { NOTIMP; }
68 
69  /// Set an output buffer for retrieving the next row(s)
70  void setOutputRowBuffer(double* data, size_t count=0);
71 
72  /// The offset of a given column in the doubles[] data array
73  size_t dataOffset(size_t i) const { return output_.dataOffset(i); }
74 
75  // Get the number of doubles per row.
76  size_t rowDataSizeDoubles() const { return output_.rowDataSizeDoubles(); }
77 
78  bool next();
79 
80 private:
81 
82  void parse();
83 
84  std::string select_;
85 
87 
88  eckit::sql::SQLSelect* selectStmt_; // n.b. non-owning
89 
90  eckit::sql::SQLSession& session_;
91 
92  // Just for integration with IteratorProxy. Yeaurgh.
93  // TODO: Remove this hack
94  bool noMore_;
95 
96 protected:
97  int refCount_;
98 
99  // This is a bit yucky, but the IteratorProxy essentially reimplements std::shared_ptr
100  // but not in a threadsafe way.
101  friend class odc::IteratorProxy<odc::SelectIterator, odc::Select, const double>;
102 };
103 
104 //----------------------------------------------------------------------------------------------------------------------
105 
106 } // namespace odc
107 
108 #endif
static void count(void *counter, const double *data, size_t n)
Definition: UnitTests.cc:531
const core::MetaData & columns(const core::MetaData &)
double & data(size_t i)
sql::SQLSelectOutput & output_
int setColumn(size_t index, std::string name, api::ColumnType type)
size_t rowDataSizeDoubles() const
int setBitfieldColumn(size_t index, std::string name, api::ColumnType type, eckit::sql::BitfieldDef b)
const core::MetaData & columns() const
void missingValue(size_t, double)
void setOutputRowBuffer(double *data, size_t count=0)
Set an output buffer for retrieving the next row(s)
SelectIterator(const std::string &select, eckit::sql::SQLSession &session, sql::SQLSelectOutput &output)
const double * data() const
const std::map< std::string, std::string > & properties() const
void setNumberOfColumns(size_t)
size_t dataOffset(size_t i) const
The offset of a given column in the doubles[] data array.
eckit::sql::SQLSession & session_
eckit::sql::SQLSelect * selectStmt_
const core::MetaData & metadata() const
const double * data() const
size_t rowDataSizeDoubles() const
size_t dataOffset(size_t i) const
Definition: ColumnInfo.h:23