From bb98ed44d7a7be7f467a5b5112b116d5d0ebd1a7 Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Thu, 20 Jun 2013 01:06:22 +0200 Subject: [PATCH] THRIFT-1458 cpp: use the C++ standard (c++0x or later c++11) to improve code quality and cross platform capability Signed-off-by: Nate Rosenblum --- compiler/cpp/src/generate/t_cpp_generator.cc | 42 ++++++++++---------- lib/cpp/src/thrift/cxxfunctional.h | 3 ++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 9eaf7ad2..99c1aced 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -363,6 +363,8 @@ void t_cpp_generator::init_generator() { "#include " << endl << "#include " << endl << endl; + // Include C++xx compatibility header + f_types_ << "#include " << endl; // Include other Thrift includes const vector& includes = program_->get_includes(); @@ -2436,12 +2438,12 @@ void t_cpp_generator::generate_service_client(t_service* tservice, string style) if (!(*f_iter)->is_oneway()) { out << indent() << _this << "channel_->sendAndRecvMessage(" << - "std::tr1::bind(cob, this), " << _this << "otrans_.get(), " << + "tcxx::bind(cob, this), " << _this << "otrans_.get(), " << _this << "itrans_.get());" << endl; } else { out << indent() << _this << "channel_->sendMessage(" << - "std::tr1::bind(cob, this), " << _this << "otrans_.get());" << endl; + "tcxx::bind(cob, this), " << _this << "otrans_.get());" << endl; } } scope_down(out); @@ -2742,8 +2744,8 @@ ProcessorGenerator::ProcessorGenerator(t_cpp_generator* generator, class_name_ = service_name_ + pstyle_ + "Processor"; if_name_ = service_name_ + "CobSvIf"; - finish_cob_ = "std::tr1::function cob, "; - finish_cob_decl_ = "std::tr1::function, "; + finish_cob_ = "tcxx::function cob, "; + finish_cob_decl_ = "tcxx::function, "; cob_arg_ = "cob, "; ret_type_ = "void "; } else { @@ -2877,25 +2879,25 @@ void ProcessorGenerator::generate_class_definition() { : ", const " + type_name((*f_iter)->get_returntype()) + "& _return"); f_header_ << indent() << "void return_" << (*f_iter)->get_name() << - "(std::tr1::function cob, int32_t seqid, " << + "(tcxx::function cob, int32_t seqid, " << "::apache::thrift::protocol::TProtocol* oprot, " << "void* ctx" << ret_arg << ");" << endl; if (generator_->gen_templates_) { f_header_ << indent() << "void return_" << (*f_iter)->get_name() << - "(std::tr1::function cob, int32_t seqid, " << + "(tcxx::function cob, int32_t seqid, " << "Protocol_* oprot, void* ctx" << ret_arg << ");" << endl; } // XXX Don't declare throw if it doesn't exist f_header_ << indent() << "void throw_" << (*f_iter)->get_name() << - "(std::tr1::function cob, int32_t seqid, " << + "(tcxx::function cob, int32_t seqid, " << "::apache::thrift::protocol::TProtocol* oprot, void* ctx, " << "::apache::thrift::TDelayedException* _throw);" << endl; if (generator_->gen_templates_) { f_header_ << indent() << "void throw_" << (*f_iter)->get_name() << - "(std::tr1::function cob, int32_t seqid, " << + "(tcxx::function cob, int32_t seqid, " << "Protocol_* oprot, void* ctx, " << "::apache::thrift::TDelayedException* _throw);" << endl; } @@ -3391,7 +3393,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice, out << "void " << tservice->get_name() << "AsyncProcessor" << class_suffix << "::process_" << tfunction->get_name() << - "(std::tr1::function cob, int32_t seqid, " << + "(tcxx::function cob, int32_t seqid, " << prot_type << "* iprot, " << prot_type << "* oprot)" << endl; scope_up(out); @@ -3472,14 +3474,14 @@ void t_cpp_generator::generate_process_function(t_service* tservice, // TODO(dreiss): Call the cob immediately? out << indent() << "iface_->" << tfunction->get_name() << "(" << - "std::tr1::bind(cob, true)" << endl; + "tcxx::bind(cob, true)" << endl; indent_up(); indent_up(); } else { string ret_arg, ret_placeholder; if (!tfunction->get_returntype()->is_void()) { ret_arg = ", const " + type_name(tfunction->get_returntype()) + "& _return"; - ret_placeholder = ", std::tr1::placeholders::_1"; + ret_placeholder = ", tcxx::placeholders::_1"; } // When gen_templates_ is true, the return_ and throw_ functions are @@ -3487,7 +3489,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice, // can resolve the correct overloaded version. out << indent() << "void (" << tservice->get_name() << "AsyncProcessor" << - class_suffix << "::*return_fn)(std::tr1::function " << + class_suffix << "::*return_fn)(tcxx::function " << "cob, int32_t seqid, " << prot_type << "* oprot, void* ctx" << ret_arg << ") =" << endl; out << @@ -3496,7 +3498,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice, if (!xceptions.empty()) { out << indent() << "void (" << tservice->get_name() << "AsyncProcessor" << - class_suffix << "::*throw_fn)(std::tr1::function " << + class_suffix << "::*throw_fn)(tcxx::function " << "cob, int32_t seqid, " << prot_type << "* oprot, void* ctx, " << "::apache::thrift::TDelayedException* _throw) =" << endl; out << @@ -3508,13 +3510,13 @@ void t_cpp_generator::generate_process_function(t_service* tservice, indent() << "iface_->" << tfunction->get_name() << "(" << endl; indent_up(); indent_up(); out << - indent() << "std::tr1::bind(return_fn, this, cob, seqid, oprot, ctx" << + indent() << "tcxx::bind(return_fn, this, cob, seqid, oprot, ctx" << ret_placeholder << ")"; if (!xceptions.empty()) { out << ',' << endl << - indent() << "std::tr1::bind(throw_fn, this, cob, seqid, oprot, " << - "ctx, std::tr1::placeholders::_1)"; + indent() << "tcxx::bind(throw_fn, this, cob, seqid, oprot, " << + "ctx, tcxx::placeholders::_1)"; } } @@ -3544,7 +3546,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice, out << "void " << tservice->get_name() << "AsyncProcessor" << class_suffix << "::return_" << tfunction->get_name() << - "(std::tr1::function cob, int32_t seqid, " << + "(tcxx::function cob, int32_t seqid, " << prot_type << "* oprot, void* ctx" << ret_arg_decl << ')' << endl; scope_up(out); @@ -3613,7 +3615,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice, out << "void " << tservice->get_name() << "AsyncProcessor" << class_suffix << "::throw_" << tfunction->get_name() << - "(std::tr1::function cob, int32_t seqid, " << + "(tcxx::function cob, int32_t seqid, " << prot_type << "* oprot, void* ctx, " << "::apache::thrift::TDelayedException* _throw)" << endl; scope_up(out); @@ -4477,7 +4479,7 @@ string t_cpp_generator::function_signature(t_function* tfunction, ? "()" : ("(" + type_name(ttype) + " const& _return)")); if (has_xceptions) { - exn_cob = ", std::tr1::function /* exn_cob */"; + exn_cob = ", tcxx::function /* exn_cob */"; } } else { throw "UNKNOWN STYLE"; @@ -4485,7 +4487,7 @@ string t_cpp_generator::function_signature(t_function* tfunction, return "void " + prefix + tfunction->get_name() + - "(std::tr1::function cob" + exn_cob + + "(tcxx::function cob" + exn_cob + argument_list(arglist, name_params, true) + ")"; } else { throw "UNKNOWN STYLE"; diff --git a/lib/cpp/src/thrift/cxxfunctional.h b/lib/cpp/src/thrift/cxxfunctional.h index b3c6e3e4..c24b91b1 100644 --- a/lib/cpp/src/thrift/cxxfunctional.h +++ b/lib/cpp/src/thrift/cxxfunctional.h @@ -120,4 +120,7 @@ }}} // apache::thrift::stdcxx #endif + // Alias for thrift c++ compatibility namespace + namespace tcxx = apache::thrift::stdcxx; + #endif // #ifndef _THRIFT_CXXFUNCTIONAL_H_ -- 2.17.1