Updated Branches: refs/heads/master f6acf4411 -> cf8b62643
THRIFT-2304 cpp:Move client assignments from construtor in method Patch: Martin Vogt Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/cf8b6264 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/cf8b6264 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/cf8b6264 Branch: refs/heads/master Commit: cf8b6264348c5df232f7a81e6a5463b3763943ab Parents: f6acf44 Author: Roger Meier <[email protected]> Authored: Sat Jan 4 23:31:21 2014 +0100 Committer: Roger Meier <[email protected]> Committed: Sat Jan 4 23:31:21 2014 +0100 ---------------------------------------------------------------------- compiler/cpp/src/generate/t_cpp_generator.cc | 46 +++++++++++++++++------ 1 file changed, 34 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/cf8b6264/compiler/cpp/src/generate/t_cpp_generator.cc ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 333fe60..7f23f9b 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -2254,16 +2254,15 @@ void t_cpp_generator::generate_service_client(t_service* tservice, string style) if (style != "Cob") { f_header_ << indent() << service_name_ << style << "Client" << short_suffix << - "(" << prot_ptr << " prot) :" << - endl; + "(" << prot_ptr << " prot) "; + if (extends.empty()) { + f_header_ << "{" << endl; f_header_ << - indent() << " piprot_(prot)," << endl << - indent() << " poprot_(prot) {" << endl << - indent() << " iprot_ = prot.get();" << endl << - indent() << " oprot_ = prot.get();" << endl << + indent() << " setProtocol(prot);" << endl << indent() << "}" << endl; } else { + f_header_ << ":" << endl; f_header_ << indent() << " " << extends << style << client_suffix << "(prot, prot) {}" << endl; @@ -2271,20 +2270,43 @@ void t_cpp_generator::generate_service_client(t_service* tservice, string style) f_header_ << indent() << service_name_ << style << "Client" << short_suffix << - "(" << prot_ptr << " iprot, " << prot_ptr << " oprot) :" << endl; + "(" << prot_ptr << " iprot, " << prot_ptr << " oprot) "; if (extends.empty()) { + f_header_ << "{" << endl; f_header_ << - indent() << " piprot_(iprot)," << endl << - indent() << " poprot_(oprot) {" << endl << - indent() << " iprot_ = iprot.get();" << endl << - indent() << " oprot_ = oprot.get();" << endl << + indent() << " setProtocol(iprot,oprot);" << endl << indent() << "}" << endl; } else { - f_header_ << + f_header_ << ":" << indent() << " " << extends << style << client_suffix << "(iprot, oprot) {}" << endl; } + // create the setProtocol methods + if (extends.empty()) { + f_header_ << " private:"<<endl; + // 1: one parameter + f_header_ << + indent() << "void setProtocol" << short_suffix << "(" + << prot_ptr << " prot) {" <<endl; + f_header_ << indent() << "setProtocol(prot,prot);"<<endl; + f_header_ << indent() << "}"<<endl; + // 2: two parameter + f_header_ << + indent() << "void setProtocol" << short_suffix << + "(" << prot_ptr << " iprot, " << prot_ptr << " oprot) {"<<endl; + + f_header_ << + indent() << " piprot_=iprot;"<<endl << + indent() << " poprot_=oprot;"<<endl << + indent() << " iprot_ = iprot.get();"<<endl << + indent() << " oprot_ = oprot.get();"<<endl; + + f_header_ << indent() << "}"<<endl; + f_header_ << " public:"<<endl; + } + + // Generate getters for the protocols. // Note that these are not currently templated for simplicity. // TODO(simpkins): should they be templated?
