mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
[C++] Add GetMutableSizePrefixedRoot and generate GetMutableSizePrefixedXxx functions (#6815)
* flattests_cpp17 doesn't compile with Visual Studio 2017: warning C4100: 'indent': unreferenced formal parameter
stringify_util.h(127): error C2220: warning treated as error - no 'object' file generated
stringify_util.h(127): warning C4100: 'indent': unreferenced formal parameter
stringify_util.h(85): warning C4100: 'indent': unreferenced formal parameter
stringify_util.h(85): warning C4100: 'fbs': unreferenced formal parameter
* [C++] Add GetMutableSizePrefixedRoot() and generate a GetMutableSizePrefixed function
When using the mutable API together with size prefixed buffers these functions should be present.
* clang-format
* Cleanup branch for PR
Revert "flattests_cpp17 doesn't compile with Visual Studio 2017: warning C4100: 'indent': unreferenced formal parameter"
This reverts commit a92055203e.
This commit is contained in:
@@ -2327,6 +2327,11 @@ template<typename T> T *GetMutableRoot(void *buf) {
|
||||
EndianScalar(*reinterpret_cast<uoffset_t *>(buf)));
|
||||
}
|
||||
|
||||
template<typename T> T *GetMutableSizePrefixedRoot(void *buf) {
|
||||
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) +
|
||||
sizeof(uoffset_t));
|
||||
}
|
||||
|
||||
template<typename T> const T *GetRoot(const void *buf) {
|
||||
return GetMutableRoot<T>(const_cast<void *>(buf));
|
||||
}
|
||||
|
||||
@@ -834,6 +834,10 @@ inline Monster *GetMutableMonster(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<Monster>(buf);
|
||||
}
|
||||
|
||||
inline MyGame::Sample::Monster *GetMutableSizePrefixedMonster(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyMonsterBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<MyGame::Sample::Monster>(nullptr);
|
||||
|
||||
@@ -505,6 +505,17 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " return flatbuffers::GetMutableRoot<{{STRUCT_NAME}}>(buf);";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
|
||||
code_ += "inline \\";
|
||||
code_ +=
|
||||
"{{CPP_NAME}} "
|
||||
"*{{NULLABLE_EXT}}GetMutableSizePrefixed{{STRUCT_NAME}}(void "
|
||||
"*buf) {";
|
||||
code_ +=
|
||||
" return "
|
||||
"flatbuffers::GetMutableSizePrefixedRoot<{{CPP_NAME}}>(buf);";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
}
|
||||
|
||||
if (parser_.file_identifier_.length()) {
|
||||
|
||||
@@ -457,6 +457,10 @@ inline ArrayTable *GetMutableArrayTable(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<ArrayTable>(buf);
|
||||
}
|
||||
|
||||
inline MyGame::Example::ArrayTable *GetMutableSizePrefixedArrayTable(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<MyGame::Example::ArrayTable>(buf);
|
||||
}
|
||||
|
||||
inline const char *ArrayTableIdentifier() {
|
||||
return "ARRT";
|
||||
}
|
||||
|
||||
@@ -3677,6 +3677,10 @@ inline Monster *GetMutableMonster(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<Monster>(buf);
|
||||
}
|
||||
|
||||
inline MyGame::Example::Monster *GetMutableSizePrefixedMonster(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<MyGame::Example::Monster>(buf);
|
||||
}
|
||||
|
||||
inline const char *MonsterIdentifier() {
|
||||
return "MONS";
|
||||
}
|
||||
|
||||
@@ -933,6 +933,10 @@ inline ScalarStuff *GetMutableScalarStuff(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<ScalarStuff>(buf);
|
||||
}
|
||||
|
||||
inline optional_scalars::ScalarStuff *GetMutableSizePrefixedScalarStuff(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<optional_scalars::ScalarStuff>(buf);
|
||||
}
|
||||
|
||||
inline const char *ScalarStuffIdentifier() {
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
@@ -798,6 +798,10 @@ inline Movie *GetMutableMovie(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<Movie>(buf);
|
||||
}
|
||||
|
||||
inline Movie *GetMutableSizePrefixedMovie(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<Movie>(buf);
|
||||
}
|
||||
|
||||
inline const char *MovieIdentifier() {
|
||||
return "MOVI";
|
||||
}
|
||||
|
||||
@@ -349,6 +349,10 @@ inline MonsterExtra *GetMutableMonsterExtra(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<MonsterExtra>(buf);
|
||||
}
|
||||
|
||||
inline MyGame::MonsterExtra *GetMutableSizePrefixedMonsterExtra(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<MyGame::MonsterExtra>(buf);
|
||||
}
|
||||
|
||||
inline const char *MonsterExtraIdentifier() {
|
||||
return "MONE";
|
||||
}
|
||||
|
||||
@@ -3648,6 +3648,10 @@ inline Monster *GetMutableMonster(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<Monster>(buf);
|
||||
}
|
||||
|
||||
inline MyGame::Example::Monster *GetMutableSizePrefixedMonster(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<MyGame::Example::Monster>(buf);
|
||||
}
|
||||
|
||||
inline const char *MonsterIdentifier() {
|
||||
return "MONS";
|
||||
}
|
||||
|
||||
@@ -288,6 +288,10 @@ inline ApplicationData *GetMutableApplicationData(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<ApplicationData>(buf);
|
||||
}
|
||||
|
||||
inline Geometry::ApplicationData *GetMutableSizePrefixedApplicationData(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<Geometry::ApplicationData>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyApplicationDataBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Geometry::ApplicationData>(nullptr);
|
||||
|
||||
@@ -893,6 +893,10 @@ inline ScalarStuff *GetMutableScalarStuff(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<ScalarStuff>(buf);
|
||||
}
|
||||
|
||||
inline optional_scalars::ScalarStuff *GetMutableSizePrefixedScalarStuff(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<optional_scalars::ScalarStuff>(buf);
|
||||
}
|
||||
|
||||
inline const char *ScalarStuffIdentifier() {
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
@@ -829,6 +829,10 @@ inline Movie *GetMutableMovie(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<Movie>(buf);
|
||||
}
|
||||
|
||||
inline Movie *GetMutableSizePrefixedMovie(void *buf) {
|
||||
return flatbuffers::GetMutableSizePrefixedRoot<Movie>(buf);
|
||||
}
|
||||
|
||||
inline const char *MovieIdentifier() {
|
||||
return "MOVI";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user