Skip to content

Commit

Permalink
Fixed issue #710. SetInterest caused dataitems not to be properly ini…
Browse files Browse the repository at this point in the history
…tialized for writing.
  • Loading branch information
eoudejans committed Apr 10, 2024
1 parent 95fc133 commit 4b4d963
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
17 changes: 8 additions & 9 deletions stg/dll/src/gdal/gdal_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,18 +884,17 @@ void DataItemsWriteStatusInfo::SetLaunderedName(TokenID layerID, TokenID fieldID

void DataItemsWriteStatusInfo::RefreshInterest(const TreeItem* storageHolder)
{
for (auto subItem = storageHolder->WalkConstSubTree(nullptr); subItem; subItem = storageHolder->WalkConstSubTree(subItem))
for (auto sub_item = storageHolder->WalkConstSubTree(nullptr); sub_item; sub_item = storageHolder->WalkConstSubTree(sub_item))
{
if (not (IsDataItem(subItem) and subItem->IsStorable()))
if (not (IsDataItem(sub_item) and sub_item->IsStorable()))
continue;

auto unitItem = GetLayerHolderFromDataItem(storageHolder, subItem);
SharedStr layerName(unitItem->GetName().c_str());
SharedStr fieldName(subItem->GetName().c_str());
if (subItem->GetInterestCount() && !m_LayerAndFieldIDMapping[GetTokenID_mt(layerName)][GetTokenID_mt(fieldName)].isWritten)
setInterest(GetTokenID_mt(layerName), GetTokenID_mt(fieldName), true);
else
setInterest(GetTokenID_mt(layerName), GetTokenID_mt(fieldName), false);
auto unit_item = GetLayerHolderFromDataItem(storageHolder, sub_item);

auto layer_id = unit_item->GetID();
auto field_id = sub_item->GetID();
bool sub_item_has_interest = sub_item->GetInterestCount(); // && m_LayerAndFieldIDMapping.contains(layer_id) && !m_LayerAndFieldIDMapping[layer_id][field_id].isWritten;
setInterest(layer_id, field_id, sub_item_has_interest);
}
}

Expand Down
26 changes: 12 additions & 14 deletions stg/dll/src/gdal/gdal_vect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,38 +1562,37 @@ void GdalVectSM::WriteLayer(TokenID layer_id, const GdalMetaInfo& gmi)
bool GdalVectSM::WriteDataItem(StorageMetaInfoPtr&& smiHolder)
{
DBG_START("gdalwrite.vect", "WriteDataItem", false);

auto smi = smiHolder.get();
const auto& gmi = dynamic_cast<const GdalMetaInfo&>(*smi);
auto driver_array = GetOptionArray(gmi.m_DriverItem);
SharedStr data_source_name = smi->StorageManager()->GetNameStr();

const TreeItem* storage_holder = smi->StorageHolder();
const AbstrDataItem* adi = smi->CurrRD();
const TreeItem* storage_holder = smi->StorageHolder();
const AbstrDataItem* adi = smi->CurrRD();

if (not adi->IsStorable())
return true;

const AbstrDataObject* ado = adi->GetRefObj();
auto adu = adi->GetAbstrDomainUnit();
auto avu = adi->GetAbstrValuesUnit();
const ValueClass* vc = ado->GetValuesType();
ValueClassID vcID = vc->GetValueClassID();
const AbstrDataObject* ado = adi->GetRefObj();
auto adu = adi->GetAbstrDomainUnit();
auto avu = adi->GetAbstrValuesUnit();
const ValueClass* vc = ado->GetValuesType();
ValueClassID vcID = vc->GetValueClassID();

auto unit_item = GetLayerHolderFromDataItem(storage_holder, adi);
auto layer_id = unit_item->GetID();
auto fieldID = adi->GetID();

if (not m_DataItemsStatusInfo.m_initialized) // first time writing
{
m_DataItemsStatusInfo.RefreshInterest(storage_holder);

if (not m_DataItemsStatusInfo.m_initialized) { // first time writing
PrepareDataItemsForWriting(*smi, m_DataItemsStatusInfo);
m_DataItemsStatusInfo.m_initialized = true;
}

m_DataItemsStatusInfo.RefreshInterest(storage_holder); // user may have set other iterests at this point.
m_DataItemsStatusInfo.SetInterestForDataHolder(layer_id, fieldID, adi); // write once all dataitems are ready

if (not m_DataItemsStatusInfo.LayerIsReadyForWriting(layer_id))
return true;

Expand All @@ -1606,8 +1605,7 @@ bool GdalVectSM::WriteDataItem(StorageMetaInfoPtr&& smiHolder)

if (driver_supports_update) // write layers incrementally
WriteLayer(layer_id, gmi);
else // write whole dataset in one go
{
else { // write whole dataset in one go
for (auto& layer : m_DataItemsStatusInfo.m_LayerAndFieldIDMapping)
WriteLayer(layer.first, gmi);
}
Expand Down

0 comments on commit 4b4d963

Please sign in to comment.