Skip to content

chore: Refactor stats_line into StatsBuilder#631

Merged
elshize merged 3 commits intomainfrom
stats-builder
Feb 16, 2026
Merged

chore: Refactor stats_line into StatsBuilder#631
elshize merged 3 commits intomainfrom
stats-builder

Conversation

@elshize
Copy link
Member

@elshize elshize commented Feb 1, 2026

No description provided.

@elshize elshize force-pushed the stats-builder branch 5 times, most recently from 4abf7eb to 1bc3e75 Compare February 5, 2026 22:48
*/
class StatsBuilder {
private:
std::unique_ptr<::pisa::detail::StatsBuilderInterface> m_impl;
Copy link
Member Author

Choose a reason for hiding this comment

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

Separating implementation details to the source file so that we can keep nlohmann dependency private.

virtual void add(std::string const& key, double value) { m_json[key] = value; }
virtual void add(std::string const& key, std::string value) { m_json[key] = std::move(value); }
virtual void add(std::string const& key, const char* value) { m_json[key] = value; }
[[nodiscard]] virtual auto build() const -> std::string { return m_json.dump(2); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think build sounds as something that becomes immutable (or finalized) once it is "built". But in this case, I can build it and then continue adding elements to the structure. Maybe a better name could be str/to_str?

As a follow-up, if we make this change, we could also consider renaming pisa::stats_builder() by pisa::json_stats.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I think this makes sense, I'll make the suggested changes once I find a moment.


namespace pisa {

class JsonStatsBuilder: public ::pisa::detail::StatsBuilderInterface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think JsonStatsBuilder sounds verbose (very Java-style). Maybe JsonStats could be enough? That would make sense, since we could expose a str method instead of having a build method (comment in line 31).

@gustingonzalez
Copy link
Collaborator

@elshize, looks good to me!

@elshize elshize merged commit dc6d00b into main Feb 16, 2026
7 checks passed
@elshize elshize deleted the stats-builder branch February 16, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants