void t_xsd_generator::generate_element(ostream& out,
string name,
t_type* ttype,
- vector<string> attrs,
+ t_struct* attrs,
bool optional,
bool nillable,
bool list_element) {
indent(out) <<
"<xsd:element name=\"" << name << "\"" << soptional << snillable << ">" << endl;
indent_up();
- if (attrs.size() == 0 && ttype->is_void()) {
+ if (attrs == NULL && ttype->is_void()) {
indent(out) <<
"<xsd:complexType />" << endl;
} else {
subname = type_name(subtype);
}
f_php_ << "$GLOBALS['" << program_->get_name() << "_xsd_elt_" << name << "'] = '" << subname << "';" << endl;
- generate_element(out, subname, subtype, vector<string>(), false, false, true);
+ generate_element(out, subname, subtype, NULL, false, false, true);
indent_down();
indent(out) << "</xsd:sequence>" << endl;
indent(out) << "<xsd:attribute name=\"list\" type=\"xsd:boolean\" />" << endl;
}
- vector<string>::iterator a_iter;
- for (a_iter = attrs.begin(); a_iter != attrs.end(); ++a_iter) {
- indent(out) << "<xsd:attribute name=\"" << (*a_iter) << "\" type=\"xsd:boolean\" />" << endl;
+ if (attrs != NULL) {
+ const vector<t_field*>& members = attrs->get_members();
+ vector<t_field*>::const_iterator a_iter;
+ for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) {
+ indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\"" << type_name((*a_iter)->get_type()) << "\" />" << endl;
+ }
}
indent_down();
indent(out) <<
indent(out) <<
"</xsd:element>" << endl;
} else {
- if (attrs.size() == 0) {
+ if (attrs == NULL) {
indent(out) <<
"<xsd:element name=\"" << name << "\"" << " type=\"" << type_name(ttype) << "\"" << soptional << snillable << " />" << endl;
} else {
indent_up();
indent(out) << "<xsd:extension base=\"" << type_name(ttype) << "\">" << endl;
indent_up();
- vector<string>::iterator a_iter;
- for (a_iter = attrs.begin(); a_iter != attrs.end(); ++a_iter) {
- indent(out) << "<xsd:attribute name=\"" << (*a_iter) << "\" type=\"xsd:boolean\" />" << endl;
+ const vector<t_field*>& members = attrs->get_members();
+ vector<t_field*>::const_iterator a_iter;
+ for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) {
+ indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\"" << type_name((*a_iter)->get_type()) << "\" />" << endl;
}
indent_down();
indent(out) << "</xsd:extension>" << endl;
private:
- void generate_element(std::ostream& out, std::string name, t_type* ttype, std::vector<std::string> attrs=std::vector<std::string>(), bool optional=false, bool nillable=false, bool list_element=false);
+ void generate_element(std::ostream& out, std::string name, t_type* ttype, t_struct* attrs=NULL, bool optional=false, bool nillable=false, bool list_element=false);
std::string ns(std::string in, std::string ns) {
return ns + ":" + in;
#include <string>
+// Forward declare for xsd_attrs
+class t_struct;
+
/**
* Class to represent a field in a thrift structure. A field has a data type,
* a symbolic name, and a numeric identifier.
key_(0),
value_(NULL),
xsd_optional_(false),
- xsd_nillable_(false) {}
+ xsd_nillable_(false),
+ xsd_attrs_(NULL) {}
t_field(t_type* type, std::string name, int32_t key) :
type_(type),
key_(key),
value_(NULL),
xsd_optional_(false),
- xsd_nillable_(false) {}
+ xsd_nillable_(false),
+ xsd_attrs_(NULL) {}
~t_field() {}
return xsd_nillable_;
}
- void add_xsd_attr(std::string attr) {
- xsd_attrs_.push_back(attr);
+ void set_xsd_attrs(t_struct* xsd_attrs) {
+ xsd_attrs_ = xsd_attrs;
}
- const std::vector<std::string>& get_xsd_attrs() {
+ t_struct* get_xsd_attrs() {
return xsd_attrs_;
}
bool xsd_optional_;
bool xsd_nillable_;
- std::vector<std::string> xsd_attrs_;
+ t_struct* xsd_attrs_;
std::string doc_;
bool has_doc_;