Commit c2411e9c authored by daksenik's avatar daksenik

Fixed operator++. Added CreateXXX for vector types.

parent bf26a0ec
......@@ -679,6 +679,9 @@ class CppGenerator : public BaseGenerator {
// Generate a convenient CreateX function that uses the above builder
// to create a table in one go.
std::vector<FieldDef*>vect_pars;
code += "inline flatbuffers::Offset<" + struct_def.name + "> Create";
code += struct_def.name;
code += "(flatbuffers::FlatBufferBuilder &_fbb";
......@@ -686,6 +689,7 @@ class CppGenerator : public BaseGenerator {
it != struct_def.fields.vec.end(); ++it) {
auto &field = **it;
if (!field.deprecated) {
if (field.value.type.base_type == BASE_TYPE_STRING || field.value.type.base_type == BASE_TYPE_VECTOR) vect_pars.push_back(*it);
code += ",\n " + GenTypeWire(field.value.type, " ", true);
code += field.name + " = ";
if (field.value.type.enum_def && IsScalar(field.value.type.base_type)) {
......@@ -721,7 +725,7 @@ class CppGenerator : public BaseGenerator {
code += " return builder_.Finish();\n}\n\n";
//Generate a CreateX function with vector types as parameters
std::vector<FieldDef*>vect_pars_ids;
if (vect_pars.size()) {
code += "inline flatbuffers::Offset<" + struct_def.name + "> Create";
code += struct_def.name;
code += "(flatbuffers::FlatBufferBuilder &_fbb";
......@@ -730,12 +734,10 @@ class CppGenerator : public BaseGenerator {
auto &field = **it;
if (!field.deprecated) {
if (field.value.type.base_type == BASE_TYPE_STRING) {
vect_pars_ids.push_back(*it);
code += ",\n const char *";
code += field.name + " = \"\"";
}
else if (field.value.type.base_type == BASE_TYPE_VECTOR) {
vect_pars_ids.push_back(*it);
code += ",\n std::vector<" + GenTypeWire(field.value.type.VectorType(), "", false) + "> " + field.name;
code += " = std::vector<" + GenTypeWire(field.value.type.VectorType(), "", false) + ">()";
}
......@@ -767,8 +769,8 @@ class CppGenerator : public BaseGenerator {
code += ") {\n ";
//getting offsets
for (auto it = vect_pars_ids.begin();
it != vect_pars_ids.end(); ++it) {
for (auto it = vect_pars.begin();
it != vect_pars.end(); ++it) {
auto&field = **it;
code += "auto " + field.name + "_off = ";
if (field.value.type.base_type == BASE_TYPE_STRING) {
......@@ -779,7 +781,6 @@ class CppGenerator : public BaseGenerator {
}
}
//...
code += struct_def.name + "Builder builder_(_fbb);\n";
for (size_t size = struct_def.sortbysize ? sizeof(largest_scalar_t) : 1;
size; size /= 2) {
......@@ -789,7 +790,7 @@ class CppGenerator : public BaseGenerator {
if (!field.deprecated && (!struct_def.sortbysize ||
size == SizeOf(field.value.type.base_type))) {
code += " builder_.add_" + field.name + "(";
code += (!IsScalar(field.value.type.base_type) && (!IsStruct(field.value.type))) ? //if vector or string
code += (field.value.type.base_type == BASE_TYPE_STRING || field.value.type.base_type == BASE_TYPE_VECTOR) ? //if vector or string
(field.name + "_off") : field.name;
code += ");\n";
}
......@@ -797,6 +798,7 @@ class CppGenerator : public BaseGenerator {
}
code += " return builder_.Finish();\n}\n\n";
}
}
static void GenPadding(const FieldDef &field, std::string &code,
int &padding_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment