📄 types.cpp
字号:
else if (pflag && complexType.name) fprintf(stream, "class %s : public xsd__anyType\n{ public:\n", t); else fprintf(stream, "class %s\n{ public:\n", t); if (complexType.complexContent->restriction->group) gen(URI, *complexType.complexContent->restriction->group); if (complexType.complexContent->restriction->all) gen(URI, *complexType.complexContent->restriction->all); if (complexType.complexContent->restriction->sequence) gen(URI, *complexType.complexContent->restriction->sequence); if (complexType.complexContent->restriction->choice) gen(URI, name, *complexType.complexContent->restriction->choice); // TODO // gen(URI, complexType.complexContent->restriction->attribute); const xs__complexType *p = &complexType; bool flag = true; do { if (p->complexContent && p->complexContent->restriction) { gen(URI, p->complexContent->restriction->attribute); if (p->complexContent->restriction->anyAttribute && flag) gen(URI, *p->complexContent->restriction->anyAttribute); if (p->complexContent->restriction->complexTypePtr()) p = p->complexContent->restriction->complexTypePtr(); else break; } else if (p->complexContent && p->complexContent->extension) { gen(URI, p->complexContent->extension->attribute); gen(URI, p->complexContent->extension->attributeGroup); if (p->complexContent->extension->anyAttribute && flag) { gen(URI, *p->complexContent->extension->anyAttribute); flag = false; } if (p->complexContent->extension->complexTypePtr()) p = p->complexContent->extension->complexTypePtr(); else break; } else { gen(URI, p->attribute); gen(URI, p->attributeGroup); if (p->anyAttribute && flag) gen(URI, *p->anyAttribute); break; } } while (p); } } else if (complexType.complexContent->extension) { if (!anonymous) fprintf(stream, "\n/// \"%s\":%s is a%s complexType with complexContent extension of %s.\n", URI?URI:"", name, complexType.abstract?"n abstract":"", complexType.complexContent->extension->base); document(complexType.annotation); if (anonymous) fprintf(stream, " struct %s\n {\n", t); else if (cflag) fprintf(stream, "struct %s\n{\n", t); else if (fflag) fprintf(stream, "class %s\n{ public:\n", t); else // TODO: what to do if base class is in another namespace and elements must be qualified in XML payload? { fprintf(stream, "class %s : public %s\n{ public:\n", t, cname(NULL, NULL, complexType.complexContent->extension->base)); soapflag = true; } xs__complexType *p = complexType.complexContent->extension->complexTypePtr(); while (p) { const char *pURI; if (p->schemaPtr()) pURI = p->schemaPtr()->targetNamespace; else pURI = URI; const char *b = cname(NULL, pURI, p->name); static int nesting = 0; if (cflag || fflag || anonymous) fprintf(stream, "/// INHERITED FROM %s:\n", b); else if (nesting == 0) fprintf(stream, "/* INHERITED FROM %s:\n", b); else fprintf(stream, " INHERITED FROM %s:\n", b); nesting++; if (p->complexContent && p->complexContent->extension) { if (p->complexContent->extension->group) gen(pURI, *p->complexContent->extension->group); // schema URI? if (p->complexContent->extension->all) gen(pURI, *p->complexContent->extension->all); if (p->complexContent->extension->sequence) gen(pURI, *p->complexContent->extension->sequence); if (p->complexContent->extension->choice) gen(pURI, p->name, *p->complexContent->extension->choice); gen(pURI, p->complexContent->extension->attribute); gen(pURI, p->complexContent->extension->attributeGroup); if (p->complexContent->extension->anyAttribute) gen(pURI, *p->complexContent->extension->anyAttribute); p = p->complexContent->extension->complexTypePtr(); modify(b); nesting--; if (cflag || fflag || anonymous) fprintf(stream, "// END OF INHERITED\n"); else if (nesting == 0) fprintf(stream, " END OF INHERITED */\n"); else fprintf(stream, " END OF INHERITED\n"); } else { if (p->all) gen(pURI, p->all->element); // what about schema URI? else if (p->choice) gen(pURI, p->name, *p->choice); else if (p->all) gen(pURI, *p->all); else if (p->sequence) gen(pURI, *p->sequence); else if (p->any) gen(pURI, *p->any); gen(pURI, p->attribute); gen(pURI, p->attributeGroup); if (p->anyAttribute) gen(pURI, *p->anyAttribute); modify(b); nesting--; if (cflag || fflag || anonymous) fprintf(stream, "// END OF INHERITED\n"); else if (nesting == 0) fprintf(stream, " END OF INHERITED */\n"); else fprintf(stream, " END OF INHERITED\n"); break; } } if (complexType.complexContent->extension->group) gen(URI, *complexType.complexContent->extension->group); if (complexType.complexContent->extension->all) gen(URI, *complexType.complexContent->extension->all); if (complexType.complexContent->extension->sequence) gen(URI, *complexType.complexContent->extension->sequence); if (complexType.complexContent->extension->choice) gen(URI, name, *complexType.complexContent->extension->choice); gen(URI, complexType.complexContent->extension->attribute); gen(URI, complexType.complexContent->extension->attributeGroup); if (complexType.complexContent->extension->anyAttribute) gen(URI, *complexType.complexContent->extension->anyAttribute); } else fprintf(stream, "//\tunrecognized\n"); } else { if (!anonymous) fprintf(stream, "\n/// \"%s\":%s is a%s complexType.\n", URI?URI:"", name, complexType.abstract?"n abstract":""); document(complexType.annotation); if (anonymous) fprintf(stream, " struct %s\n {\n", t); else if (cflag) fprintf(stream, "struct %s\n{\n", t); else if (pflag && complexType.name) fprintf(stream, "class %s : public xsd__anyType\n{ public:\n", t); else fprintf(stream, "class %s\n{ public:\n", t); if (complexType.all) gen(URI, *complexType.all); else if (complexType.choice) gen(URI, name, *complexType.choice); else if (complexType.sequence) gen(URI, *complexType.sequence); else if (complexType.any) gen(URI, *complexType.any); } gen(URI, complexType.attribute); gen(URI, complexType.attributeGroup); if (complexType.anyAttribute) gen(URI, *complexType.anyAttribute); if (complexType.mixed || (complexType.complexContent && complexType.complexContent->extension && complexType.complexContent->extension->complexTypePtr() && complexType.complexContent->extension->complexTypePtr()->mixed)) { fprintf(stream, "/// TODO: this mixed complexType is user-definable.\n/// Consult the protocol documentation to change or insert declarations.\n/// Use wsdl2h option -d to use xsd__anyType DOM.\n"); if (dflag) { fprintf(stream, pointerformat, "xsd__anyType", "__mixed"); fprintf(stream, ";\t///< Catch mixed content in DOM.\n"); } else { fprintf(stream, elementformat, "_XML", "__mixed"); fprintf(stream, ";\t///< Catch mixed content in XML string\n"); } } if (!anonymous) { if (!cflag && !(pflag && complexType.name) && !soapflag) { if (!complexType.complexContent || !complexType.complexContent->extension || !complexType.complexContent->extension->complexTypePtr()) { fprintf(stream, "/// A handle to the soap struct that manages this instance (automatically set)\n"); fprintf(stream, pointerformat, "struct soap", "soap"); fprintf(stream, ";\n"); } } modify(t); fprintf(stream, "};\n"); } scope.pop_back();}void Types::gen(const char *URI, const vector<xs__attribute>& attributes){ for (vector<xs__attribute>::const_iterator attribute = attributes.begin(); attribute != attributes.end(); ++attribute) gen(URI, *attribute);}void Types::gen(const char *URI, const xs__attribute& attribute){ const char *name, *type, *nameURI = NULL, *typeURI = NULL; name = attribute.name; type = attribute.type; bool is_optional = attribute.use != required && attribute.use != default_ && attribute.use != fixed_ && !attribute.value; document(attribute.annotation); if (!URI || strcmp(URI, attribute.schemaPtr()->targetNamespace)) nameURI = attribute.schemaPtr()->targetNamespace; if (attribute.attributePtr()) // attribute ref { char *prefix = NULL; name = attribute.attributePtr()->name; if (attribute.schemaPtr() != attribute.attributePtr()->schemaPtr()) nameURI = attribute.attributePtr()->schemaPtr()->targetNamespace; if (attribute.attributePtr()->type) { type = attribute.attributePtr()->type; } else { type = name; typeURI = attribute.attributePtr()->schemaPtr()->targetNamespace; prefix = "_"; } fprintf(stream, "/// Attribute reference %s.\n", attribute.ref); document(attribute.attributePtr()->annotation); fprintf(stream, attributeformat, pname(is_optional, prefix, typeURI, type), aname(NULL, nameURI, name)); // make sure no name - type clash } else if (name && type) { fprintf(stream, "/// Attribute %s of type %s.\n", name, type); fprintf(stream, attributeformat, pname(is_optional, NULL, URI, type), aname(NULL, nameURI, name)); // make sure no name - type clash } else if (name && attribute.simpleTypePtr()) { fprintf(stream, "@"); gen(URI, name, *attribute.simpleTypePtr(), true); fprintf(stream, elementformat, "", aname(NULL, nameURI, name)); } else if (attribute.ref) { fprintf(stream, "/// Attribute reference %s.\n", attribute.ref); fprintf(stream, attributeformat, pname(is_optional, NULL, NULL, attribute.ref), aname(NULL, NULL, attribute.ref)); } else { fprintf(stream, "/// Warning: attribute '%s' has no type or ref. Assuming string content.\n", name?name:""); fprintf(stream, attributeformat, tname(NULL, NULL, "xs:string"), aname(NULL, nameURI, name)); } switch (attribute.use) { case optional: fprintf(stream, " 0"); break; case prohibited: fprintf(stream, " 0:0"); break; case required: fprintf(stream, " 1"); break; default: break; } if (attribute.value) { if (type) { const char *t = tname(NULL, NULL, type); if (!strncmp(t, "unsigned ", 9)) t += 9; if (!strcmp(t, "bool") || !strcmp(t, "char") || !strcmp(t, "double") || !strcmp(t, "float") || !strcmp(t, "int") || !strcmp(t, "long") || !strcmp(t, "LONG64") || !strcmp(t, "short") || !strcmp(t, "ULONG64")) fprintf(stream, " = %s", attribute.value); else if (!strncmp(t, "enum ", 5)) fprintf(stream, " = %s", ename(t + 5, attribute.value)); else if (!strcmp(t, "char*") || !strcmp(t, "char *") // not elegant || !strcmp(t, "std::string") || !strcmp(t, "std::string*") || !strcmp(t, "std::string *")) // not elegant fprintf(stream, " = \"%s\"", cstring(attribute.value)); else if (!strcmp(t, "xsd__QName") && attribute.value_) // QName is in value_ fprintf(stream, " = \"%s\"", cstring(attribute.value_)); } fprintf(stream, ";\t///< Default value=\"%s\".\n", attribute.value); } else if (attribute.use == required) fprintf(stream, ";\t///< Required attribute.\n"); else if (attribute.use == prohibited) fprintf(stream, ";\t///< Prohibited attribute.\n"); else fprintf(stream, ";\t///< Optional attribute.\n");}void Types::gen(const char *URI, const vector<xs__attributeGroup>& attributeGroups){ for (vector<xs__attributeGroup>::const_iterator attributeGroup = attributeGroups.begin(); attributeGroup != attributeGroups.end(); ++attributeGroup) { if ((*attributeGroup).attributeGroupPtr()) // attributeGroup ref { if ((*attributeGroup).schemaPtr() == (*attributeGroup).attributeGroupPtr()->schemaPtr()) { gen(URI, (*attributeGroup).attributeGroupPtr()->attribute); gen(URI, (*attributeGroup).attributeGroupPtr()->attributeGroup); } else { gen((*attributeGroup).attributeGroupPtr()->schemaPtr()->targetNamespace, (*attributeGroup).attributeGroupPtr()->attribute); gen((*attributeGroup).attributeGroupPtr()->schemaPtr()->targetNamespace, (*attributeGroup).attributeGroupPtr()->attributeGroup); } if ((*attributeGroup).attributeGroupPtr()->anyAttribute) gen(URI, *(*attributeGroup).attributeGroupPtr()->anyAttribute); } else { gen(URI, (*attributeGroup).attribute); gen(URI, (*attributeGroup).attributeGroup); if ((*attributeGroup).anyAttribute) gen(URI, *(*attributeGroup).anyAttribute); } }}void Types::gen(const char *URI, const vector<xs__all>& alls){ for (vector<xs__all>::const_iterator all = alls.begin(); all != alls.end(); ++all) gen(URI, *all);}void Types::gen(const char *URI, const xs__all& all){ bool tmp_union1 = with_union; bool tmp_union2 = fake_union; with_union = false; fake_union = false; gen(URI, all.element); with_union = tmp_union1; fake_union = tmp_union2;}void Types::gen(const char *URI, const vector<xs__sequence>& sequences){ for (vector<xs__sequence>::const_iterator sequence = sequences.begin(); sequence != sequences.end(); ++sequence) gen(URI, *sequence);}void Types::gen(const char *URI, const vector<xs__sequence*>& sequences){ for (vector<xs__sequence*>::const_iterator sequence = sequences.begin(); sequence != sequences.end(); ++sequence) gen(URI, **sequence);}void Types::gen(const char *URI, const xs__sequence& sequence){ bool tmp_union1 = with_union; bool tmp_union2 = fake_union; with_union = false; fake_union = false; document(sequence.annotation); gen(URI, sequence.element); gen(URI, sequence.group); gen(URI, sequence.choice); gen(URI, sequence.sequence); gen(URI, sequence.any); with_union = tmp_union1; fake_union = tmp_union2;}void Types::gen(const char *URI, const vector<xs__element>& elements){ for (vector<xs__element>::const_iterator element = elements.begin(); element != elements.end(); ++element) gen(URI, *element);}void Types::gen(const char *URI, const xs__element& element){ const char *name, *type, *nameURI = NULL, *typeURI = NULL; name = element.name; type = element.type; document(element.annotation); if (!URI || strcmp(URI, element.schemaPtr()->targetNamespace)) nameUR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -