[C++] Update to address comparator failure in big endian (#7681)

* update unit test and generated file to test is extra endianswap can help resolve issue

* remove EndianScalar wrapper from Get method

* remove endianscalar wrapper

* update

* update

* use Array instead

* clang format

* address error

* clang

* update

* manually generate

* Move Nim to completed language

* Add swift link

* address comments

* update unit test

* address comment

* address comment

* regenerate file

* use auto instead of size_t

* use uint32_t instead

* update

* format

* delete extra whitespace

Co-authored-by: Wen Sun <sunwen@google.com>
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Wen Sun
2022-12-06 14:02:16 -08:00
committed by GitHub
parent 11394575bc
commit b5ebd3fd78
3 changed files with 46 additions and 30 deletions

View File

@@ -2269,15 +2269,18 @@ class CppGenerator : public BaseGenerator {
code_.SetValue("INPUT_TYPE", input_type);
code_ +=
" int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}"
") const { ";
code_ += " for (auto i = 0; i < {{FIELD_NAME}}()->size(); i++) {";
code_ += " const auto {{FIELD_NAME}}_l = {{FIELD_NAME}}_[i];";
code_ += " const auto {{FIELD_NAME}}_r = _{{FIELD_NAME}}->Get(i);";
code_ += " if({{FIELD_NAME}}_l != {{FIELD_NAME}}_r) ";
") const {";
code_ +=
" return static_cast<int>({{FIELD_NAME}}_l > "
"{{FIELD_NAME}}_r)"
" - static_cast<int>({{FIELD_NAME}}_l < {{FIELD_NAME}}_r);";
" const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();";
code_ +=
" for (flatbuffers::uoffset_t i = 0; i < "
"curr_{{FIELD_NAME}}->size(); i++) {";
code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);";
code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);";
code_ += " if(lhs != rhs)";
code_ +=
" return static_cast<int>(lhs > rhs)"
" - static_cast<int>(lhs < rhs);";
code_ += " }";
code_ += " return 0;";
}