Skip to content

Commit

Permalink
stub out repeatable iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopendlebury committed Jan 31, 2024
1 parent 5cd6815 commit 85f5e72
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/gribmessageiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ Iterator::Iterator(GribReader* reader,
Iterator& Iterator::operator++() {
delete m_ptr;
codes_handle* h = codes_handle_new_from_file(0, reader->fin, PRODUCT_GRIB, &err);
//printf("got new handle %p\n", h);
if (h == NULL) {
//printf("Last message, setting pointer to last message\n");
m_ptr = m_lastMessage;
} else {
message_id++;
Expand Down
14 changes: 14 additions & 0 deletions src/gribreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ GribReader GribReader::withLocations(std::shared_ptr<arrow::Table> locations) {
return *this;
}

GribReader GribReader::withRepeatableIterator(bool repeatable) {
//TODO - add some validation
this->isRepeatable = repeatable;
return *this;
}

void GribReader::validateConversionFields(std::shared_ptr<arrow::Table> locations, std::string table_name) {
auto table = locations.get();
auto columns = table->ColumnNames();
Expand Down Expand Up @@ -141,6 +147,8 @@ GribReader GribReader::withConversions(std::shared_ptr<arrow::Table> conversions
//the table should contain 2 columns "lat" and "lon"
validateConversionFields(conversions, " passed conversions via arrow");

//TODO - Validate types ?

auto rowConversion = ColumnarTableToVector(conversions);

for (auto row : rowConversion.ValueOrDie()) {
Expand Down Expand Up @@ -223,7 +231,13 @@ Iterator GribReader::begin() {
}

Iterator GribReader::end() {

if (isRepeatable) {
//TODO Make the iterator repeatable
//Not sure how yet need to play with how this iterfaces at the python __iter__, next() and StopIteration level
}
return Iterator( this, m_endMessage, m_endMessage );

}

std::optional<GribLocationData*> GribReader::getLocationDataFromCache(std::unique_ptr<GridArea>& area) {
Expand Down
2 changes: 2 additions & 0 deletions src/gribreader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GribReader
GribReader withLocations(std::string path);
GribReader withConversions(std::shared_ptr<arrow::Table> conversions);
GribReader withConversions(std::string path);
GribReader withRepeatableIterator(bool repeatable);

Iterator begin();
Iterator end();
Expand All @@ -49,6 +50,7 @@ class GribReader
private:
string filepath;
int err = 0;
bool isRepeatable = false;
std::shared_ptr<arrow::Table> shared_locations;
arrow::Table* conversions = NULLPTR;
std::unordered_map<GridArea, std::shared_ptr<arrow::Table>> locations_in_area;
Expand Down

0 comments on commit 85f5e72

Please sign in to comment.