*/
void t_cpp_generator::generate_typedef(t_typedef* ttypedef) {
f_types_ <<
- indent() << "typedef " << type_name(ttypedef->get_type()) << " " << ttypedef->get_symbolic() << ";" << endl <<
+ indent() << "typedef " << type_name(ttypedef->get_type(), true) << " " << ttypedef->get_symbolic() << ";" << endl <<
endl;
}
string name = prefix + tfield->get_name();
if (type->is_struct() || type->is_xception()) {
- generate_deserialize_struct(out, (t_struct*)(tfield->get_type()), name);
+ generate_deserialize_struct(out, (t_struct*)type, name);
} else if (type->is_container()) {
- generate_deserialize_container(out, tfield->get_type(), name);
+ generate_deserialize_container(out, type, name);
} else if (type->is_base_type() || type->is_enum()) {
indent(out) <<
"xfer += iprot->";
if (type->is_struct() || type->is_xception()) {
generate_serialize_struct(out,
- (t_struct*)(tfield->get_type()),
+ (t_struct*)type,
prefix + tfield->get_name());
} else if (type->is_container()) {
generate_serialize_container(out,
- tfield->get_type(),
+ type,
prefix + tfield->get_name());
} else if (type->is_base_type() || type->is_enum()) {
* @param ttype The type
* @return String of the type name, i.e. std::set<type>
*/
-string t_cpp_generator::type_name(t_type* ttype) {
+string t_cpp_generator::type_name(t_type* ttype, bool in_typedef) {
if (ttype->is_base_type()) {
return base_type_name(((t_base_type*)ttype)->get_base());
}
if (ttype->is_map()) {
t_map* tmap = (t_map*) ttype;
return "std::map<" +
- type_name(tmap->get_key_type()) + ", " +
- type_name(tmap->get_val_type()) + "> ";
+ type_name(tmap->get_key_type(), in_typedef) + ", " +
+ type_name(tmap->get_val_type(), in_typedef) + "> ";
}
if (ttype->is_set()) {
t_set* tset = (t_set*) ttype;
- return "std::set<" + type_name(tset->get_elem_type()) + "> ";
+ return "std::set<" + type_name(tset->get_elem_type(), in_typedef) + "> ";
}
if (ttype->is_list()) {
t_list* tlist = (t_list*) ttype;
- return "std::vector<" + type_name(tlist->get_elem_type()) + "> ";
+ return "std::vector<" + type_name(tlist->get_elem_type(), in_typedef) + "> ";
+ }
+
+ string class_prefix;
+ if (in_typedef && (ttype->is_struct() || ttype->is_xception())) {
+ class_prefix = "class ";
}
// Check if it needs to be namespaced
t_program* program = ttype->get_program();
if (program != NULL && program != program_) {
return
+ class_prefix +
namespace_prefix(program->get_cpp_namespace()) +
ttype->get_name();
}
- return ttype->get_name();
+ return class_prefix + ttype->get_name();
}
/**
std::string namespace_prefix(std::string ns);
std::string namespace_open(std::string ns);
std::string namespace_close(std::string ns);
- std::string type_name(t_type* ttype);
+ std::string type_name(t_type* ttype, bool in_typedef=false);
std::string base_type_name(t_base_type::t_base tbase);
std::string declare_field(t_field* tfield, bool init=false);
std::string function_signature(t_function* tfunction, std::string prefix="");
if (type->is_struct() || type->is_xception()) {
generate_deserialize_struct(out,
- (t_struct*)(tfield->get_type()),
+ (t_struct*)type,
name);
} else if (type->is_container()) {
- generate_deserialize_container(out, tfield->get_type(), name);
+ generate_deserialize_container(out, type, name);
} else if (type->is_base_type() || type->is_enum()) {
indent(out) <<
if (type->is_struct() || type->is_xception()) {
generate_serialize_struct(out,
- (t_struct*)(tfield->get_type()),
+ (t_struct*)type,
prefix + tfield->get_name());
} else if (type->is_container()) {
generate_serialize_container(out,
- tfield->get_type(),
+ type,
prefix + tfield->get_name());
} else if (type->is_base_type() || type->is_enum()) {
out << endl;
- out <<
- indent() << "public function __construct($vals=null) {" << endl;
- indent_up();
- out <<
- indent() << "if (is_array($vals)) {" << endl;
- indent_up();
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+ // Generate constructor from array
+ if (members.size() > 0) {
+ out <<
+ indent() << "public function __construct($vals=null) {" << endl;
+ indent_up();
+ out <<
+ indent() << "if (is_array($vals)) {" << endl;
+ indent_up();
+ for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+ out <<
+ indent() << "if (isset($vals['" << (*m_iter)->get_name() << "'])) {" << endl <<
+ indent() << " $this->" << (*m_iter)->get_name() << " = $vals['" << (*m_iter)->get_name() << "'];" << endl <<
+ indent() << "}" << endl;
+ }
+ indent_down();
out <<
- indent() << "if (isset($vals['" << (*m_iter)->get_name() << "'])) {" << endl <<
- indent() << " $this->" << (*m_iter)->get_name() << " = $vals['" << (*m_iter)->get_name() << "'];" << endl <<
indent() << "}" << endl;
+ indent_down();
+ out <<
+ indent() << "}" << endl <<
+ endl;
}
- indent_down();
- out <<
- indent() << "}" << endl;
-
- indent_down();
- out <<
- indent() << "}" << endl <<
- endl;
generate_php_struct_reader(out, tstruct);
generate_php_struct_writer(out, tstruct);
if (type->is_struct() || type->is_xception()) {
generate_deserialize_struct(out,
- (t_struct*)(tfield->get_type()),
+ (t_struct*)type,
name);
} else if (type->is_container()) {
- generate_deserialize_container(out, tfield->get_type(), name);
+ generate_deserialize_container(out, type, name);
} else if (type->is_base_type() || type->is_enum()) {
if (binary_inline_) {
if (type->is_struct() || type->is_xception()) {
generate_serialize_struct(out,
- (t_struct*)(tfield->get_type()),
+ (t_struct*)type,
prefix + tfield->get_name());
} else if (type->is_container()) {
generate_serialize_container(out,
- tfield->get_type(),
+ type,
prefix + tfield->get_name());
} else if (type->is_base_type() || type->is_enum()) {
if (type->is_struct() || type->is_xception()) {
generate_deserialize_struct(out,
- (t_struct*)(tfield->get_type()),
+ (t_struct*)type,
name);
} else if (type->is_container()) {
- generate_deserialize_container(out, tfield->get_type(), name);
+ generate_deserialize_container(out, type, name);
} else if (type->is_base_type() || type->is_enum()) {
indent(out) <<
name << " = iprot.";
if (type->is_struct() || type->is_xception()) {
generate_serialize_struct(out,
- (t_struct*)(tfield->get_type()),
+ (t_struct*)type,
prefix + tfield->get_name());
} else if (type->is_container()) {
generate_serialize_container(out,
- tfield->get_type(),
+ type,
prefix + tfield->get_name());
} else if (type->is_base_type() || type->is_enum()) {