mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 13:37:25 +00:00
[C++] Enable using struct and array of struct as key (#7741)
* add unit tests for support struct as key * make changes to parser and add helper function to generate comparator for struct * implement * add more unit tests * format * just a test * test done * rerun generator * restore build file * address comment * format * rebase * rebase * add more unit tests * rerun generator * address some comments * address comment * update * format * address comment Co-authored-by: Wen Sun <sunwen@google.com> Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -918,7 +918,7 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
||||
ECHECK(ParseType(type));
|
||||
|
||||
if (struct_def.fixed) {
|
||||
if (IsIncompleteStruct(type) ||
|
||||
if (IsIncompleteStruct(type) ||
|
||||
(IsArray(type) && IsIncompleteStruct(type.VectorType()))) {
|
||||
std::string type_name = IsArray(type) ? type.VectorType().struct_def->name : type.struct_def->name;
|
||||
return Error(std::string("Incomplete type in struct is not allowed, type name: ") + type_name);
|
||||
@@ -1072,8 +1072,11 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
||||
if (field->key) {
|
||||
if (struct_def.has_key) return Error("only one field may be set as 'key'");
|
||||
struct_def.has_key = true;
|
||||
auto is_valid = IsScalar(type.base_type) || IsString(type);
|
||||
if (IsArray(type)) { is_valid |= IsScalar(type.VectorType().base_type); }
|
||||
auto is_valid = IsScalar(type.base_type) || IsString(type) || IsStruct(type);
|
||||
if (IsArray(type)) {
|
||||
is_valid |=
|
||||
IsScalar(type.VectorType().base_type) || IsStruct(type.VectorType());
|
||||
}
|
||||
if (!is_valid) {
|
||||
return Error(
|
||||
"'key' field must be string, scalar type or fixed size array of "
|
||||
|
||||
Reference in New Issue
Block a user