includes : output |
Output the block to the stream.
Any other method of any other object can call this method. This is called 'public' access.
The data-type returned is "voidtype";
This method is contained in the object "includes".
The method takes the following arguments:
filedef : Pointer to tgl_structure_parser
Not sure.
obj : Pointer to @schemaobj
Not sure.
This method is overridden from an abstract method with the same signature found in the object @block.
The namespaces "ph::tools::schema" and "ph::xmlobj" are used.
The files "schema/schema_method.hpp", "schema/schema_obj.hpp", "schema/schema_typename.hpp", "tgl_block.hpp", "tgl_structure_parser.hpp" and "tgl_list_parser.hpp" are included.
Collect includes.
if (obj->parent()) { xmlobj::xmlobj *outer = obj->parent(); if (!outer) { filedef->error("No object as outer of [" + obj->name() + "] in schema."); filedef->write_output("????"); } else { std::set<std::string> includes; {Parse other and includes} {Use superclass include} {Process members} {Process method arguments} {Process method includes} for (std::set<std::string>::iterator i=includes.begin(); i != includes.end(); i++) { if (_language == "C++") filedef->write_output("#include " + *i + "\\n"); else if (_language == "Java") filedef->write_output("import " + *i + ";\\n"); else { filedef->error("Need to implement that language."); return; } } } } else { filedef->error("No outer"); filedef->write_output("????"); }
1 Parse out the other classes and other includes lists.
{Parse other and includes} ≡ tgl_list_parser lp; std::vector<std::string> votherclasses; std::vector<std::string> votherincludes; if (!lp.parse_to_vector(_otherclasses, &votherclasses)) { filedef->error("otherclasses list was not in appropriate format."); return; } if (!lp.parse_to_vector(_otherincludes, &votherincludes)) { filedef->error("otherincludes list was not in appropriate format."); return; }
2 If the superclass has an include definition, then use that.
{Use superclass include} ≡ std::string include = ""; if (_language == "C++") { include = outer->get("include"); if (include != "") include = "\\"" + include + "\\""; } else if (_language == "Java") include = outer->get("imp"); else { filedef->error("Need to implement that language."); return; } if (include != "") includes.insert(include); else { // see if the class is in the "otherclasses" list, and if // so, use that include path. std::vector<std::string>::iterator ic = votherclasses.begin(); std::vector<std::string>::iterator ii = votherincludes.begin(); bool found = false; while (ic != votherclasses.end() && ii != votherincludes.end() && !found) { if (*ic == outer->name()) { if (_language == "C++") includes.insert("\\"" + *ii + "\\""); else if (_language == "Java") includes.insert(*ii); found = true; } ic++; ii++; } if (!found && _language == "C++") { // if the classname is empty, then don't output the include for it. Otherwise // only output if it's in C++. std::string classname = outer->get("classname"); if (classname != "") includes.insert("\\"" + classname + ".hpp\\""); } }
3 Test for any vector/ref members/enum.
{Process members} ≡ { xmlobj_typed_vector<schema_typename> *v = dynamic_cast<xmlobj_typed_vector<schema_typename> *>( obj->get_composite_object("members")); if (!v) { filedef->error("No composite member 'members'."); return; } for (xmlobj_typed_vector<schema_typename>::iterator i=v->begin(); i != v->end(); i++) { if (!collect_typename(filedef, obj, *i, &includes)) return; } }
4 Test for any vector/ref arguments to functions.
{Process method arguments} ≡ { xmlobj_typed_vector<schema_method> *methods = dynamic_cast<xmlobj_typed_vector<schema_method> *>( obj->get_composite_object("methods")); if (!methods) { filedef->error("No composite member 'methods'."); return; } for (xmlobj_typed_vector<schema_method>::iterator method=methods->begin(); method != methods->end(); method++) { xmlobj_typed_vector<schema_typename> *v = dynamic_cast<xmlobj_typed_vector<schema_typename> *>( method->get_composite_object("arguments")); if (!v) { filedef->error("No composite member 'arguments'."); return; } for (xmlobj_typed_vector<schema_typename>::iterator i=v->begin(); i != v->end(); i++) { if (!collect_typename(filedef, obj, *i, &includes)) return; } // and also the return type. xmlobj_typed_ref<schema_typename> *r = dynamic_cast<xmlobj_typed_ref<schema_typename> *>( method->get_composite_object("returns")); if (!r) { filedef->error("No composite member 'returns'."); return; } if (r->get()) if (!collect_typename(filedef, obj, *r->get(), &includes)) return; } }
5 Add in any includes from methods.
{Process method includes} ≡ { xmlobj_typed_vector<schema_method> *methods = dynamic_cast<xmlobj_typed_vector<schema_method> *>( obj->get_composite_object("methods")); if (!methods) { filedef->error("No composite member 'methods'."); return; } for (xmlobj_typed_vector<schema_method>::iterator method=methods->begin(); method != methods->end(); method++) { // insert this include. std::string inc = method->get("includes"); if (inc != "") { if (!lp.parse_to_set(inc, &includes)) { filedef->error("List was not in appropriate format."); return; } } } }