compiler: make a standard way for language generators to accept sub-namespaces
This patch adds a new method to t_generator that allows the compiler to avoid special cases in checking for sub-namespaces in the Thrift IDL.
Patch: Bruce Lowekamp
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@987565 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index 68697c6..f755643 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -160,16 +160,26 @@
// Language neutral namespace / packaging
void set_namespace(std::string language, std::string name_space) {
+ size_t sub_index = language.find('.');
+ std::string base_language = language.substr(0, sub_index);
+ std::string sub_namespace;
+
t_generator_registry::gen_map_t my_copy = t_generator_registry::get_generator_map();
t_generator_registry::gen_map_t::iterator it;
- it=my_copy.find(language);
+ it=my_copy.find(base_language);
if (it == my_copy.end()) {
- if (language != "smalltalk.prefix" && language != "smalltalk.package") {
- throw "No generator named '" + language + "' could be found!";
- }
+ throw "No generator named '" + base_language + "' could be found!";
}
+
+ if (sub_index != std::string::npos) {
+ std::string sub_namespace = language.substr(sub_index+1);
+ if(! it->second->is_valid_namespace(sub_namespace)) {
+ throw base_language +" generator does not accept '" + sub_namespace + "' as sub-namespace!";
+ }
+ }
+
namespaces_[language] = name_space;
}