Skip to content

feat: adding JsonKindDispatcher + Surface conversion#5195

Open
ssdetlab wants to merge 12 commits intoacts-project:mainfrom
ssdetlab:surface-json-converter-fixes
Open

feat: adding JsonKindDispatcher + Surface conversion#5195
ssdetlab wants to merge 12 commits intoacts-project:mainfrom
ssdetlab:surface-json-converter-fixes

Conversation

@ssdetlab
Copy link
Contributor

@ssdetlab ssdetlab commented Mar 5, 2026

Adding JsonKindDispatcher that unifies the interface for the json conversion.

Refactoring the Surface json conversion to TypeDispatcher + JsonKindDispatcher flow.

SurfaceJsonConverter is now a class that stores the json encoders/decoders and its Config members.
The class is static, since a lot of external conversion depends on the conversion functions being statically accessible.
Could be refactored later (e.g., refactor all the json converters to classes and pass the surface converter as a Config member).

The kind of the Surface + Bounds type is performed by two independent functions, in case there will be changes to the way the type is handled.

PerigeeSurface is handled independently outside of the dispatcher structure, since it does not follow the usual constructor argument convention.
The said constructor could be added to unify the interface.

The PR also adds GeometryIdentifier conversion with the dedicated converter and fixes the material conversion bug.

@github-actions github-actions bot added this to the next milestone Mar 5, 2026
@github-actions github-actions bot added the Component - Plugins Affects one or more Plugins label Mar 5, 2026
@ssdetlab
Copy link
Contributor Author

ssdetlab commented Mar 5, 2026

Introduced an additional overload for boundless surfaces to unify the interface

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

📊: Physics performance monitoring for 01a9538

Full contents

physmon summary

}

template <typename surface_t>
std::string getSurfaceKind() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to cpp file

/// @return a shared object created from json input
static std::shared_ptr<Surface> fromJson(const nlohmann::json& jSurface);

static Config m_cfg;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being static means that it can't be extended at this time, right?

Maybe this should also be private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it private. Added a setter for the time being. When the migration to the dispatcher pattern is finished, we can just make a regular constructor for this

}

if constexpr (std::is_void_v<return_t>) {
decoder->second(encoded, std::forward<args_t>(args)...);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only forward if the function was

  template <typename... Ts>
  return_t operator()(const nlohmann::json& encoded, Ts&&... args) const {

so the template function needs to accept Ts&&, only then are they universal references and can be forwarded. I think we probably want to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this a forwarding reference

///
/// @return string representation of the surface bounds kind
template <typename bounds_t>
std::string getSurfaceBoundsKind() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function and the other templated functions are only used in the .cpp file. Can you move them there instead of having them in the header here? That would also allow removing the added headers and moving them into the .cpp only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the templates to the cpp. Cleaned up the headers


#include <memory>

#include <nlohmann/json_fwd.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .cpp file should probably include the full header I suppose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this -- clangd adds these automatically sometimes, missed this one

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component - Plugins Affects one or more Plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants