Support native_type for tables when using the C++ object API. (#8668)

* Support native_type for tables when using the C++ object API.

If native_type is specified on a table:
- No object API struct type is generated.
- The object API refers to the table by its native_type.
- UnPack and Create<TableName> methods are declared but not defined; as they
  must be user-provided.

* Add tests for native_type on tables.

* Add documentation for native_type on tables.
This commit is contained in:
cosmith-nvidia
2025-11-05 07:50:10 -08:00
committed by GitHub
parent 4173b84d4b
commit 599847236c
7 changed files with 251 additions and 153 deletions

View File

@@ -920,6 +920,15 @@ void NativeTypeTest() {
Native::Vector3D(20 * i + 0.1f, 20 * i + 0.2f, 20 * i + 0.3f));
}
src_data.matrix = std::make_unique<Native::Matrix>(1, 2);
src_data.matrix->values = {3, 4};
for (int i = 0; i < N; ++i) {
src_data.matrices.push_back(std::make_unique<Native::Matrix>(1, i));
std::fill(src_data.matrices[i]->values.begin(),
src_data.matrices[i]->values.end(), i + 0.5f);
}
flatbuffers::FlatBufferBuilder fbb;
fbb.Finish(Geometry::ApplicationData::Pack(fbb, &src_data));
@@ -943,6 +952,20 @@ void NativeTypeTest() {
TEST_EQ(v2.y, 20 * i + 0.2f);
TEST_EQ(v2.z, 20 * i + 0.3f);
}
TEST_EQ(dstDataT->matrix->rows, 1);
TEST_EQ(dstDataT->matrix->columns, 2);
TEST_EQ(dstDataT->matrix->values[0], 3);
TEST_EQ(dstDataT->matrix->values[1], 4);
for (int i = 0; i < N; ++i) {
const Native::Matrix &m = *dstDataT->matrices[i];
TEST_EQ(m.rows, 1);
TEST_EQ(m.columns, i);
for (int j = 0; j < i; ++j) {
TEST_EQ(m.values[j], i + 0.5f);
}
}
}
// Guard against -Wunused-function on platforms without file tests.