IODA Bundle
Table.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2018 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 Simon Smart
12 /// @date Dec 2018
13 
14 #ifndef odc_core_Table_H
15 #define odc_core_Table_H
16 
17 #include <memory>
18 
19 #include "eckit/io/Buffer.h"
20 
22 #include "odc/core/MetaData.h"
23 #include "odc/core/Span.h"
24 
25 
26 namespace eckit { class DataHandle; }
27 
28 namespace odc {
29 namespace core {
30 
31 class DecodeTarget;
32 
33 //----------------------------------------------------------------------------------------------------------------------
34 
35 
36 class Table {
37 
38 public: // methods
39 
40  // Construct a table. This is a static function rather than a constructor
41  // so that we can return false for no-more-data rather than throwing an
42  // exception
43 
44  static std::unique_ptr<Table> readTable(ThreadSharedDataHandle& dh);
45 
46  eckit::Offset startPosition() const;
47  eckit::Offset nextPosition() const;
48  eckit::Length encodedDataSize() const;
49 
50  size_t rowCount() const;
51  size_t columnCount() const;
52  int32_t byteOrder() const;
53  bool otherByteOrder() const;
54 
55  const MetaData& columns() const;
56  const Properties& properties() const;
57 
58  eckit::Buffer readEncodedData();
59 
60  void decode(DecodeTarget& target);
61 
62  Span span(const std::vector<std::string>& columns, bool onlyConstant=false);
63  Span decodeSpan(const std::vector<std::string>& columns);
64 
65 private: // methods
66 
67  Table(const ThreadSharedDataHandle& dh);
68 
69  /// Lookups used for decoding. Memoised for efficiency
70  const std::map<std::string, size_t>& columnLookup();
71  const std::map<std::string, size_t>& simpleColumnLookup();
72 
73 private: // members
74 
76 
77  eckit::Offset startPosition_;
78  eckit::Offset dataPosition_;
79  eckit::Length dataSize_;
80  eckit::Offset nextPosition_;
81  int32_t byteOrder_;
82 
85 
86  // Lookups. Memoised for efficiency
87 
88  std::map<std::string, size_t> columnLookup_;
89  std::map<std::string, size_t> simpleColumnLookup_;
90 };
91 
92 
93 //----------------------------------------------------------------------------------------------------------------------
94 
95 } // namespace core
96 } // namespace odc
97 
98 #endif
eckit::Buffer readEncodedData()
Definition: Table.cc:74
eckit::Offset startPosition_
Definition: Table.h:77
Table(const ThreadSharedDataHandle &dh)
Definition: Table.cc:34
bool otherByteOrder() const
Definition: Table.cc:62
size_t columnCount() const
Definition: Table.cc:54
Properties properties_
Definition: Table.h:84
static std::unique_ptr< Table > readTable(ThreadSharedDataHandle &dh)
Definition: Table.cc:386
Span span(const std::vector< std::string > &columns, bool onlyConstant=false)
Definition: Table.cc:211
eckit::Length dataSize_
Definition: Table.h:79
eckit::Offset nextPosition() const
Definition: Table.cc:42
int32_t byteOrder_
Definition: Table.h:81
eckit::Offset nextPosition_
Definition: Table.h:80
Span decodeSpan(const std::vector< std::string > &columns)
Definition: Table.cc:295
eckit::Offset dataPosition_
Definition: Table.h:78
const Properties & properties() const
Definition: Table.cc:70
size_t rowCount() const
Definition: Table.cc:50
const std::map< std::string, size_t > & simpleColumnLookup()
Definition: Table.cc:104
const std::map< std::string, size_t > & columnLookup()
Lookups used for decoding. Memoised for efficiency.
Definition: Table.cc:83
int32_t byteOrder() const
Definition: Table.cc:58
void decode(DecodeTarget &target)
Definition: Table.cc:114
const MetaData & columns() const
Definition: Table.cc:66
std::map< std::string, size_t > columnLookup_
Definition: Table.h:88
eckit::Length encodedDataSize() const
Definition: Table.cc:46
std::map< std::string, size_t > simpleColumnLookup_
Definition: Table.h:89
eckit::Offset startPosition() const
Definition: Table.cc:37
MetaData metadata_
Definition: Table.h:83
ThreadSharedDataHandle dh_
Definition: Table.h:75
std::map< std::string, std::string > Properties
Definition: Header.h:35
Definition: ColumnInfo.h:23