summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTGIshib <justzeddicus@gmail.com>2016-08-15 13:30:30 +0300
committerTGIshib <justzeddicus@gmail.com>2016-08-15 13:30:30 +0300
commitfa74ce6d162cc25fbf3af153b8067363049de7c3 (patch)
treefda3e9f612d72ae6e7b5afaaab04fe0a8e9dd06e
parent8fdced4e1141a98fb37e952058874423702347ca (diff)
downloadflatbuffers-fa74ce6d162cc25fbf3af153b8067363049de7c3.tar.gz
flatbuffers-fa74ce6d162cc25fbf3af153b8067363049de7c3.tar.bz2
flatbuffers-fa74ce6d162cc25fbf3af153b8067363049de7c3.zip
Update idl_gen_general.cpp
-rw-r--r--src/idl_gen_general.cpp38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp
index c1b66da4..55f14930 100644
--- a/src/idl_gen_general.cpp
+++ b/src/idl_gen_general.cpp
@@ -669,55 +669,43 @@ void GenStructBody(const StructDef &struct_def, std::string *code_ptr, const cha
}
}
-void IncChar(std::string &str) {
- static int index = -1, num = 1;
- if (index < 0) {
- for (size_t i = 0; i < str.length(); i++) {
- if (str[i] == '!') {
- index = i;
- break;
- }
- }
- }
- str[index] = (char)(num + '0');
- num++;
+std::string GenOffsetGetter(flatbuffers::FieldDef *key_field, const char &num) {
+ return "__offset(" +
+ NumToString(key_field->value.offset) + ", o" + num +
+ (lang_.language == IDLOptions::kCSharp ?
+ ".Value, builder.DataBuffer)" : ", _bb)");
}
std::string GenKeyGetter(flatbuffers::FieldDef *key_field) {
auto data_buffer = (lang_.language == IDLOptions::kCSharp) ?
"builder.DataBuffer" : "_bb";
- auto get_offset = "__offset(" +
- NumToString(key_field->value.offset) + ", o!" +
- (lang_.language == IDLOptions::kCSharp ? ".Value" : "") +
- ", " + data_buffer + ")";
-
std::string key_getter = "";
if (key_field->value.type.base_type == BASE_TYPE_STRING) {
if (lang_.language == IDLOptions::kJava)
key_getter += " return ";
key_getter += FunctionStart('C') + "ompareStrings(";
- IncChar(get_offset);
- key_getter += get_offset + ", ";
- IncChar(get_offset);
- key_getter += get_offset + ", " + data_buffer + ")";
+ key_getter += GenOffsetGetter(key_field, '1') + ", ";
+ key_getter += GenOffsetGetter(key_field, '2') + ", " + data_buffer + ")";
if (lang_.language == IDLOptions::kJava)
key_getter += ";";
}
else {
auto field_getter = data_buffer + GenGetter(key_field->value.type).substr(2) +
- "(" + get_offset + ")";
- IncChar(field_getter);
+ "(" + GenOffsetGetter(key_field, '1') + ")";
if (lang_.language == IDLOptions::kCSharp) {
key_getter += field_getter;
- IncChar(field_getter);
+ field_getter = data_buffer + GenGetter(key_field->value.type).substr(2) +
+ "(" + GenOffsetGetter(key_field, '2') + ")";
key_getter += ".CompareTo(" + field_getter + ")";
}
else {
key_getter += "\n " + GenTypeGet(key_field->value.type) + " off1 = ";
key_getter += field_getter + ";\n " + GenTypeGet(key_field->value.type);
key_getter += " off2 = ";
- IncChar(field_getter);
+ field_getter = data_buffer + GenGetter(key_field->value.type).substr(2) +
+ "(" + GenOffsetGetter(key_field, '2') + ")";
key_getter += field_getter + ";\n";
+ key_getter += " return off1 > off2 ? 1 : off1 < off2 ? -1 : 0;\n";
}
}
return key_getter;