Author: jfarrell
Date: Fri Jun 22 03:22:53 2012
New Revision: 1352765
URL: http://svn.apache.org/viewvc?rev=1352765&view=rev
Log:
Thrift-1567:Thrift/cpp: Allow alternate classes to be used for strings
Client: cpp
Patch: dreiss
The goal of this diff is to allow Thrift strings to be used without
depending on std::string, since it looks like we're starting to move
away from std::string instead of moving to a better implementation.
Modified:
thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc
thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.h
thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
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=1352765&r1=1352764&r2=1352765&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc Fri Jun 22
03:22:53 2012
@@ -69,6 +69,9 @@ class t_cpp_generator : public t_oop_gen
iter = parsed_options.find("templates");
gen_templates_ = (iter != parsed_options.end());
+ gen_templates_only_ =
+ (iter != parsed_options.end() && iter->second == "only");
+
out_dir_base_ = "gen-cpp";
}
@@ -253,7 +256,13 @@ class t_cpp_generator : public t_oop_gen
bool gen_templates_;
/**
- * True if we should use a path prefix in our #include statements for other
+ * True iff we should generate process function pointers for only templatized
+ * reader/writer methods.
+ */
+ bool gen_templates_only_;
+
+ /**
+ * True iff we should use a path prefix in our #include statements for other
* thrift-generated header files.
*/
bool use_include_prefix_;
@@ -2896,11 +2905,15 @@ void ProcessorGenerator::generate_class_
f_header_ <<
indent() << "processMap_[\"" << (*f_iter)->get_name() << "\"] = ";
if (generator_->gen_templates_) {
- f_header_ << "ProcessFunctions(" << endl <<
- indent() << " &" << class_name_ << "::process_" <<
- (*f_iter)->get_name() << "," << endl <<
- indent() << " &" << class_name_ << "::process_" <<
- (*f_iter)->get_name() << ")";
+ f_header_ << "ProcessFunctions(" << endl;
+ if (generator_->gen_templates_only_) {
+ indent(f_header_) << " NULL," << endl;
+ } else {
+ indent(f_header_) << " &" << class_name_ << "::process_" <<
+ (*f_iter)->get_name() << "," << endl;
+ }
+ indent(f_header_) << " &" << class_name_ << "::process_" <<
+ (*f_iter)->get_name() << ")";
} else {
f_header_ << "&" << class_name_ << "::process_" << (*f_iter)->get_name();
}
@@ -2988,7 +3001,12 @@ void ProcessorGenerator::generate_dispat
f_out_ <<
indent() << "(this->*(pfn->second.specialized))";
} else {
- if (generator_->gen_templates_) {
+ if (generator_->gen_templates_only_) {
+ // TODO: This is a null pointer, so nothing good will come from calling
+ // it. Throw an exception instead.
+ f_out_ <<
+ indent() << "(this->*(pfn->second.generic))";
+ } else if (generator_->gen_templates_) {
f_out_ <<
indent() << "(this->*(pfn->second.generic))";
} else {
@@ -4246,6 +4264,11 @@ string t_cpp_generator::namespace_close(
string t_cpp_generator::type_name(t_type* ttype, bool in_typedef, bool arg) {
if (ttype->is_base_type()) {
string bname = base_type_name(((t_base_type*)ttype)->get_base());
+ std::map<string, string>::iterator it =
ttype->annotations_.find("cpp.type");
+ if (it != ttype->annotations_.end()) {
+ bname = it->second;
+ }
+
if (!arg) {
return bname;
}
Modified: thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.h
URL:
http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.h?rev=1352765&r1=1352764&r2=1352765&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.h (original)
+++ thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.h Fri Jun 22
03:22:53 2012
@@ -134,7 +134,8 @@ class TBinaryProtocolT
inline uint32_t writeDouble(const double dub);
- inline uint32_t writeString(const std::string& str);
+ template <typename StrType>
+ inline uint32_t writeString(const StrType& str);
inline uint32_t writeBinary(const std::string& str);
@@ -187,12 +188,14 @@ class TBinaryProtocolT
inline uint32_t readDouble(double& dub);
- inline uint32_t readString(std::string& str);
+ template<typename StrType>
+ inline uint32_t readString(StrType& str);
inline uint32_t readBinary(std::string& str);
protected:
- uint32_t readStringBody(std::string& str, int32_t sz);
+ template<typename StrType>
+ uint32_t readStringBody(StrType& str, int32_t sz);
Transport_* trans_;
Modified: thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
URL:
http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc?rev=1352765&r1=1352764&r2=1352765&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc (original)
+++ thrift/trunk/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc Fri Jun 22
03:22:53 2012
@@ -176,7 +176,8 @@ uint32_t TBinaryProtocolT<Transport_>::w
template <class Transport_>
-uint32_t TBinaryProtocolT<Transport_>::writeString(const std::string& str) {
+template<typename StrType>
+uint32_t TBinaryProtocolT<Transport_>::writeString(const StrType& str) {
uint32_t size = str.size();
uint32_t result = writeI32((int32_t)size);
if (size > 0) {
@@ -401,7 +402,8 @@ uint32_t TBinaryProtocolT<Transport_>::r
}
template <class Transport_>
-uint32_t TBinaryProtocolT<Transport_>::readString(std::string& str) {
+template<typename StrType>
+uint32_t TBinaryProtocolT<Transport_>::readString(StrType& str) {
uint32_t result;
int32_t size;
result = readI32(size);
@@ -414,7 +416,8 @@ uint32_t TBinaryProtocolT<Transport_>::r
}
template <class Transport_>
-uint32_t TBinaryProtocolT<Transport_>::readStringBody(std::string& str,
+template<typename StrType>
+uint32_t TBinaryProtocolT<Transport_>::readStringBody(StrType& str,
int32_t size) {
uint32_t result = 0;