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

📄 main.cxx

📁 pwlib源码库
💻 CXX
📖 第 1 页 / 共 5 页
字号:
  }  cxx << "  strm << setw(indent-1) << \"}\";\n"         "}\n"         "#endif\n"         "\n"         "\n";  if (xml_output)  {    cxx << GetTemplatePrefix()        << "BOOL " << GetClassNameString() << "::PreambleDecodeXER(PXER_Stream & strm)\n"           "{\n";    if (fields.GetSize())    {      cxx << "  PXMLElement * elem = strm.GetCurrentElement();\n"             "  PXMLElement * sub_elem;\n"             "  BOOL result;\n"             "\n";      for (i = 0; i < fields.GetSize(); i++)      {        PString id = fields[i].GetIdentifier();        cxx << "  if ((sub_elem = (PXMLElement *)elem->GetElement(\"" << id << "\")) && sub_elem->IsElement())\n"               "  {\n";        if (i >= numFields || fields[i].IsOptional())          cxx << "    IncludeOptionalField(e_" << id << ");\n";        cxx << "    strm.SetCurrentElement(sub_elem);\n"               "    result = m_" << id << ".Decode(strm);\n"               "    strm.SetCurrentElement(sub_elem);\n"               "    if (!result)\n"               "      return FALSE;\n"               "  }\n"               "\n";      }    }    cxx << "  return TRUE;\n"           "}\n"           "\n";    if (fields.GetSize())    {      cxx << GetTemplatePrefix()          << "void " << GetClassNameString() << "::PreambleEncodeXER(PXER_Stream & strm) const\n"             "{\n";      cxx << "  PXMLElement * elem = strm.GetCurrentElement();\n"             "  PXMLElement * sub_elem;\n"             "\n";      for (i = 0; i < fields.GetSize(); i++)      {        PString id = fields[i].GetIdentifier();        if (i >= numFields || fields[i].IsOptional())          cxx << "  if (HasOptionalField(e_" << id << "))\n"                 "  {\n";        cxx << "    sub_elem = elem->AddChild(new PXMLElement(elem, \"" << id << "\"));\n"               "    strm.SetCurrentElement(sub_elem);\n"               "    m_" << id << ".Encode(strm);\n";        if (i >= numFields || fields[i].IsOptional())          cxx << "  }\n";        cxx << "\n";      }      cxx << "  strm.SetCurrentElement(elem);\n"             "}\n"             "\n";    }  }  if (numFields > 0) {    cxx << GetTemplatePrefix()        << "PObject::Comparison " << GetClassNameString() << "::Compare(const PObject & obj) const\n"           "{\n"           "#ifndef PASN_LEANANDMEAN\n"           "  PAssert(PIsDescendant(this, " << GetClassNameString() << "), PInvalidCast);\n"           "#endif\n"           "  const " << GetClassNameString() << " & other = (const " << GetClassNameString() << " &)obj;\n"           "\n"           "  Comparison result;\n"           "\n";    for (i = 0; i < numFields; i++) {      PString identifier = fields[i].GetIdentifier();      cxx << "  if ((result = m_" << identifier << ".Compare(other.m_" << identifier << ")) != EqualTo)\n"             "    return result;\n";    }    cxx << "\n"           "  return PASN_Sequence::Compare(other);\n"           "}\n"           "\n"           "\n";  }  cxx << GetTemplatePrefix()      << "PINDEX " << GetClassNameString() << "::GetDataLength() const\n"         "{\n"         "  PINDEX length = 0;\n";  for (i = 0; i < numFields; i++) {    if (fields[i].IsOptional())      cxx << "  if (HasOptionalField(e_" << fields[i].GetIdentifier() << "))\n  ";    cxx << "  length += m_" << fields[i].GetIdentifier() << ".GetObjectLength();\n";  }  cxx << "  return length;\n"         "}\n"         "\n"         "\n"      << GetTemplatePrefix()      << "BOOL " << GetClassNameString() << "::Decode(PASN_Stream & strm)\n"         "{\n"         "  if (!PreambleDecode(strm))\n"         "    return FALSE;\n\n";  if (xml_output)  {    cxx << "  if (PIsDescendantStr(&strm, PXER_Stream))\n"           "    return TRUE;\n\n";  }  for (i = 0; i < numFields; i++) {    cxx << "  if (";    if (fields[i].IsOptional())      cxx << "HasOptionalField(e_" << fields[i].GetIdentifier() << ") && ";    cxx << "!m_" << fields[i].GetIdentifier() << ".Decode(strm))\n"           "    return FALSE;\n";  }  for (; i < fields.GetSize(); i++)    cxx << "  if (!KnownExtensionDecode(strm, e_"        << fields[i].GetIdentifier()        << ", m_" << fields[i].GetIdentifier() << "))\n"           "    return FALSE;\n";  cxx << "\n"         "  return UnknownExtensionsDecode(strm);\n"         "}\n"         "\n"         "\n"      << GetTemplatePrefix()      << "void " << GetClassNameString() << "::Encode(PASN_Stream & strm) const\n"         "{\n"         "  PreambleEncode(strm);\n\n";  if (xml_output)  {    cxx << "  if (PIsDescendant(&strm, \"PXER_Stream\"))\n"           "    return;\n\n";  }  for (i = 0; i < numFields; i++) {    if (fields[i].IsOptional())      cxx << "  if (HasOptionalField(e_" << fields[i].GetIdentifier() << "))\n"             "  ";    cxx << "  m_" << fields[i].GetIdentifier() << ".Encode(strm);\n";  }  for (; i < fields.GetSize(); i++)    cxx << "  KnownExtensionEncode(strm, e_"        << fields[i].GetIdentifier()        << ", m_" << fields[i].GetIdentifier() << ");\n";  cxx << "\n"         "  UnknownExtensionsEncode(strm);\n";  EndGenerateCplusplus(hdr, cxx);}const char * SequenceType::GetAncestorClass() const{  return "PASN_Sequence";}BOOL SequenceType::CanReferenceType() const{  return TRUE;}BOOL SequenceType::ReferencesType(const TypeBase & type){  for (PINDEX i = 0; i < fields.GetSize(); i++)    if (fields[i].ReferencesType(type))      return TRUE;  return FALSE;}/////////////////////////////////////////////////////////SequenceOfType::SequenceOfType(TypeBase * base, Constraint * constraint, unsigned tag)  : TypeBase(tag){  baseType = base;  if (constraint != NULL)    AddConstraint(constraint);}SequenceOfType::~SequenceOfType(){  delete baseType;}void SequenceOfType::PrintOn(ostream & strm) const{  PrintStart(strm);  if (baseType == NULL)    strm << "!!Null Type!!\n";  else    strm << *baseType << '\n';  PrintFinish(strm);}void SequenceOfType::FlattenUsedTypes(){  baseType = baseType->FlattenThisType(*this);}TypeBase * SequenceOfType::FlattenThisType(const TypeBase & parent){  if (!baseType->IsPrimitiveType() || baseType->HasConstraints())    return new DefinedType(this, parent);  // Search for an existing sequence of type  PString seqName = "ArrayOf_" + baseType->GetTypeName();  TypeBase * existingType = Module->FindType(seqName);  if (existingType != NULL)    return new DefinedType(this, existingType);  return new DefinedType(this, seqName);}BOOL SequenceOfType::IsPrimitiveType() const{  return FALSE;}void SequenceOfType::GenerateCplusplus(ostream & hdr, ostream & cxx){  BeginGenerateCplusplus(hdr, cxx);  cxx << ")\n"         "{\n";  GenerateCplusplusConstraints(PString(), hdr, cxx);  cxx << "}\n"         "\n"         "\n";  PString baseTypeName = baseType->GetTypeName();  // Generate declarations for generated functions  hdr << "    PASN_Object * CreateObject() const;\n"         "    " << baseTypeName << " & operator[](PINDEX i) const";  if (Module->UsingInlines())    hdr << " { return (" << baseTypeName << " &)array[i]; }\n";  else    hdr << ";\n";  // Generate implementation for functions  cxx << GetTemplatePrefix()      << "PASN_Object * " << GetClassNameString() << "::CreateObject() const\n"         "{\n";  if (baseType->HasConstraints()) {    cxx << "  " << baseTypeName << " * obj = new " << baseTypeName << ";\n";    baseType->GenerateCplusplusConstraints("obj->", hdr, cxx);    cxx << "  return obj;\n";  }  else    cxx << "  return new " << baseTypeName << ";\n";  if (!Module->UsingInlines())    cxx << "}\n"           "\n"           "\n"        << GetTemplatePrefix()        << baseTypeName << " & " << GetClassNameString() << "::operator[](PINDEX i) const\n"           "{\n"           "  return (" << baseTypeName << " &)array[i];\n";  EndGenerateCplusplus(hdr, cxx);}void SequenceOfType::GenerateForwardDecls(ostream & hdr){  if (baseType->IsParameterizedType())    return;  PString baseTypeName = baseType->GetTypeName();  PStringSet typesOutput(PARRAYSIZE(StandardClasses), StandardClasses);  typesOutput += GetIdentifier();  if (!typesOutput.Contains(baseTypeName))    hdr << "class " << baseTypeName << ";\n\n";}const char * SequenceOfType::GetAncestorClass() const{  return "PASN_Array";}BOOL SequenceOfType::CanReferenceType() const{  return TRUE;}BOOL SequenceOfType::ReferencesType(const TypeBase & type){  return baseType->ReferencesType(type) && baseType->IsParameterizedType();}/////////////////////////////////////////////////////////SetType::SetType()  : SequenceType(NULL, FALSE, NULL, Tag::UniversalSet){}SetType::SetType(SequenceType * seq)  : SequenceType(*seq){  tag.number = Tag::UniversalSet;}const char * SetType::GetAncestorClass() const{  return "PASN_Set";}/////////////////////////////////////////////////////////SetOfType::SetOfType(TypeBase * base, Constraint * constraint)  : SequenceOfType(base, constraint, Tag::UniversalSet){}/////////////////////////////////////////////////////////ChoiceType::ChoiceType(TypesList * stnd,                       BOOL extendable,                       TypesList * extensions)  : SequenceType(stnd, extendable, extensions, Tag::IllegalUniversalTag){}void ChoiceType::GenerateCplusplus(ostream & hdr, ostream & cxx){  PINDEX i;  BeginGenerateCplusplus(hdr, cxx);  // Complete the ancestor constructor parameters  cxx << ", " << numFields << ", " << (extendable ? "TRUE" : "FALSE");  // Generate the enum's for each choice discriminator, and include strings for  // PrintOn() debug output into acncestor constructor  BOOL outputEnum = FALSE;  int prevNum = -1;  for (i = 0; i < fields.GetSize(); i++) {    const Tag & fieldTag = fields[i].GetTag();    if (fieldTag.mode == Tag::Automatic || !fields[i].IsChoice()) {      if (outputEnum) {        hdr << ",\n";        cxx << "        \"";      }      else {        hdr << "    enum Choices {\n";        cxx << "\n"               "#ifndef PASN_NOPRINTON\n"               "      , \"";        outputEnum = TRUE;      }      hdr << "      e_" << fields[i].GetIdentifier();      cxx << fields[i].GetIdentifier();      if (fieldTag.mode != Tag::Automatic && fieldTag.number != (unsigned)(prevNum+1)) {        hdr << " = " << fieldTag.number;        cxx << '=' << fieldTag.number;      }      prevNum = fieldTag.number;      cxx << " \"\n";    }  }  if (outputEnum) {    hdr << "\n"           "    };\n"           "\n";    cxx << "#endif\n"           "    ";  }  cxx << ")\n"         "{\n";  GenerateCplusplusConstraints(PString(), hdr, cxx);  cxx << "}\n"         "\n"         "\n";  // Generate code for type safe cast operators of selected choice object  BOOL needExtraLine = FALSE;  if (Module->UsingOperators()) {    PStringSet typesOutput(PARRAYSIZE(StandardClasses), StandardClasses);    typesOutput += GetIdentifier();    for (i = 0; i < fields.GetSize(); i++) {      PString type = fields[i].GetTypeName();      if (!typesOutput.Contains(type)) {        if (Module->UsingInlines()) {          hdr << "#if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9\n"                 "    operator " << type << " &() const { return *(" << type << " *)choice; }\n"                 "#else\n"                 "    operator " << type << " &() { return *(" << type << " *)choice; }\n"                 "    operator const " << type << " &() const { return *(const " << type << " *)choice; }\n"                 "#endif\n";        }        else {          hdr << "#if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9\n"                 "    operator " << type << " &() const;\n"                 "#else\n"                 "    operator " << type << " &();\n"                 "    operator const " << type << " &() const;\n"                 "#endif\n";          cxx << "#if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9\n"              << GetTemplatePrefix()              << GetClassNameString() << "::operator " << type << " &() const\n"                 "#else\n"              << GetTemplatePrefix()              << GetClassNameString() << "::operator " << type << " &()\n"                 "{\n"                 "#ifndef PASN_LEANANDMEAN\n"                 "  PAssert(PIsDescendant(PAssertNULL(choice), " << type << "), PInvalidCast);\n"                 "#endif\n"                 "  return *(" << type << " *)choice;\n"                 "}\n"                 "\n"                 "\n"              << GetTemplatePrefix()              << GetClassNameString() << "::operator const " << type << " &() const\n"                 "#endif\n"                 "{\n"                 "#ifndef PASN_LEANANDMEAN\n"                 "  PAssert(PIsDescendant(PAssertNULL(choice), " << type << "), PInvalidCast);\n"                 "#endif\n"                 "  return *(" << type << " *)choice;\n"                 "}\n"                 "\n"                 "\n";        }        typesOutput += type;        needExtraLine = TRUE;      }    }  }  else {    for (i = 0; i < fields.GetSize(); i++) {      PString type = fields[i].GetTypeName();      PString fieldName = fields[i].GetIdentifier();      if (Module->UsingInlines()) {        hdr << "    "       << type << " & m_" << fieldName << "() { return *(" << type << " *)choice; }\n"               "    const " << type << " & m_" << fieldName << "() const { return *(const " << type << " *)choice; }\n";      }      else {        hdr << "    "       << type << " & m_" << fieldName << "();\n"               "    const " << type << " & m_" << fieldName << "() const;\n";        cxx << GetTemplatePrefix() << type << " & "            << GetClassNameString() << "::m_" << fieldName << "()\n"               "{\n"               "#ifndef PASN_LEANANDMEAN\n"               "  PAssert(PIsDescendant(PAssertNULL(choice), " << type << "), PInvalidCast);\n"               "#endif\n"               "  return *(" << type << " *)choice;\n"               "}\n"               "\n"               "\n"            << GetTemplatePrefix() << type << " const & "            << GetClassNameString() << "::m_" << fieldName << "() const\n"               "{\n"               "#ifndef PASN_LEANANDMEAN\n"               "  PAssert(PIsDescendant(PAssertNULL(choice), " << type << "), PInvalidCast);\n"               "#endif\n"               "  return *(" << type << " *)choice;\n"               "}\n"               "\n"               "\n";      }    }    needExtraLine = TRUE;  }  if (needExtraLine)    hdr << '\n';  // Generate virtual function to create chosen object based on discriminator  hdr << "    BOOL CreateObject();\n";  cxx << GetTemplatePrefix()      << "BOOL " << GetClassNameString() << "::CreateObject()\n"         "{\n";  // special case: if choice is all NULLs then simply output code  BOOL allNull = TRUE;  for (i = 0; allNull && i < fields.GetSize(); i++)     allNull = a

⌨️ 快捷键说明

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