📄 types.cpp
字号:
{ if (!anonymous && !simpleType.restriction->pattern.empty()) { fprintf(stream, " \""); for (vector<xs__pattern>::const_iterator pattern2 = simpleType.restriction->pattern.begin(); pattern2 != simpleType.restriction->pattern.end(); ++pattern2) { if (pattern2 != simpleType.restriction->pattern.begin()) fprintf(stream, "|"); fprintf(stream, "%s", xstring((*pattern2).value)); } fprintf(stream, "\""); } // add range info only when type is numeric bool is_numeric = false; if (!strncmp(s, "unsigned ", 9)) s += 9; if (strstr("char short int LONG64 float double ", s)) is_numeric = true; if (!anonymous && simpleType.restriction->minLength && simpleType.restriction->minLength->value) fprintf(stream, " %s", simpleType.restriction->minLength->value); else if (is_numeric && !anonymous && simpleType.restriction->minInclusive && simpleType.restriction->minInclusive->value && is_integer(simpleType.restriction->minInclusive->value)) fprintf(stream, " %s", simpleType.restriction->minInclusive->value); if (!anonymous && simpleType.restriction->maxLength && simpleType.restriction->maxLength->value) fprintf(stream, ":%s", simpleType.restriction->maxLength->value); else if (is_numeric && !anonymous && simpleType.restriction->maxInclusive && simpleType.restriction->maxInclusive->value && is_integer(simpleType.restriction->maxInclusive->value)) fprintf(stream, ":%s", simpleType.restriction->maxInclusive->value); if (!anonymous) { fprintf(stream, ";\n"); if (pflag && simpleType.name) { const char *s = aname(prefix, URI, name); knames.insert(s); s = aname(prefix, URI, name); fprintf(stream, "\n/// Class wrapper\n"); fprintf(stream, "class %s : public xsd__anyType\n{ public:\n", s); fprintf(stream, elementformat, tname(prefix, URI, name), "__item;"); modify(s); fprintf(stream, "\n};\n"); } } } } } else if (simpleType.list) { if (simpleType.list->restriction && simpleType.list->restriction->base) { if (!anonymous) { fprintf(stream, "\n/// \"%s\":%s is a simpleType list restriction of %s.\n", URI?URI:"", name, simpleType.list->restriction->base); fprintf(stream, "/// Note: this enumeration is a bitmask, so a set of values is supported (using | and & bit-ops on the bit vector).\n"); } document(simpleType.annotation); if (!anonymous) { t = deftname(ENUM, NULL, false, prefix, URI, name); if (t) fprintf(stream, "enum * %s\n{\n", t); } else { t = ""; fprintf(stream, "enum *\n{\n"); } if (t) { for (vector<xs__enumeration>::const_iterator enumeration = simpleType.list->restriction->enumeration.begin(); enumeration != simpleType.list->restriction->enumeration.end(); ++enumeration) { if ((*enumeration).value) { if (!strcmp(simpleType.list->restriction->base, "xs:QName") && (*enumeration).value_) fprintf(stream, "\t%s,\t///< %s value=\"%s\"\n", ename(t, (*enumeration).value_), simpleType.list->restriction->base, (*enumeration).value_); else fprintf(stream, "\t%s,\t///< %s value=\"%s\"\n", ename(t, (*enumeration).value), simpleType.list->restriction->base, (*enumeration).value); } else fprintf(stream, "//\tunrecognized: bitmask enumeration '%s' has no value\n", t); } if (!anonymous) { fprintf(stream, "};\n"); if (yflag) fprintf(stream, "/// Typedef synonym for enum %s.\ntypedef enum %s %s;\n", t, t, t); if (pflag && simpleType.name) { const char *s = aname(prefix, URI, name); knames.insert(s); s = aname(prefix, URI, name); fprintf(stream, "\n/// Class wrapper\n"); fprintf(stream, "class %s : public xsd__anyType\n{ public:\n", s); fprintf(stream, elementformat, tname(prefix, URI, name), "__item;"); modify(s); fprintf(stream, "\n};\n"); } } else fprintf(stream, "}\n"); } } else if (simpleType.list->itemType) { const xs__simpleType *p = simpleType.list->itemTypePtr(); if (p && p->restriction && p->restriction->base && !p->restriction->enumeration.empty() && p->restriction->enumeration.size() <= 64) { if (!anonymous) { fprintf(stream, "\n/// \"%s\":%s is a simpleType list of %s.\n", URI?URI:"", name, simpleType.list->itemType); fprintf(stream, "/// Note: this enumeration is a bitmask, so a set of values is supported (using | and & bit-ops on the bit vector).\n"); } document(simpleType.annotation); if (!anonymous) { t = deftname(ENUM, NULL, false, prefix, URI, name); if (t) fprintf(stream, "enum * %s\n{\n", t); } else { t = ""; fprintf(stream, "enum *\n{\n"); } if (t) { for (vector<xs__enumeration>::const_iterator enumeration = p->restriction->enumeration.begin(); enumeration != p->restriction->enumeration.end(); ++enumeration) { if ((*enumeration).value) fprintf(stream, "\t%s,\t///< %s value=\"%s\"\n", ename(t, (*enumeration).value), p->restriction->base, (*enumeration).value); else fprintf(stream, "//\tunrecognized: bitmask enumeration '%s' has no value\n", t); } if (!anonymous) { fprintf(stream, "};\n"); if (yflag) fprintf(stream, "/// Typedef synonym for enum %s.\ntypedef enum %s %s;\n", t, t, t); if (pflag && simpleType.name) { const char *s = aname(prefix, URI, name); knames.insert(s); s = aname(prefix, URI, name); fprintf(stream, "\n/// Class wrapper.\n"); fprintf(stream, "class %s : public xsd__anyType\n{ public:\n", s); fprintf(stream, elementformat, tname(prefix, URI, name), "__item;"); modify(s); fprintf(stream, "\n};\n"); } } else fprintf(stream, "}\n"); } } else { const char *s = tname(NULL, NULL, "xsd:string"); if (!anonymous) { fprintf(stream, "\n/// \"%s\":%s is a simpleType containing a whitespace separated list of %s.\n", URI?URI:"", name, simpleType.list->itemType); t = deftname(TYPEDEF, NULL, strchr(s, '*') != NULL, prefix, URI, name); } document(simpleType.annotation); if (t) fprintf(stream, "typedef %s %s;\n", s, t); else { fprintf(stream, elementformat, s, ""); fprintf(stream, "\n"); } } } else { if (!anonymous) { fprintf(stream, "\n/// \"%s\":%s is a simpleType list.\n", URI?URI:"", name); fprintf(stream, "/// Note: this enumeration is a bitmask, so a set of values is supported (using | and & bit-ops on the bit vector).\n"); } document(simpleType.annotation); if (!anonymous) { t = deftname(ENUM, NULL, false, prefix, URI, name); if (t && !eflag) fprintf(stream, "/// Note: enum values are prefixed with '%s' to avoid name clashes, please use wsdl2h option -e to omit this prefix\n", t); } else t = ""; if (t) { fprintf(stream, "enum * %s\n{\n", t); for (vector<xs__simpleType>::const_iterator simple = simpleType.list->simpleType.begin(); simple != simpleType.list->simpleType.end(); ++simple) { if ((*simple).restriction && (*simple).restriction->base) { for (vector<xs__enumeration>::const_iterator enumeration = (*simple).restriction->enumeration.begin(); enumeration != (*simple).restriction->enumeration.end(); ++enumeration) { if ((*enumeration).value) fprintf(stream, "\t%s,\t///< %s value=\"%s\"\n", ename(t, (*enumeration).value), (*simple).restriction->base, (*enumeration).value); else fprintf(stream, "//\tunrecognized: bitmask enumeration '%s' has no value\n", t); } } } if (!anonymous) { fprintf(stream, "};\n"); if (yflag) fprintf(stream, "/// Typedef synonym for enum %s.\ntypedef enum %s %s;\n", t, t, t); if (pflag && simpleType.name) { const char *s = aname(prefix, URI, name); knames.insert(s); s = aname(prefix, URI, name); fprintf(stream, "\n/// Class wrapper.\n"); fprintf(stream, "class %s : public xsd__anyType\n{ public:\n", s); fprintf(stream, elementformat, tname(prefix, URI, name), "__item;"); modify(s); fprintf(stream, "\n};\n"); } } else fprintf(stream, "}\n"); } } } else if (simpleType.union_) { if (simpleType.union_->memberTypes) { const char *s = tname(NULL, NULL, "xsd:string"); if (!anonymous) t = deftname(TYPEDEF, NULL, strchr(s, '*') != NULL, prefix, URI, name); fprintf(stream, "\n/// union of values \"%s\"\n", simpleType.union_->memberTypes); if (t) fprintf(stream, "typedef %s %s;\n", s, t); else { fprintf(stream, elementformat, s, ""); fprintf(stream, "\n"); } } else if (!simpleType.union_->simpleType.empty()) { const char *s = tname(NULL, NULL, "xsd:string"); fprintf(stream, "\n"); if (!anonymous) t = deftname(TYPEDEF, NULL, strchr(s, '*') != NULL, prefix, URI, name); for (vector<xs__simpleType>::const_iterator simpleType1 = simpleType.union_->simpleType.begin(); simpleType1 != simpleType.union_->simpleType.end(); ++simpleType1) if ((*simpleType1).restriction) { fprintf(stream, "/// union of values from \"%s\"\n", (*simpleType1).restriction->base); // TODO: are there any other types we should report here? } if (t) fprintf(stream, "typedef %s %s;\n", s, t); else { fprintf(stream, elementformat, s, ""); fprintf(stream, "\n"); } } else fprintf(stream, "//\tunrecognized\n"); } else fprintf(stream, "//\tunrecognized simpleType\n");}void Types::gen(const char *URI, const char *name, const xs__complexType& complexType, bool anonymous){ const char *t = NULL; const char *prefix = NULL; bool soapflag = false; if (complexType.name) name = complexType.name; else prefix = "_"; if (anonymous && name) t = sname(URI, name); else if (name) { t = cname(prefix, URI, name); if (deftypemap[t]) return; } if (name) scope.push_back(name); if (complexType.simpleContent) { if (!anonymous) fprintf(stream, "\n/// \"%s\":%s is a%s complexType with simpleContent.\n", URI?URI:"", name, complexType.abstract?"n abstract":""); document(complexType.annotation); if (complexType.simpleContent->restriction) { if (anonymous) { if (cflag) fprintf(stream, " struct %s\n {\n", t); else fprintf(stream, " class %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); const char *base = "xs:string"; const char *baseURI = NULL; const xs__complexType *p = &complexType; do { if (!p->simpleContent) break; if (p->simpleContent->restriction) { if (p->simpleContent->restriction->complexTypePtr()) p = p->simpleContent->restriction->complexTypePtr(); else { base = p->simpleContent->restriction->base; if (p->simpleContent->restriction->simpleTypePtr() && p->simpleContent->restriction->simpleTypePtr()->schemaPtr()) baseURI = p->simpleContent->restriction->simpleTypePtr()->schemaPtr()->targetNamespace; break; } } else if (p->simpleContent->extension) { if (p->simpleContent->extension->complexTypePtr()) p = p->simpleContent->extension->complexTypePtr(); else { base = p->simpleContent->extension->base; if (p->simpleContent->extension->simpleTypePtr() && p->simpleContent->extension->simpleTypePtr()->schemaPtr()) baseURI = p->simpleContent->extension->simpleTypePtr()->schemaPtr()->targetNamespace; break; } } else break; } while (p); fprintf(stream, "/// __item wraps '%s' simpleContent.\n", base); fprintf(stream, elementformat, tname(NULL, baseURI, base), "__item"); fprintf(stream, ";\n"); p = &complexType; bool flag = true; do { if (!p->simpleContent) break; if (p->simpleContent->restriction) { // TODO: to avoid problems should only generate attribute when name is different gen(URI, p->simpleContent->restriction->attribute); if (p->simpleContent->restriction->anyAttribute && flag) { gen(URI, *p->simpleContent->restriction->anyAttribute); flag = false; } if (p->simpleContent->restriction->complexTypePtr()) p = p->simpleContent->restriction->complexTypePtr(); else break; } else if (p->simpleContent->extension) { gen(URI, p->simpleContent->extension->attribute); gen(URI, p->simpleContent->extension->attributeGroup); if (p->simpleContent->extension->anyAttribute && flag) { gen(URI, *p->simpleContent->extension->anyAttribute); flag = false; } if (p->simpleContent->extension->complexTypePtr()) p = p->simpleContent->extension->complexTypePtr(); else break; } else break; } while (p); } else if (complexType.simpleContent->extension) { const char *base = "xs:string"; const char *baseURI = NULL; if (cflag || fflag || anonymous) { if (anonymous) { if (cflag) fprintf(stream, " struct %s\n {\n", t); else fprintf(stream, " class %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); const xs__complexType *p = &complexType; do { if (!p->simpleContent) break; if (p->simpleContent->restriction) { if (p->simpleContent->restriction->complexTypePtr()) p = p->simpleContent->restriction->complexTypePtr(); else { base = p->simpleContent->restriction->base; if (p->simpleContent->restriction->simpleTypePtr() && p->simpleContent->restriction->simpleTypePtr()->schemaPtr()) baseURI = p->simpleContent->restriction->simpleTypePtr()->schemaPtr()->targetNamespace; break; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -