Skip to content

Added rfl::Commented; resolves #597#602

Open
liuzicheng1987 wants to merge 13 commits intomainfrom
f/comments
Open

Added rfl::Commented; resolves #597#602
liuzicheng1987 wants to merge 13 commits intomainfrom
f/comments

Conversation

@liuzicheng1987
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @liuzicheng1987, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant feature by adding the rfl::Commented<T> wrapper, which allows developers to embed descriptive comments directly within their data structures. These comments are then seamlessly serialized into formats like YAML and XML, greatly improving the readability and maintainability of the generated output. The implementation ensures that comments are handled as write-only metadata, focusing on enhancing the clarity of serialized data without affecting deserialization logic.

Highlights

  • New rfl::Commented Wrapper: Introduced a new rfl::Commented<T> class template that allows associating an optional comment string with any data field T. This enhances the self-documenting capabilities of serialized data.
  • YAML and XML Comment Support: The rfl::Commented wrapper is fully integrated with YAML and XML serialization, enabling comments to be written directly into the output. Comments are rendered as line comments (#) in YAML and <!-- comment --> blocks in XML.
  • Write-Only Comment Functionality: Comments added via rfl::Commented are write-only; they are preserved during serialization but are intentionally ignored during deserialization, as is common practice for comments in data formats.
  • Comprehensive Documentation and Testing: New documentation (docs/commented.md) has been added to explain the usage and API of rfl::Commented, complemented by dedicated unit tests for both XML and YAML serialization to ensure correct functionality.
Changelog
  • README.md
    • Updated the list of custom containers to include rfl::Commented.
  • docs/commented.md
    • Added new documentation for rfl::Commented, explaining its purpose, usage with YAML and XML examples, and API details.
  • docs/docs-readme.md
    • Added a link to the new rfl::Commented documentation page.
  • include/rfl.hpp
    • Included the new rfl/Commented.hpp header.
    • Corrected a duplicate include for rfl/CamelCaseToSnakeCase.hpp.
  • include/rfl/Commented.hpp
    • New file: Defines the rfl::Commented<T> class template, which wraps a value and an optional comment, providing constructors and accessors.
  • include/rfl/parsing/Parent.hpp
    • Included supports_comments.hpp.
    • Added a static add_comment method to Parent to allow writers to attach comments to array or object elements.
  • include/rfl/parsing/Parser.hpp
    • Included the new Parser_commented.hpp.
  • include/rfl/parsing/Parser_commented.hpp
    • New file: Implements the Parser specialization for rfl::Commented<T>, handling serialization of comments (for supported writers) and ignoring them during deserialization.
  • include/rfl/parsing/supports_comments.hpp
    • New file: Defines a C++ concept supports_comments to identify writers that can handle comments.
  • include/rfl/xml/Writer.hpp
    • Updated namespace declaration to rfl::xml.
    • Added declarations for add_comment_to_array and add_comment_to_object methods.
    • Minor formatting adjustment in a comment.
  • include/rfl/yaml/Writer.hpp
    • Updated namespace declaration to rfl::yaml.
    • Modified parameter names for add_array_to_array and add_array_to_object to indicate unused arguments.
    • Added declarations for add_comment_to_array, add_comment_to_object, and new_comment methods.
  • mkdocs.yaml
    • Updated the documentation navigation menu to include rfl::Commented.
  • src/rfl/xml/Writer.cpp
    • Implemented add_comment_to_array and add_comment_to_object to append XML comment nodes.
    • Simplified Ref<pugi::xml_node>::make calls for root element creation.
  • src/rfl/yaml/Writer.cpp
    • Implemented add_comment_to_array, add_comment_to_object, and new_comment methods to integrate YAML comments into the output.
  • tests/xml/test_comment.cpp
    • New file: Added a unit test to verify rfl::Commented functionality with XML serialization.
  • tests/yaml/test_comment.cpp
    • New file: Added a unit test to verify rfl::Commented functionality with YAML serialization.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces rfl::Commented, a useful feature for adding comments to serialized data in formats that support them, like YAML and XML. The implementation is comprehensive, covering the new type, parser specializations, and updates to the XML and YAML writers. The documentation and tests are also well-written.

I've found a few issues, mostly in the rfl::Commented class implementation regarding converting constructors and assignment operators, which could lead to data loss (comments being discarded) or compilation errors. There's also a minor issue with JSON schema generation for Commented<T> and a couple of small typos/inconsistencies. Addressing these points will improve the robustness and consistency of the new feature.

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.

1 participant