// Include the types file
f_types_impl_ <<
- "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
+ "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
"_types.h\"" << endl <<
endl;
"#ifndef " << program_name_ << "_CONSTANTS_H" << endl <<
"#define " << program_name_ << "_CONSTANTS_H" << endl <<
endl <<
- "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
+ "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
"_types.h\"" << endl <<
endl <<
ns_open_ << endl <<
endl;
f_consts_impl <<
- "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
+ "#include \"" << get_include_prefix(*get_program()) << program_name_ <<
"_constants.h\"" << endl <<
endl <<
ns_open_ << endl <<
t_field fval(tmap->get_val_type(), val);
out <<
- indent() << declare_field(&fkey) << endl <<
- indent() << declare_field(&fval) << endl;
+ indent() << declare_field(&fkey) << endl;
generate_deserialize_field(out, &fkey);
- generate_deserialize_field(out, &fval);
-
indent(out) <<
- prefix << ".insert(std::make_pair(" << key << ", " << val << "));" << endl;
+ declare_field(&fval, false, false, false, true) << " = " <<
+ prefix << "[" << key << "];" << endl;
+
+ generate_deserialize_field(out, &fval);
}
void t_cpp_generator::generate_deserialize_set_element(ofstream& out,
* @param ttype The type
* @return Field declaration, i.e. int x = 0;
*/
-string t_cpp_generator::declare_field(t_field* tfield, bool init, bool pointer, bool constant) {
+string t_cpp_generator::declare_field(t_field* tfield, bool init, bool pointer, bool constant, bool reference) {
// TODO(mcslee): do we ever need to initialize the field?
string result = "";
if (constant) {
if (pointer) {
result += "*";
}
+ if (reference) {
+ result += "&";
+ }
result += " " + tfield->get_name();
if (init) {
t_type* type = get_true_type(tfield->get_type());
result += " = (" + type_name(type) + ")0";
}
}
- return result + ";";
+ if (!reference) {
+ result += ";";
+ }
+ return result;
}
/**
if ((last_slash = include_prefix.rfind("/")) != string::npos) {
return include_prefix.substr(0, last_slash) + "/" + out_dir_base_ + "/";
}
-
+
return "";
}
*/
void generate_deserialize_field (std::ofstream& out,
- t_field* tfield,
+ t_field* tfield,
std::string prefix="",
std::string suffix="");
-
+
void generate_deserialize_struct (std::ofstream& out,
t_struct* tstruct,
std::string prefix="");
-
+
void generate_deserialize_container (std::ofstream& out,
t_type* ttype,
std::string prefix="");
-
+
void generate_deserialize_set_element (std::ofstream& out,
t_set* tset,
std::string prefix="");
std::string namespace_close(std::string ns);
std::string type_name(t_type* ttype, bool in_typedef=false, bool arg=false);
std::string base_type_name(t_base_type::t_base tbase);
- std::string declare_field(t_field* tfield, bool init=false, bool pointer=false, bool constant=false);
+ std::string declare_field(t_field* tfield, bool init=false, bool pointer=false, bool constant=false, bool reference=false);
std::string function_signature(t_function* tfunction, std::string prefix="");
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
ttype = get_true_type(ttype);
return
- ttype->is_container() ||
+ ttype->is_container() ||
ttype->is_struct() ||
ttype->is_xception() ||
(ttype->is_base_type() && (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING));