Author: dreiss
Date: Wed Oct 21 06:09:16 2009
New Revision: 827893
URL: http://svn.apache.org/viewvc?rev=827893&view=rev
Log:
pynames
Modified:
incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc
Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc?rev=827893&r1=827892&r2=827893&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc
(original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc Wed Oct
21 06:09:16 2009
@@ -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;
}
/**