[C++] Fixed/Enabled --cpp-ptr-type std::shared_ptr [#5813] (#5959)

This commit is contained in:
volkan-ozdemir 2020-06-11 19:38:40 -04:00 committed by GitHub
parent a28357d7ac
commit 8e505cb677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -2714,24 +2714,28 @@ class CppGenerator : public BaseGenerator {
code_.SetValue("STRUCT_NAME", Name(struct_def));
code_.SetValue("NATIVE_NAME",
NativeName(Name(struct_def), &struct_def, opts_));
auto native_name =
NativeName(WrapInNameSpace(struct_def), &struct_def, parser_.opts);
code_.SetValue("POINTER_TYPE",
GenTypeNativePtr(native_name, nullptr, false));
if (opts_.generate_object_based_api) {
// Generate the X::UnPack() method.
code_ +=
"inline " + TableUnPackSignature(struct_def, false, opts_) + " {";
code_ +=
" {{POINTER_TYPE}} _o = {{POINTER_TYPE}}(new {{NATIVE_NAME}}());";
if(opts_.g_cpp_std == cpp::CPP_STD_X0) {
auto native_name =
NativeName(WrapInNameSpace(struct_def), &struct_def, parser_.opts);
code_.SetValue("POINTER_TYPE",
GenTypeNativePtr(native_name, nullptr, false));
code_ +=
" {{POINTER_TYPE}} _o = {{POINTER_TYPE}}(new {{NATIVE_NAME}}());";
} else if(opts_.g_cpp_std == cpp::CPP_STD_11) {
code_ += " auto _o = std::unique_ptr<{{NATIVE_NAME}}>(new {{NATIVE_NAME}}());";
} else {
code_ += " auto _o = std::make_unique<{{NATIVE_NAME}}>();";
}
code_ += " UnPackTo(_o.get(), _resolver);";
code_ += " return _o.release();";
code_ += "}";
code_ += "";
code_ +=
"inline " + TableUnPackToSignature(struct_def, false, opts_) + " {";
code_ += " (void)_o;";

View File

@ -2197,7 +2197,7 @@ flatbuffers::Offset<TypeAliases> CreateTypeAliases(flatbuffers::FlatBufferBuilde
} // namespace Example
inline InParentNamespaceT *InParentNamespace::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
std::unique_ptr<MyGame::InParentNamespaceT> _o = std::unique_ptr<MyGame::InParentNamespaceT>(new InParentNamespaceT());
auto _o = std::make_unique<InParentNamespaceT>();
UnPackTo(_o.get(), _resolver);
return _o.release();
}
@ -2222,7 +2222,7 @@ inline flatbuffers::Offset<InParentNamespace> CreateInParentNamespace(flatbuffer
namespace Example2 {
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
std::unique_ptr<MyGame::Example2::MonsterT> _o = std::unique_ptr<MyGame::Example2::MonsterT>(new MonsterT());
auto _o = std::make_unique<MonsterT>();
UnPackTo(_o.get(), _resolver);
return _o.release();
}
@ -2249,7 +2249,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
namespace Example {
inline TestSimpleTableWithEnumT *TestSimpleTableWithEnum::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
std::unique_ptr<MyGame::Example::TestSimpleTableWithEnumT> _o = std::unique_ptr<MyGame::Example::TestSimpleTableWithEnumT>(new TestSimpleTableWithEnumT());
auto _o = std::make_unique<TestSimpleTableWithEnumT>();
UnPackTo(_o.get(), _resolver);
return _o.release();
}
@ -2275,7 +2275,7 @@ inline flatbuffers::Offset<TestSimpleTableWithEnum> CreateTestSimpleTableWithEnu
}
inline StatT *Stat::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
std::unique_ptr<MyGame::Example::StatT> _o = std::unique_ptr<MyGame::Example::StatT>(new StatT());
auto _o = std::make_unique<StatT>();
UnPackTo(_o.get(), _resolver);
return _o.release();
}
@ -2307,7 +2307,7 @@ inline flatbuffers::Offset<Stat> CreateStat(flatbuffers::FlatBufferBuilder &_fbb
}
inline ReferrableT *Referrable::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
std::unique_ptr<MyGame::Example::ReferrableT> _o = std::unique_ptr<MyGame::Example::ReferrableT>(new ReferrableT());
auto _o = std::make_unique<ReferrableT>();
UnPackTo(_o.get(), _resolver);
return _o.release();
}
@ -2333,7 +2333,7 @@ inline flatbuffers::Offset<Referrable> CreateReferrable(flatbuffers::FlatBufferB
}
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
std::unique_ptr<MyGame::Example::MonsterT> _o = std::unique_ptr<MyGame::Example::MonsterT>(new MonsterT());
auto _o = std::make_unique<MonsterT>();
UnPackTo(_o.get(), _resolver);
return _o.release();
}
@ -2507,7 +2507,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
}
inline TypeAliasesT *TypeAliases::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
std::unique_ptr<MyGame::Example::TypeAliasesT> _o = std::unique_ptr<MyGame::Example::TypeAliasesT>(new TypeAliasesT());
auto _o = std::make_unique<TypeAliasesT>();
UnPackTo(_o.get(), _resolver);
return _o.release();
}