IODA Bundle
TODATable.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 /// ECMWF Oct 2010
14 
15 #ifndef TODATable_H
16 #define TODATable_H
17 
18 #include "eckit/sql/SQLTable.h"
19 
20 #include "odc/Reader.h"
21 #include "odc/csv/TextReader.h"
22 
23 
24 namespace odc {
25 namespace sql {
26 
27 //----------------------------------------------------------------------------------------------------------------------
28 
29 template <typename READER>
30 class TODATable : public eckit::sql::SQLTable {
31 public:
32 
33  TODATable(eckit::sql::SQLDatabase& owner, const std::string& path, const std::string& name);
34  TODATable(eckit::sql::SQLDatabase& owner, eckit::DataHandle& dh);
35 
36  virtual ~TODATable();
37 
38  const READER& oda() const;
39 
40 private: // methods
41 
42  void populateMetaData();
43 // void updateMetaData(const std::vector<SQLColumn*>&);
44 
45 protected: // methods
46 
47  TODATable(eckit::sql::SQLDatabase& owner, const std::string& path, const std::string& name, READER&& oda);
48 
49 private: // methods (overrides)
50 
51  virtual bool hasColumn(const std::string&) const override;
52  virtual const eckit::sql::SQLColumn& column(const std::string&) const override;
53 
54  virtual eckit::sql::SQLTableIterator* iterator(const std::vector<std::reference_wrapper<const eckit::sql::SQLColumn>>&,
55  std::function<void(eckit::sql::SQLTableIterator&)> metadataUpdateCallback) const override;
56 
57  virtual void print(std::ostream& s) const override;
58 
59 public:
60 
61  READER oda_;
62 };
63 
64 //----------------------------------------------------------------------------------------------------------------------
65 
66 // Specific cases for Reader and TextReader
67 
68 extern template class TODATable<Reader>;
69 extern template class TODATable<TextReader>;
70 
71 struct ODATable : public TODATable<Reader> {
72  ODATable(eckit::sql::SQLDatabase& owner, const std::string& path, const std::string& name) :
73  TODATable<Reader>(owner, path, name, Reader(path)) {}
74  ODATable(eckit::sql::SQLDatabase& owner, eckit::DataHandle& dh) :
75  TODATable<Reader>(owner, "<>", "input", Reader(dh)) {}
76 };
77 
78 
80  ODBCSVTable(eckit::sql::SQLDatabase& owner, const std::string& path, const std::string& name, const std::string& delimiter) :
81  TODATable<TextReader>(owner, path, name, TextReader(path, delimiter)) {}
82  ODBCSVTable(eckit::sql::SQLDatabase& owner, std::istream& is, const std::string& name, const std::string& delimiter) :
83  TODATable<TextReader>(owner, "<none>", name, TextReader(is, delimiter)) {}
84 };
85 
86 
87 //----------------------------------------------------------------------------------------------------------------------
88 
89 } // namespace sql
90 } // namespace odc
91 
92 #endif
void oda
TODATable(eckit::sql::SQLDatabase &owner, const std::string &path, const std::string &name, READER &&oda)
TODATable(eckit::sql::SQLDatabase &owner, const std::string &path, const std::string &name)
virtual bool hasColumn(const std::string &) const override
Definition: TODATable.cc:167
void populateMetaData()
Definition: TODATable.cc:85
TODATable(eckit::sql::SQLDatabase &owner, eckit::DataHandle &dh)
const READER & oda() const
Definition: TODATable.cc:79
virtual const eckit::sql::SQLColumn & column(const std::string &) const override
Definition: TODATable.cc:196
virtual ~TODATable()
Definition: TODATable.cc:76
virtual void print(std::ostream &s) const override
Definition: TODATable.cc:229
virtual eckit::sql::SQLTableIterator * iterator(const std::vector< std::reference_wrapper< const eckit::sql::SQLColumn >> &, std::function< void(eckit::sql::SQLTableIterator &)> metadataUpdateCallback) const override
Definition: TODATable.cc:223
Definition: ColumnInfo.h:23
ODATable(eckit::sql::SQLDatabase &owner, const std::string &path, const std::string &name)
Definition: TODATable.h:72
ODATable(eckit::sql::SQLDatabase &owner, eckit::DataHandle &dh)
Definition: TODATable.h:74
ODBCSVTable(eckit::sql::SQLDatabase &owner, std::istream &is, const std::string &name, const std::string &delimiter)
Definition: TODATable.h:82
ODBCSVTable(eckit::sql::SQLDatabase &owner, const std::string &path, const std::string &name, const std::string &delimiter)
Definition: TODATable.h:80