⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 types.cpp

📁 一款开源的soap库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
      strcat(t, "-");    }    strcat(t, name);    s = fname("_", URI, t, &rnames, NOLOOKUP);    rnames.insert(s);  }  else if (URI)  { s = nsprefix(NULL, URI);	/* TODO: this may be affected? */    t = (char*)emalloc(strlen(s) + 16);    sprintf(t, "_%s__struct_%d", s, snum++);    s = t;  }  else  { t = (char*)emalloc(16);    sprintf(t, "struct_%d", snum++);    s = t;  }  return s;}// generate union nameconst char *Types::uname(const char *URI){ const char *s;  char *t;  if (!aflag)  { size_t len = 0;    for (VectorOfString::const_iterator i = scope.begin(); i != scope.end(); ++i)      len += strlen(*i) + 1;    t = (char*)emalloc(len + 6);    strcpy(t, "union");    for (VectorOfString::const_iterator j = scope.begin(); j != scope.end(); ++j)    { strcat(t, "-");      strcat(t, *j);    }    s = fname("_", URI, t, &rnames, NOLOOKUP);    rnames.insert(s);  }  else if (URI)  { s = nsprefix(NULL, URI);	/* TODO: this may be affected? */    t = (char*)emalloc(strlen(s) + 16);    sprintf(t, "_%s__union_%d", s, unum++);    s = t;  }  else  { t = (char*)emalloc(16);    sprintf(t, "_union_%d", unum++);    s = t;  }  return s;}// generate enum nameconst char *Types::gname(const char *URI, const char *name){ const char *s;  char *t;  if (!aflag && name)  { size_t len = 0;    for (VectorOfString::const_iterator i = scope.begin(); i != scope.end(); ++i)      len += strlen(*i) + 1;    t = (char*)emalloc(len + strlen(name) + 1);    *t = '\0';    for (VectorOfString::const_iterator j = scope.begin(); j != scope.end(); ++j)    { strcat(t, *j);      strcat(t, "-");    }    strcat(t, name);    s = fname("_", URI, t, &rnames, NOLOOKUP);    rnames.insert(s);  }  else if (URI)  { s = nsprefix(NULL, URI);	/* TODO: this may be affected? */    t = (char*)emalloc(strlen(s) + 16);    sprintf(t, "_%s__enum_%d", s, gnum++);    s = t;  }  else  { t = (char*)emalloc(16);    sprintf(t, "enum_%d", gnum++);    s = t;  }  return s;}// check if nillable or minOccurs=0 (and no default value is present)bool Types::is_nillable(const xs__element& element){ return !element.default_ && (element.nillable || (element.minOccurs && !strcmp(element.minOccurs, "0")));}bool Types::is_basetype(const char *type){ const char *t = tname(NULL, NULL, type);  if (!strcmp(t, "std::string")   || strstr(t, "__"))    return false;  return !strncmp(type, "xs:", 3) || !strncmp(type, "SOAP-ENC:", 9);}void Types::dump(FILE *fd){  fprintf(fd, "\nTypes:\n");  for (MapOfStringToString::const_iterator i = usetypemap.begin(); i != usetypemap.end(); ++i)    fprintf(fd, "%s=%s\n", (*i).first, (*i).second?(*i).second:"(null)");  fprintf(fd, "\nPointers:\n");  for (MapOfStringToString::const_iterator j = ptrtypemap.begin(); j != ptrtypemap.end(); ++j)    fprintf(fd, "%s=%s\n", (*j).first, (*j).second?(*j).second:"(null)");}void Types::define(const char *URI, const char *name, const xs__complexType& complexType){ // generate prototype for structs/classes and store name  const char *prefix = NULL;  if (complexType.name)    name = complexType.name;  else    prefix = "_";  if (complexType.complexContent && complexType.complexContent->restriction && !strcmp(complexType.complexContent->restriction->base, "SOAP-ENC:Array"))  { if (strcmp(schema_prefix, "ns"))      prefix = "*";    else      prefix = "";  }  if (cflag)  { const char *t = deftname(STRUCT, "*", true, prefix, URI, name);    if (t)    { if (yflag)        fprintf(stream, "\n/// Typedef synonym for struct %s.\ntypedef struct %s %s;\n", t, t, t);    }    else if (name)    { t = deftypemap[cname(prefix, URI, name)];      if (t)      { fprintf(stream, "\n/// Imported complexType \"%s\":%s from typemap %s.\n", URI, name, mapfile?mapfile:"");        document(complexType.annotation);        if (*t)	  format(t);        else	  fprintf(stream, "// complexType definition intentionally left blank.\n");      }    }  }  else   { const char *t = deftname(CLASS, "*", true, prefix, URI, name);    if (t)      fprintf(stream, "\n//  Forward declaration of class %s.\nclass %s;\n", t, t);    else if (name)    { t = deftypemap[cname(prefix, URI, name)];      if (t)      { fprintf(stream, "\n/// Imported complexType \"%s\":%s from typemap %s.\n", URI, name, mapfile?mapfile:"");        document(complexType.annotation);        if (*t)	  format(t);        else	  fprintf(stream, "// complexType definition intentionally left blank.\n");      }    }  }}void Types::gen(const char *URI, const char *name, const xs__simpleType& simpleType, bool anonymous){ const char *t = NULL;  const char *prefix = NULL;  if (simpleType.name)    name = simpleType.name;  else    prefix = "_";  if (!anonymous)  { t = deftypemap[cname(NULL, URI, name)];    if (t)    { fprintf(stream, "\n/// Imported simpleType \"%s\":%s from typemap %s.\n", URI, name, mapfile?mapfile:"");      document(simpleType.annotation);      if (*t)	format(t);      else	fprintf(stream, "// simpleType definition intentionally left blank.\n");      return;    }  }  if (simpleType.restriction && simpleType.restriction->base)  { if (!anonymous)      fprintf(stream, "\n/// \"%s\":%s is a simpleType restriction of %s.\n", URI?URI:"", name, simpleType.restriction->base);    document(simpleType.annotation);    document(simpleType.restriction->annotation);    if (!simpleType.restriction->enumeration.empty())    { bool is_numeric = true; // check if all enumeration values are numeric      bool is_qname = !strcmp(simpleType.restriction->base, "xs:QName");      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);      }      if (!t)        t = gname(URI, name);      if (!anonymous)        fprintf(stream, "enum %s\n{\n", t);      else        fprintf(stream, "    enum %s\n    {\n", t);      for (vector<xs__enumeration>::const_iterator enumeration1 = simpleType.restriction->enumeration.begin(); enumeration1 != simpleType.restriction->enumeration.end(); ++enumeration1)      { const char *s;        if ((s = (*enumeration1).value))	  is_numeric &= is_integer(s);      }      SetOfString enumvals;      for (vector<xs__enumeration>::const_iterator enumeration2 = simpleType.restriction->enumeration.begin(); enumeration2 != simpleType.restriction->enumeration.end(); ++enumeration2)      { const char *s;        document((*enumeration2).annotation);        if ((s = (*enumeration2).value))	{ if (!enumvals.count(s))	  { enumvals.insert(s);	    if (is_numeric)              fprintf(stream, "\t%s = %s,\t///< %s value=\"%s\"\n", ename(t, s), s, simpleType.restriction->base, s);            else if (is_qname && (*enumeration2).value_)              fprintf(stream, "\t%s,\t///< %s value=\"%s\"\n", ename(t, (*enumeration2).value_), simpleType.restriction->base, (*enumeration2).value_);            else              fprintf(stream, "\t%s,\t///< %s value=\"%s\"\n", ename(t, s), simpleType.restriction->base, s);	  }	}        else          fprintf(stream, "//\tunrecognized: enumeration '%s' has no value\n", name?name:"");      }      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.restriction->length && simpleType.restriction->length->value)        fprintf(stream, "/// Length of this string is exactly %s characters\n", simpleType.restriction->length->value);      else      { const char *a = NULL, *b = NULL;        if (simpleType.restriction->minLength)          a = simpleType.restriction->minLength->value;        if (simpleType.restriction->maxLength)          b = simpleType.restriction->maxLength->value;        if (a || b)          fprintf(stream, "/// Length of this string is within %s..%s characters\n", a?a:"0", b?b:"");      }      if (simpleType.restriction->precision && simpleType.restriction->precision->value)        fprintf(stream, "/// %sprecision is %s\n", simpleType.restriction->precision->fixed?"fixed ":"", simpleType.restriction->precision->value);      if (simpleType.restriction->scale && simpleType.restriction->scale->value)        fprintf(stream, "/// %sscale is %s\n", simpleType.restriction->scale->fixed?"fixed ":"", simpleType.restriction->scale->value);      if (simpleType.restriction->totalDigits && simpleType.restriction->totalDigits->value)        fprintf(stream, "/// %snumber of total digits is %s\n", simpleType.restriction->totalDigits->fixed?"fixed ":"", simpleType.restriction->totalDigits->value);      if (simpleType.restriction->fractionDigits && simpleType.restriction->fractionDigits->value)        fprintf(stream, "/// %snumber of fraction digits is %s\n", simpleType.restriction->fractionDigits->fixed?"fixed ":"", simpleType.restriction->fractionDigits->value);      for (vector<xs__pattern>::const_iterator pattern1 = simpleType.restriction->pattern.begin(); pattern1 != simpleType.restriction->pattern.end(); ++pattern1)        fprintf(stream, "/// Content pattern is \"%s\"\n", xstring((*pattern1).value));      const char *ai = NULL, *ae = NULL, *bi = NULL, *be = NULL;      if (simpleType.restriction->minInclusive)        ai = simpleType.restriction->minInclusive->value;      else if (simpleType.restriction->minExclusive)        ae = simpleType.restriction->minExclusive->value;      if (simpleType.restriction->maxInclusive)        bi = simpleType.restriction->maxInclusive->value;      else if (simpleType.restriction->maxExclusive)        be = simpleType.restriction->maxExclusive->value;      if (ai || ae || bi || be)      { fprintf(stream, "/// Value range is ");        if (ai)	  fprintf(stream, "[%s..", ai);        else if (ae)	  fprintf(stream, "(%s..", ae);        else	  fprintf(stream, "[..");        if (bi)	  fprintf(stream, "%s]\n", bi);        else if (be)	  fprintf(stream, "%s)\n", be);        else	  fprintf(stream, "]\n");      }      if (!simpleType.restriction->attribute.empty())      { fprintf(stderr, "\nWarning: simpleType '%s' should not have attributes\n", name?name:"");      }      const char *s = tname(NULL, NULL, simpleType.restriction->base);      if (!anonymous)      { bool is_ptr = false;	is_ptr = (strchr(s, '*') != NULL) || (s == pname(true, NULL, NULL, simpleType.restriction->base));        t = deftname(TYPEDEF, NULL, is_ptr, prefix, URI, name);        if (t)	  fprintf(stream, "typedef %s %s", s, t);      }      else      { t = "";        fprintf(stream, elementformat, s, "");        fprintf(stream, "\n");      }      if (t)      { 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)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -