mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 18:35:19 +00:00
THRIFT-2494: Add enum toString helper function in c_glib
Client: c_glib Patch: Xiaodong Ma
This commit is contained in:
parent
879cab2cea
commit
40f8ce2b4d
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user