mirror of
https://github.com/opencv/opencv.git
synced 2025-07-28 16:25:01 +08:00
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.
This commit is contained in:
parent
1f2e7adb4b
commit
1db93911ae
@ -126,8 +126,8 @@ public:
|
|||||||
const google::protobuf::UnknownField& field = unknownFields.field(i);
|
const google::protobuf::UnknownField& field = unknownFields.field(i);
|
||||||
CV_Assert(field.type() == google::protobuf::UnknownField::TYPE_GROUP);
|
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");
|
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 fieldName(field.group().field(0).length_delimited());
|
||||||
std::string fieldValue = field.group().field(1).length_delimited();
|
std::string fieldValue(field.group().field(1).length_delimited());
|
||||||
params.set(fieldName, fieldValue);
|
params.set(fieldName, fieldValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ public:
|
|||||||
const Reflection *refl = msg.GetReflection();
|
const Reflection *refl = msg.GetReflection();
|
||||||
int type = field->cpp_type();
|
int type = field->cpp_type();
|
||||||
bool isRepeated = field->is_repeated();
|
bool isRepeated = field->is_repeated();
|
||||||
const std::string &name = field->name();
|
const std::string name(field->name());
|
||||||
|
|
||||||
#define SET_UP_FILED(getter, arrayConstr, gtype) \
|
#define SET_UP_FILED(getter, arrayConstr, gtype) \
|
||||||
if (isRepeated) { \
|
if (isRepeated) { \
|
||||||
@ -189,7 +189,7 @@ public:
|
|||||||
params.set(name, DictValue::arrayString(buf.begin(), size));
|
params.set(name, DictValue::arrayString(buf.begin(), size));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
params.set(name, refl->GetEnum(msg, field)->name());
|
params.set(name, std::string(refl->GetEnum(msg, field)->name()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -212,7 +212,7 @@ public:
|
|||||||
{
|
{
|
||||||
const FieldDescriptor *fd = msgDesc->field(fieldId);
|
const FieldDescriptor *fd = msgDesc->field(fieldId);
|
||||||
|
|
||||||
if (!isInternal && !ends_with_param(fd->name()))
|
if (!isInternal && !ends_with_param(std::string(fd->name())))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const google::protobuf::UnknownFieldSet& unknownFields = msgRefl->GetUnknownFields(msg);
|
const google::protobuf::UnknownFieldSet& unknownFields = msgRefl->GetUnknownFields(msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user