Skip to content

Commit

Permalink
Minor update in logic: do the endpoint selection when next is called
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Jan 13, 2025
1 parent 8155339 commit f6c2d79
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/app/AttributePathExpandIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,7 @@ namespace app {

AttributePathExpandIterator::AttributePathExpandIterator(DataModel::Provider * dataModel, Position & position) :
mDataModelProvider(dataModel), mPosition(position)
{
mEndpoints = dataModel->Endpoints();

// Position on the correct endpoint ...
if (mPosition.mOutputPath.mEndpointId != kInvalidEndpointId)
{
for (mEndpointIndex = 0; mEndpointIndex < mEndpoints.size(); mEndpointIndex++)
{
if (mEndpoints[mEndpointIndex].id == mPosition.mOutputPath.mEndpointId)
{
break;
}
}
}
}
{}

bool AttributePathExpandIterator::AdvanceOutputPath()
{
Expand Down Expand Up @@ -231,6 +217,22 @@ std::optional<ClusterId> AttributePathExpandIterator::NextClusterId()

std::optional<EndpointId> AttributePathExpandIterator::NextEndpointId()
{
if (mEndpointIndex == kInvalidIndex)
{
// index is missing, have to start a new iteration
mEndpoints = mDataModelProvider->Endpoints();

if (mPosition.mOutputPath.mEndpointId != kInvalidEndpointId)
{
// Position on the correct endpoint if we have a start point
mEndpointIndex = 0;
while ((mEndpointIndex < mEndpoints.size()) && (mEndpoints[mEndpointIndex].id != mPosition.mOutputPath.mEndpointId))
{
mEndpointIndex++;
}
}
}

if (mPosition.mOutputPath.mEndpointId == kInvalidEndpointId)
{
if (!mPosition.mAttributePath->mValue.HasWildcardEndpointId())
Expand All @@ -247,11 +249,10 @@ std::optional<EndpointId> AttributePathExpandIterator::NextEndpointId()
VerifyOrReturnValue(mPosition.mAttributePath->mValue.HasWildcardEndpointId(), std::nullopt);
mEndpointIndex++;
}
if (mEndpointIndex < mEndpoints.size())
{
return mEndpoints[mEndpointIndex].id;
}
return std::nullopt;

VerifyOrReturnValue(mEndpointIndex < mEndpoints.size(), std::nullopt);

return mEndpoints[mEndpointIndex].id;
}

} // namespace app
Expand Down

0 comments on commit f6c2d79

Please sign in to comment.