Skip to content

Commit 1db9391

Browse files
authored
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.
1 parent 1f2e7ad commit 1db9391

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

modules/dnn/src/caffe/caffe_importer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ class CaffeImporter
126126
const google::protobuf::UnknownField& field = unknownFields.field(i);
127127
CV_Assert(field.type() == google::protobuf::UnknownField::TYPE_GROUP);
128128
CV_CheckGE(field.group().field_count(), 2, "UnknownField should have at least 2 items: name and value");
129-
std::string fieldName = field.group().field(0).length_delimited();
130-
std::string fieldValue = field.group().field(1).length_delimited();
129+
std::string fieldName(field.group().field(0).length_delimited());
130+
std::string fieldValue(field.group().field(1).length_delimited());
131131
params.set(fieldName, fieldValue);
132132
}
133133
}
@@ -137,7 +137,7 @@ class CaffeImporter
137137
const Reflection *refl = msg.GetReflection();
138138
int type = field->cpp_type();
139139
bool isRepeated = field->is_repeated();
140-
const std::string &name = field->name();
140+
const std::string name(field->name());
141141

142142
#define SET_UP_FILED(getter, arrayConstr, gtype) \
143143
if (isRepeated) { \
@@ -189,7 +189,7 @@ class CaffeImporter
189189
params.set(name, DictValue::arrayString(buf.begin(), size));
190190
}
191191
else {
192-
params.set(name, refl->GetEnum(msg, field)->name());
192+
params.set(name, std::string(refl->GetEnum(msg, field)->name()));
193193
}
194194
break;
195195
default:
@@ -212,7 +212,7 @@ class CaffeImporter
212212
{
213213
const FieldDescriptor *fd = msgDesc->field(fieldId);
214214

215-
if (!isInternal && !ends_with_param(fd->name()))
215+
if (!isInternal && !ends_with_param(std::string(fd->name())))
216216
continue;
217217

218218
const google::protobuf::UnknownFieldSet& unknownFields = msgRefl->GetUnknownFields(msg);

0 commit comments

Comments
 (0)