pynames
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@827893 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index ec4095b..8c54502 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -354,6 +354,8 @@
* @param tenum The enumeration
*/
void t_py_generator::generate_enum(t_enum* tenum) {
+ std::ostringstream to_string_mapping, from_string_mapping;
+
f_types_ <<
"class " << tenum->get_name() <<
(gen_newstyle_ ? "(object)" : "") <<
@@ -361,6 +363,9 @@
indent_up();
generate_python_docstring(f_types_, tenum);
+ to_string_mapping << indent() << "_VALUES_TO_NAMES = {" << endl;
+ from_string_mapping << indent() << "_NAMES_TO_VALUES = {" << endl;
+
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
int value = -1;
@@ -373,10 +378,21 @@
f_types_ <<
indent() << (*c_iter)->get_name() << " = " << value << endl;
+
+ // Dictionaries to/from string names of enums
+ to_string_mapping <<
+ indent() << indent() << value << ": \"" <<
+ escape_string((*c_iter)->get_name()) << "\"," << endl;
+ from_string_mapping <<
+ indent() << indent() << '"' << escape_string((*c_iter)->get_name()) <<
+ "\": " << value << ',' << endl;
}
+ to_string_mapping << indent() << "}" << endl;
+ from_string_mapping << indent() << "}" << endl;
indent_down();
f_types_ << endl;
+ f_types_ << to_string_mapping.str() << endl << from_string_mapping.str() << endl;
}
/**