From: Mark Slee Date: Fri, 8 Dec 2006 19:15:35 +0000 (+0000) Subject: Generate a null implementation of thrift C++ class for easy subclassing X-Git-Tag: 0.2.0~1584 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=962a8585663db144150c98e4a6adc275a2a473a7;p=common%2Fthrift.git Generate a null implementation of thrift C++ class for easy subclassing Summary: Sometimes you just want a subclass that only implements one method... annoying to fill in nulls for the others, so use the generated null class Reviewed By: tbr-aditya git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664888 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 9188955f..645e0850 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -684,6 +684,7 @@ void t_cpp_generator::generate_service(t_service* tservice) { // Generate all the components generate_service_interface(tservice); + generate_service_null(tservice); generate_service_helpers(tservice); generate_service_client(tservice); generate_service_processor(tservice); @@ -750,6 +751,48 @@ void t_cpp_generator::generate_service_interface(t_service* tservice) { "}; " << endl << endl; } +/** + * Generates a null implementation of the service. + * + * @param tservice The service to generate a header definition for + */ +void t_cpp_generator::generate_service_null(t_service* tservice) { + string extends = ""; + if (tservice->get_extends() != NULL) { + extends = " : virtual public " + type_name(tservice->get_extends()) + "Null"; + } + f_header_ << + "class " << service_name_ << "Null : virtual public " << service_name_ << "If" << extends << " {" << endl << + " public: " << endl; + indent_up(); + f_header_ << + indent() << "virtual ~" << service_name_ << "If() {}" << endl; + vector functions = tservice->get_functions(); + vector::iterator f_iter; + for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { + f_header_ << + indent() << function_signature(*f_iter) << " {" << endl; + indent_up(); + t_type* returntype = (*f_iter)->get_returntype(); + if (returntype->is_void()) { + f_header_ << + indent() << "return;" << endl; + } else { + t_field returnfield(returntype, "rval"); + f_header_ << + indent() << declare_field(&returnfield, true) << endl << + indent() << "return rval;" << endl; + } + indent_down(); + f_header_ << + indent() << "}" << endl; + } + indent_down(); + f_header_ << + "}; " << endl << endl; +} + + /** * Generates a multiface, which is a single server that just takes a set * of objects implementing the interface and calls them all, returning the diff --git a/compiler/cpp/src/generate/t_cpp_generator.h b/compiler/cpp/src/generate/t_cpp_generator.h index 435b0c6e..fdab3eea 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.h +++ b/compiler/cpp/src/generate/t_cpp_generator.h @@ -52,6 +52,7 @@ class t_cpp_generator : public t_oop_generator { */ void generate_service_interface (t_service* tservice); + void generate_service_null (t_service* tservice); void generate_service_multiface (t_service* tservice); void generate_service_helpers (t_service* tservice); void generate_service_client (t_service* tservice);