Skip to content

Commit

Permalink
code review: add more comments
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Hanca <[email protected]>
  • Loading branch information
jhanca-robotecai committed Dec 13, 2023
1 parent 723c9cf commit 949fb4f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ namespace ROS2
serializeContext->EnumerateAll(
[&](const AZ::SerializeContext::ClassData* classData, const AZ::Uuid& typeId) -> bool
{
return ParseAttributes<SDFormat::SensorImporterHooksStorage>(m_sensorHooks, classData, "SensorImporterHooks");
return CopyHooksCallback<SDFormat::SensorImporterHooksStorage>(m_sensorHooks, classData, "SensorImporterHooks");
});

serializeContext->EnumerateAll(
[&](const AZ::SerializeContext::ClassData* classData, const AZ::Uuid& typeId) -> bool
{
return ParseAttributes<SDFormat::ModelPluginImporterHooksStorage>(
return CopyHooksCallback<SDFormat::ModelPluginImporterHooksStorage>(
m_modelPluginHooks, classData, "ModelPluginImporterHooks");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ namespace ROS2
const SDFormat::SensorImporterHooksStorage& GetSensorHooks() const override;
const SDFormat::ModelPluginImporterHooksStorage& GetModelPluginHooks() const override;

// Method for parsing attributes used for both sensor importer hooks and model plugin importer hooks
//! Callback for finding hooks defined in class reflection for certain SerializeContext attribute. This callback should be used
//! with EnumerateAll method and it is meant to be called only once, as the search results are copied and can be reused.
//! @param outputBuffer output buffer where hooks are copied
//! @param classData serialization context in which queried attribute might exist.
//! @param attributeName name of the attribute used to store hooks.
//! @return true if not found; false if found (stop iterating)
template<typename T>
bool ParseAttributes(T& outputBuffer, const AZ::SerializeContext::ClassData* classData, const AZStd::string& attributeName)
bool CopyHooksCallback(T& outputBuffer, const AZ::SerializeContext::ClassData* classData, const AZStd::string& attributeName)
{
auto* attribute = AZ::FindAttribute(AZ::Crc32(attributeName.c_str()), classData->m_attributes);
if (attribute == nullptr)
{
return true;
return true; // attribute not found; keep iterating
}

AZ::AttributeReader reader(nullptr, attribute);
Expand All @@ -64,7 +69,7 @@ namespace ROS2
outputBuffer.insert(outputBuffer.end(), readData.begin(), readData.end());
}

return false;
return false; // attribute found, hooks copied; stop iterating
}

// Timeout for loop waiting for assets to be built
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ namespace ROS2
}
}

// Use the first entity based on a link that is not parented to any other link
// Add control components to links that are not parented to any other link (first link of each model) based on SDFormat data.
if (!linkEntityIdsWithoutParent.empty())
{
for (const auto& [contentEntityId, modelPtr] : linkEntityIdsWithoutParent)
Expand Down

0 comments on commit 949fb4f

Please sign in to comment.