THRIFT-1168 C++ cob client/server: void functions that throw exceptions

Patch: NewBlood

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1221891 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roger Meier 2011-12-21 21:23:28 +00:00
parent 1e79cb40f5
commit 94eecc8259

View File

@ -1366,11 +1366,29 @@ void t_cpp_generator::generate_struct_writer(ofstream& out,
indent(out) <<
"xfer += oprot->writeStructBegin(\"" << name << "\");" << endl;
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if ((*f_iter)->get_req() == t_field::T_OPTIONAL) {
indent(out) << "if (this->__isset." << (*f_iter)->get_name() << ") {" << endl;
bool check_if_set = (*f_iter)->get_req() == t_field::T_OPTIONAL ||
(*f_iter)->get_type()->is_xception();
if (check_if_set) {
if (first) {
first = false;
out <<
endl <<
indent() << "if ";
} else {
out <<
" else if ";
}
out << "(this->__isset." << (*f_iter)->get_name() << ") {" << endl;
indent_up();
} else {
if (!first)
out << endl;
first = true;
}
// Write field header
out <<
indent() << "xfer += oprot->writeFieldBegin(" <<
@ -1386,12 +1404,16 @@ void t_cpp_generator::generate_struct_writer(ofstream& out,
// Write field closer
indent(out) <<
"xfer += oprot->writeFieldEnd();" << endl;
if ((*f_iter)->get_req() == t_field::T_OPTIONAL) {
if (check_if_set) {
indent_down();
indent(out) << '}' << endl;
indent(out) << '}';
}
}
if (!first) {
out << endl;
}
// Write the struct map
out <<
indent() << "xfer += oprot->writeFieldStop();" << endl <<