You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2012/02/22 22:14:10 UTC

svn commit: r1292508 - /thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc

Author: bryanduxbury
Date: Wed Feb 22 21:14:10 2012
New Revision: 1292508

URL: http://svn.apache.org/viewvc?rev=1292508&view=rev
Log:
THRIFT-1518. cpp: Generated C++ code only sends the first optional field in the write() function for a struct

There was some incorrect else if logic added to the CPP generated code, which this patch replaces with the proper functionality.

Patch: Thomas Wiggins

Modified:
    thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc

Modified: thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc
URL: http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc?rev=1292508&r1=1292507&r2=1292508&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc Wed Feb 22 21:14:10 2012
@@ -1368,26 +1368,14 @@ void t_cpp_generator::generate_struct_wr
   indent(out) <<
     "xfer += oprot->writeStructBegin(\"" << name << "\");" << endl;
 
-  bool first = true;
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
     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;
+      out << endl << indent() << "if (this->__isset." << (*f_iter)->get_name() << ") {" << endl;
       indent_up();
     } else {
-      if (!first)
-        out << endl;
-      first = true;
+      out << endl;
     }
 
     // Write field header
@@ -1411,9 +1399,7 @@ void t_cpp_generator::generate_struct_wr
     }
   }
 
-  if (!first) {
-    out << endl;
-  }
+  out << endl;
 
   // Write the struct map
   out <<