Repository: thrift Updated Branches: refs/heads/master 879cab2ce -> 40f8ce2b4
THRIFT-2494: Add enum toString helper function in c_glib Client: c_glib Patch: Xiaodong Ma Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/40f8ce2b Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/40f8ce2b Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/40f8ce2b Branch: refs/heads/master Commit: 40f8ce2b4dd270d56ae39a4638f4a05bbdeb83d4 Parents: 879cab2 Author: Roger Meier <[email protected]> Authored: Sun May 4 21:48:48 2014 +0200 Committer: Roger Meier <[email protected]> Committed: Sun May 4 21:48:48 2014 +0200 ---------------------------------------------------------------------- compiler/cpp/src/generate/t_c_glib_generator.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/40f8ce2b/compiler/cpp/src/generate/t_c_glib_generator.cc ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/generate/t_c_glib_generator.cc b/compiler/cpp/src/generate/t_c_glib_generator.cc index 639f479..9e3ac3c 100644 --- a/compiler/cpp/src/generate/t_c_glib_generator.cc +++ b/compiler/cpp/src/generate/t_c_glib_generator.cc @@ -319,6 +319,24 @@ void t_c_glib_generator::generate_enum(t_enum *tenum) { "};" << endl << "typedef enum _" << this->nspace << name << " " << this->nspace << name << ";" << endl << endl; + + f_types_ << "/* return the name of the constant */" << endl; + f_types_ << "const char *" << endl; + f_types_ << "toString_"<<name<<"(int value); "<<endl<<endl;; + f_types_impl_ << "/* return the name of the constant */" << endl; + f_types_impl_ << "const char *" << endl; + f_types_impl_ << "toString_"<<name<<"(int value) "<<endl; + f_types_impl_ << "{" << endl; + f_types_impl_ << " static __thread char buf[16] = {0};" << endl; + f_types_impl_ << " switch(value) {" << endl; + for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) { + f_types_impl_ << " case " << this->nspace_uc << name_uc << "_" << (*c_iter)->get_name() + << ":" << "return \"" << this->nspace_uc << name_uc << "_" << (*c_iter)->get_name() + << "\";"<<endl; + } + f_types_impl_ << " default: g_snprintf(buf, 16, \"%d\", value); return buf;" << endl; + f_types_impl_ << " }" << endl; + f_types_impl_ << "}" << endl << endl; } /**
