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
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index 5071041..27d6633 100755
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -1366,11 +1366,29 @@
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 @@
// 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 <<