Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add typename method #8437

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pablogm
Copy link

@pablogm pablogm commented Nov 6, 2024

Summary

This pull request adds a new feature to the FlatBuffers compiler (flatc) to generate a TypeName() method in each C++ table and struct. This method returns the fully qualified type name (including namespace) as a string.

Changes Introduced

  • Introduced a new utility function, MakeFullyQualifiedName, to construct fully qualified names using namespaces and type names.
  • Updated the GenTable method in idl_gen_cpp.cpp to include a TypeName() method in generated C++ classes when a custom flag is enabled.
  • Added a new flag (--gen-type-names) to flatc to optionally generate the TypeName() method.

Motivation

The TypeName() method allows developers to access the fully qualified name of a table or struct at runtime, similarly to what Protobuf offers with T::descriptor()->full_name().

Usage

With the --gen-type-names flag, generated C++ code will include a TypeName() method

For the commit message, it’s important to keep it concise but informative. Here’s a recommended format:

Suggested Commit Message:
typescript
Copy code
feat: add TypeName() method to generated C++ tables for type identification

- Added a `TypeName()` method to generated C++ code to return the fully qualified type name (namespace.type).
- Introduced the `MakeFullyQualifiedName` utility function to construct fully qualified type names.
- Added a new `--gen-type-names` flag to `flatc` to enable this feature.
- Updated `GenTable` method in `idl_gen_cpp.cpp` to generate the `TypeName()` method when the flag is set.
Copy link

google-cla bot commented Nov 6, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant