mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Implement (shared) attribute for C++ (#5157)
* Implement native_shared attribute for C++.
Fixes #5141. See also #5145.
* Refine comment in idl.h
* Also refine docs
* Revert "Also refine docs"
This reverts commit 09dab7b45c.
* Also refine docs again.
* grumble
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
cf47f27164
commit
60e94cf083
@@ -2083,9 +2083,14 @@ class CppGenerator : public BaseGenerator {
|
||||
if (!field.deprecated) {
|
||||
code_.SetValue("FIELD_NAME", Name(field));
|
||||
if (field.value.type.base_type == BASE_TYPE_STRING) {
|
||||
if (!field.shared) {
|
||||
code_.SetValue("CREATE_STRING", "CreateString");
|
||||
} else {
|
||||
code_.SetValue("CREATE_STRING", "CreateSharedString");
|
||||
}
|
||||
code_ +=
|
||||
" auto {{FIELD_NAME}}__ = {{FIELD_NAME}} ? "
|
||||
"_fbb.CreateString({{FIELD_NAME}}) : 0;";
|
||||
"_fbb.{{CREATE_STRING}}({{FIELD_NAME}}) : 0;";
|
||||
} else if (field.value.type.base_type == BASE_TYPE_VECTOR) {
|
||||
code_ += " auto {{FIELD_NAME}}__ = {{FIELD_NAME}} ? \\";
|
||||
const auto vtype = field.value.type.VectorType();
|
||||
@@ -2294,8 +2299,16 @@ class CppGenerator : public BaseGenerator {
|
||||
switch (field.value.type.base_type) {
|
||||
// String fields are of the form:
|
||||
// _fbb.CreateString(_o->field)
|
||||
// or
|
||||
// _fbb.CreateSharedString(_o->field)
|
||||
case BASE_TYPE_STRING: {
|
||||
code += "_fbb.CreateString(" + value + ")";
|
||||
if (!field.shared) {
|
||||
code += "_fbb.CreateString(";
|
||||
} else {
|
||||
code += "_fbb.CreateSharedString(";
|
||||
}
|
||||
code += value;
|
||||
code.push_back(')');
|
||||
|
||||
// For optional fields, check to see if there actually is any data
|
||||
// in _o->field before attempting to access it. If there isn't,
|
||||
|
||||
Reference in New Issue
Block a user