const std::string& contents,
const std::string& comment_end);
+ /**
+ * check whether sub-namespace declaraction is used by generator.
+ * e.g. allow
+ * namespace py.twisted bar
+ * to specify namespace to use when -gen py:twisted is specified.
+ * Will be called with subnamespace, i.e. is_valid_namespace("twisted")
+ * will be called for the above example.
+ */
+ static bool is_valid_namespace(const std::string& sub_namespace) { return false; }
+
/**
* Escape string to use one in generated sources.
*/
const std::string& option_string)
= 0;
+ virtual bool is_valid_namespace(const std::string& sub_namespace) = 0;
+
std::string get_short_name() { return short_name_; }
std::string get_long_name() { return long_name_; }
std::string get_documentation() { return documentation_; }
const std::string& option_string) {
return new generator(program, parsed_options, option_string);
}
+
+ bool is_valid_namespace(const std::string& sub_namespace){
+ return generator::is_valid_namespace(sub_namespace);
+ }
};
class t_generator_registry {
return capitalize(program_name_);
}
+static bool is_valid_namespace(const std::string& sub_namespace) {
+ return sub_namespace == "prefix" || sub_namespace == "category";
+}
+
string t_st_generator::prefix(string class_name) {
string prefix = program_->get_namespace("smalltalk.prefix");
string name = capitalize(class_name);
// 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;
}