📄 main.cxx
字号:
{}void BooleanType::GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType){ hdr << " " << actualType.GetIdentifier() << " & operator=(BOOL v)"; if (Module->UsingInlines()) hdr << " { SetValue(v); return *this; }\n"; else { hdr << ";\n"; cxx << actualType.GetTemplatePrefix() << actualType.GetIdentifier() << " & " << actualType.GetClassNameString() << "::operator=(BOOL v)\n" "{\n" " SetValue(v);\n" " return *this;\n" "}\n" "\n" "\n"; }}const char * BooleanType::GetAncestorClass() const{ return "PASN_Boolean";}/////////////////////////////////////////////////////////IntegerType::IntegerType() : TypeBase(Tag::UniversalInteger){}IntegerType::IntegerType(NamedNumberList * lst) : TypeBase(Tag::UniversalInteger), allowedValues(*lst){ delete lst;}void IntegerType::GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType){ hdr << " " << actualType.GetIdentifier() << " & operator=(int v)"; if (Module->UsingInlines()) hdr << " { SetValue(v); return *this; }\n"; else { hdr << ";\n"; cxx << actualType.GetTemplatePrefix() << actualType.GetIdentifier() << " & " << actualType.GetClassNameString() << "::operator=(int v)\n" "{\n" " SetValue(v);\n" " return *this;\n" "}\n" "\n" "\n"; } hdr << " " << actualType.GetIdentifier() << " & operator=(unsigned v)"; if (Module->UsingInlines()) hdr << " { SetValue(v); return *this; }\n"; else { hdr << ";\n"; cxx << actualType.GetTemplatePrefix() << actualType.GetIdentifier() << " & " << actualType.GetClassNameString() << "::operator=(unsigned v)\n" "{\n" " SetValue(v);\n" " return *this;\n" "}\n" "\n" "\n"; }}const char * IntegerType::GetAncestorClass() const{ return "PASN_Integer";}/////////////////////////////////////////////////////////EnumeratedType::EnumeratedType(NamedNumberList * enums, BOOL extend, NamedNumberList * ext) : TypeBase(Tag::UniversalEnumeration), enumerations(*enums){ numEnums = enums->GetSize(); delete enums; extendable = extend; if (ext != NULL) { ext->DisallowDeleteObjects(); for (PINDEX i = 0; i < ext->GetSize(); i++) enumerations.Append(ext->GetAt(i)); delete ext; }}void EnumeratedType::PrintOn(ostream & strm) const{ PrintStart(strm); strm << '\n'; PINDEX i; for (i = 0; i < numEnums; i++) strm << indent() << enumerations[i] << '\n'; if (extendable) { strm << "...\n"; for (; i < enumerations.GetSize(); i++) strm << indent() << enumerations[i] << '\n'; } PrintFinish(strm);}TypeBase * EnumeratedType::FlattenThisType(const TypeBase & parent){ return new DefinedType(this, parent);}void EnumeratedType::GenerateCplusplus(ostream & hdr, ostream & cxx){ PINDEX i; PArgList & args = PProcess::Current().GetArguments(); BOOL xml_output = args.HasOption('x'); BeginGenerateCplusplus(hdr, cxx); int maxEnumValue = 0; for (i = 0; i < enumerations.GetSize(); i++) { int num = enumerations[i].GetNumber(); if (maxEnumValue < num) maxEnumValue = num; } // Generate enumerations and complete the constructor implementation hdr << " enum Enumerations {\n"; cxx << ", " << maxEnumValue << ", " << (extendable ? "TRUE" : "FALSE") << "\n" "#ifndef PASN_NOPRINTON\n" " , \""; int prevNum = -1; for (i = 0; i < enumerations.GetSize(); i++) { if (i > 0) { hdr << ",\n"; cxx << " \""; } hdr << " e_" << MakeIdentifierC(enumerations[i].GetName()); cxx << enumerations[i].GetName(); int num = enumerations[i].GetNumber(); if (num != prevNum+1) { hdr << " = " << num; cxx << '=' << num; } prevNum = num; cxx << " \"\n"; } hdr << "\n" " };\n" "\n"; cxx << "#endif\n" " )\n" "{\n"; GenerateCplusplusConstraints(PString(), hdr, cxx); if (xml_output) { hdr << " BOOL DecodeXER(PXER_Stream & strm);\n" " void EncodeXER(PXER_Stream & strm) const;\n"; cxx << "}\n" "\n" << GetTemplatePrefix() << "BOOL " << GetClassNameString() << "::DecodeXER(PXER_Stream & strm)\n" "{\n" " PXMLElement * elem = strm.GetCurrentElement();\n" " PXMLObject * sub_elem = elem->GetElement();\n" "\n" " if (!elem || !elem->IsElement())\n" " return FALSE;\n" "\n" " PCaselessString id = ((PXMLElement *)sub_elem)->GetName();\n" "\n" " "; for (i = 0 ; i < enumerations.GetSize() ; i++) { cxx << " if (id == \"" << enumerations[i].GetName() << "\") {\n" " value = " << enumerations[i].GetNumber() << ";\n" " return TRUE;\n" " }\n" " else"; } cxx << "\n" " return FALSE;\n" "}\n" "\n"; cxx << GetTemplatePrefix() << "void " << GetClassNameString() << "::EncodeXER(PXER_Stream & strm) const\n" "{\n" " PXMLElement * elem = strm.GetCurrentElement();\n" " PString id;\n" "\n" " switch(value)\n" " {\n"; for (i = 0 ; i < enumerations.GetSize() ; i++) { cxx << " case " << enumerations[i].GetNumber() << ":\n" " elem->AddChild(new PXMLElement(elem, \"" << enumerations[i].GetName() << "\"));\n" " break;\n"; } cxx << " default:\n" " break;\n" " }\n"; } EndGenerateCplusplus(hdr, cxx);}void EnumeratedType::GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType){ hdr << " " << actualType.GetIdentifier() << " & operator=(unsigned v)"; if (Module->UsingInlines()) hdr << " { SetValue(v); return *this; }\n"; else { hdr << ";\n"; cxx << actualType.GetTemplatePrefix() << actualType.GetIdentifier() << " & " << actualType.GetClassNameString() << "::operator=(unsigned v)\n" "{\n" " SetValue(v);\n" " return *this;\n" "}\n" "\n" "\n"; }}const char * EnumeratedType::GetAncestorClass() const{ return "PASN_Enumeration";}/////////////////////////////////////////////////////////RealType::RealType() : TypeBase(Tag::UniversalReal){}const char * RealType::GetAncestorClass() const{ return "PASN_Real";}/////////////////////////////////////////////////////////BitStringType::BitStringType() : TypeBase(Tag::UniversalBitString){}BitStringType::BitStringType(NamedNumberList * lst) : TypeBase(Tag::UniversalBitString), allowedBits(*lst){ delete lst;}int BitStringType::GetIdentifierTokenContext() const{ return OID_IDENTIFIER;}int BitStringType::GetBraceTokenContext() const{ return BITSTRING_BRACE;}const char * BitStringType::GetAncestorClass() const{ return "PASN_BitString";}/////////////////////////////////////////////////////////OctetStringType::OctetStringType() : TypeBase(Tag::UniversalOctetString){}void OctetStringType::GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType){ static const char * const types[] = { "char *", "PString &", "PBYTEArray &" }; PINDEX i; for (i = 0; i < PARRAYSIZE(types); i++) { hdr << " " << actualType.GetIdentifier() << "(const " << types[i] << " v)"; if (Module->UsingInlines()) hdr << " { SetValue(v); }\n"; else { hdr << ";\n"; cxx << actualType.GetTemplatePrefix() << actualType.GetIdentifier() << "::" << actualType.GetIdentifier() << "(const " << types[i] << " v)\n" "{\n" " SetValue(v);\n" "}\n" "\n" "\n"; } } hdr << '\n'; for (i = 0; i < PARRAYSIZE(types); i++) { hdr << " " << actualType.GetIdentifier() << " & operator=(const " << types[i] << " v)"; if (Module->UsingInlines()) hdr << " { SetValue(v); return *this; }\n"; else { hdr << ";\n"; cxx << actualType.GetTemplatePrefix() << actualType.GetIdentifier() << " & " << actualType.GetClassNameString() << "::operator=(const " << types[i] << " v)\n" "{\n" " SetValue(v);\n" " return *this;\n" "}\n" "\n" "\n"; } }}const char * OctetStringType::GetAncestorClass() const{ return "PASN_OctetString";}/////////////////////////////////////////////////////////NullType::NullType() : TypeBase(Tag::UniversalNull){}const char * NullType::GetAncestorClass() const{ return "PASN_Null";}/////////////////////////////////////////////////////////SequenceType::SequenceType(TypesList * stnd, BOOL extend, TypesList * ext, unsigned tagNum) : TypeBase(tagNum){ if (stnd != NULL) { numFields = stnd->GetSize(); fields = *stnd; delete stnd; } else numFields = 0; extendable = extend; if (ext != NULL) { ext->DisallowDeleteObjects(); for (PINDEX i = 0; i < ext->GetSize(); i++) fields.Append(ext->GetAt(i)); delete ext; }}void SequenceType::PrintOn(ostream & strm) const{ PrintStart(strm); strm << '\n'; PINDEX i; for (i = 0; i < numFields; i++) strm << fields[i]; if (extendable) { strm << indent() << "...\n"; for (; i < fields.GetSize(); i++) strm << fields[i]; } PrintFinish(strm);}void SequenceType::FlattenUsedTypes(){ for (PINDEX i = 0; i < fields.GetSize(); i++) fields.SetAt(i, fields[i].FlattenThisType(*this));}TypeBase * SequenceType::FlattenThisType(const TypeBase & parent){ return new DefinedType(this, parent);}BOOL SequenceType::IsPrimitiveType() const{ return FALSE;}void SequenceType::GenerateCplusplus(ostream & hdr, ostream & cxx){ PArgList & args = PProcess::Current().GetArguments(); BOOL xml_output = args.HasOption('x'); PINDEX i; BeginGenerateCplusplus(hdr, cxx); PINDEX baseOptions = 0; for (i = 0; i < fields.GetSize(); i++) { if (i < numFields && fields[i].IsOptional()) baseOptions++; } // Complete ancestor constructor parameters cxx << ", " << baseOptions << ", " << (extendable ? "TRUE" : "FALSE") << ", " << fields.GetSize() - numFields << ')'; // Output enum for optional parameters BOOL outputEnum = FALSE; for (i = 0; i < fields.GetSize(); i++) { if (i >= numFields || fields[i].IsOptional()) { if (outputEnum) hdr << ",\n"; else { hdr << " enum OptionalFields {\n"; outputEnum = TRUE; } hdr << " e_" << fields[i].GetIdentifier(); } } if (outputEnum) hdr << "\n" " };\n" "\n"; // Output the declarations and constructors for member variables for (i = 0; i < fields.GetSize(); i++) { PString varname = "m_" + fields[i].GetIdentifier(); hdr << " " << fields[i].GetTypeName() << ' ' << varname << ";\n"; if (fields[i].HasNonStandardTag()) { cxx << ",\n" " " << varname; fields[i].GenerateCplusplusConstructor(hdr, cxx); } } // Output declarations for generated functions hdr << "\n" " PINDEX GetDataLength() const;\n" " BOOL Decode(PASN_Stream & strm);\n" " void Encode(PASN_Stream & strm) const;\n" "#ifndef PASN_NOPRINTON\n" " void PrintOn(ostream & strm) const;\n" "#endif\n"; if (xml_output) { hdr << " BOOL PreambleDecodeXER(PXER_Stream & strm);\n"; if (fields.GetSize()) hdr << " void PreambleEncodeXER(PXER_Stream &) const;\n"; } if (numFields > 0) hdr << " Comparison Compare(const PObject & obj) const;\n"; cxx << "\n" "{\n"; GenerateCplusplusConstraints(PString(), hdr, cxx); for (i = 0; i < fields.GetSize(); i++) { PString ident = fields[i].GetIdentifier(); fields[i].GenerateCplusplusConstraints("m_" + ident + ".", hdr, cxx); if (i >= numFields && !fields[i].IsOptional()) cxx << " IncludeOptionalField(e_" << ident << ");\n"; } cxx << "}\n" "\n" "\n" "#ifndef PASN_NOPRINTON\n" << GetTemplatePrefix() << "void " << GetClassNameString() << "::PrintOn(ostream & strm) const\n" "{\n" " int indent = strm.precision() + 2;\n" " strm << \"{\\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" " "; cxx << " strm << setw(indent+" << id.GetLength()+3 << ") << \"" << id << " = \" << setprecision(indent) << m_" << id << " << '\\n';\n";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -