From 1db93911aeb65599f22db47d5d39f75bc94a821d Mon Sep 17 00:00:00 2001 From: Yannis Guyon Date: Mon, 9 Dec 2024 10:24:01 +0100 Subject: [PATCH] Support string_view in caffe_importer An upcoming change in Protobuf will change the return types of various methods like Descriptor::name() and Message::GetTypeName() from const std::string& or std::string to absl::string_view. This CL fixes users of those methods to work both before and after the change. --- modules/dnn/src/caffe/caffe_importer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/dnn/src/caffe/caffe_importer.cpp b/modules/dnn/src/caffe/caffe_importer.cpp index 50e1fbe93fa2..fc6cbcdd28ef 100644 --- a/modules/dnn/src/caffe/caffe_importer.cpp +++ b/modules/dnn/src/caffe/caffe_importer.cpp @@ -126,8 +126,8 @@ class CaffeImporter const google::protobuf::UnknownField& field = unknownFields.field(i); CV_Assert(field.type() == google::protobuf::UnknownField::TYPE_GROUP); CV_CheckGE(field.group().field_count(), 2, "UnknownField should have at least 2 items: name and value"); - std::string fieldName = field.group().field(0).length_delimited(); - std::string fieldValue = field.group().field(1).length_delimited(); + std::string fieldName(field.group().field(0).length_delimited()); + std::string fieldValue(field.group().field(1).length_delimited()); params.set(fieldName, fieldValue); } } @@ -137,7 +137,7 @@ class CaffeImporter const Reflection *refl = msg.GetReflection(); int type = field->cpp_type(); bool isRepeated = field->is_repeated(); - const std::string &name = field->name(); + const std::string name(field->name()); #define SET_UP_FILED(getter, arrayConstr, gtype) \ if (isRepeated) { \ @@ -189,7 +189,7 @@ class CaffeImporter params.set(name, DictValue::arrayString(buf.begin(), size)); } else { - params.set(name, refl->GetEnum(msg, field)->name()); + params.set(name, std::string(refl->GetEnum(msg, field)->name())); } break; default: @@ -212,7 +212,7 @@ class CaffeImporter { const FieldDescriptor *fd = msgDesc->field(fieldId); - if (!isInternal && !ends_with_param(fd->name())) + if (!isInternal && !ends_with_param(std::string(fd->name()))) continue; const google::protobuf::UnknownFieldSet& unknownFields = msgRefl->GetUnknownFields(msg);