📄 dtdparser.cpp
字号:
} if (uniseq) { CUniSequenceDataType* uniType = new CUniSequenceDataType(type); uniType->SetNonEmpty( occ == DTDElement::eOneOrMore); uniType->SetNoPrefix(true); type = uniType; } return type;}CDataType* DTDParser::TypesBlock( CDataMemberContainerType* containerType,const DTDElement& node, bool ignoreAttrib){ AutoPtr<CDataMemberContainerType> container(containerType); if (!ignoreAttrib) { AddAttributes(container, node); } const list<string>& refs = node.GetContent(); for (list<string>::const_iterator i= refs.begin(); i != refs.end(); ++i) { DTDElement& refNode = m_MapElement[*i]; if (refNode.GetName().empty()) { ParseError(i->c_str(),"definition"); } DTDElement::EOccurrence occ = node.GetOccurrence(*i); if (refNode.IsEmbedded()) { occ = refNode.GetOccurrence(); } AutoPtr<CDataType> type(Type(refNode, occ, true)); AutoPtr<CDataMember> member(new CDataMember(refNode.GetName(), type)); if ((occ == DTDElement::eZeroOrOne) || (occ == DTDElement::eZeroOrMore)) { member->SetOptional(); } if (refNode.IsEmbedded()) { member->SetNotag(); } member->SetNoPrefix(); container->AddMember(member); } return container.release();}CDataType* DTDParser::CompositeNode( const DTDElement& node, DTDElement::EOccurrence occ){ AutoPtr<CDataMemberContainerType> container(new CDataSequenceType()); AddAttributes(container, node); bool uniseq = (occ == DTDElement::eOneOrMore || occ == DTDElement::eZeroOrMore); AutoPtr<CDataType> type(Type(node, DTDElement::eOne, false, true)); AutoPtr<CDataMember> member(new CDataMember(node.GetName(), uniseq ? (AutoPtr<CDataType>(new CUniSequenceDataType(type))) : type)); member->SetNoPrefix(); member->SetNotag(); if (!uniseq) { member->SetSimpleType(); } container->AddMember(member); return container.release();}void DTDParser::AddAttributes( AutoPtr<CDataMemberContainerType>& container, const DTDElement& node){ if (node.HasAttributes()) { AutoPtr<CDataMember> member( new CDataMember("Attlist", AttribBlock(node))); member->SetNoPrefix(); member->SetAttlist(); container->AddMember(member); }}CDataType* DTDParser::AttribBlock(const DTDElement& node){ AutoPtr<CDataMemberContainerType> container(new CDataSequenceType()); const list<DTDAttribute>& att = node.GetAttributes(); for (list<DTDAttribute>::const_iterator i= att.begin(); i != att.end(); ++i) { AutoPtr<CDataType> type(x_AttribType(*i)); AutoPtr<CDataMember> member(new CDataMember(i->GetName(), type)); string defValue( i->GetValue()); if (!defValue.empty()) { member->SetDefault(new CIdDataValue(defValue)); } if (i->GetValueType() == DTDAttribute::eImplied) { member->SetOptional(); } member->SetNoPrefix(); container->AddMember(member); } return container.release();}CDataType* DTDParser::x_AttribType(const DTDAttribute& att){ CDataType* type=0; switch (att.GetType()) { case DTDAttribute::eUnknown: ParseError("Unknown attribute", "attribute"); _ASSERT(0); break; case DTDAttribute::eId: case DTDAttribute::eIdRef: case DTDAttribute::eIdRefs: case DTDAttribute::eNmtoken: case DTDAttribute::eNmtokens: case DTDAttribute::eEntity: case DTDAttribute::eEntities: case DTDAttribute::eNotation: case DTDAttribute::eString: type = new CStringDataType(); break; case DTDAttribute::eEnum: type = EnumeratedBlock(att, new CEnumDataType()); break; } return type;}CDataType* DTDParser::EnumeratedBlock(const DTDAttribute& att, CEnumDataType* enumType){ int v=1; const list<string>& attEnums = att.GetEnumValues(); for (list<string>::const_iterator i = attEnums.begin(); i != attEnums.end(); ++i, ++v) { enumType->AddValue( *i, v); } return enumType;}/////////////////////////////////////////////////////////////////////////////// debug printing#if defined(NCBI_DTDPARSER_TRACE)void DTDParser::PrintDocumentTree(void){ PrintEntities(); cout << " === Elements ===" << endl; map<string,DTDElement>::iterator i; for (i = m_MapElement.begin(); i != m_MapElement.end(); ++i) { DTDElement& node = i->second; DTDElement::EType type = node.GetType(); if (((type == DTDElement::eSequence) || (type == DTDElement::eChoice) || node.HasAttributes()) && !node.IsEmbedded()) { PrintDocumentNode(i->first,i->second); } } bool started = false; for (i = m_MapElement.begin(); i != m_MapElement.end(); ++i) { DTDElement& node = i->second; if (node.IsEmbedded()) { if (!started) { cout << " === Embedded elements ===" << endl; started = true; } PrintDocumentNode(i->first,i->second); } } started = false; for (i = m_MapElement.begin(); i != m_MapElement.end(); ++i) { DTDElement& node = i->second; DTDElement::EType type = node.GetType(); if (((type != DTDElement::eSequence) && (type != DTDElement::eChoice)) && !node.IsReferenced()) { if (!started) { cout << " === UNREFERENCED elements ===" << endl; started = true; } PrintDocumentNode(i->first,i->second); } } cout << endl;}void DTDParser::PrintEntities(void){ if (!m_MapEntity.empty()) { cout << " === Entities ===" << endl; map<string,DTDEntity>::iterator i; for (i = m_MapEntity.begin(); i != m_MapEntity.end(); ++i) { cout << i->second.GetName() << " = \"" << i->second.GetData() << "\"" << endl; } cout << endl; }}void DTDParser::PrintDocumentNode(const string& name, const DTDElement& node){ cout << name << ": "; switch (node.GetType()) { default: case DTDElement::eUnknown: cout << "unknown"; break; case DTDElement::eString: cout << "string"; break; case DTDElement::eAny: cout << "any"; break; case DTDElement::eEmpty: cout << "empty"; break; case DTDElement::eSequence: cout << "sequence";break; case DTDElement::eChoice: cout << "choice"; break; } switch (node.GetOccurrence()) { default: case DTDElement::eOne: cout << "(1)"; break; case DTDElement::eOneOrMore: cout << "(1..*)"; break; case DTDElement::eZeroOrMore: cout << "(0..*)"; break; case DTDElement::eZeroOrOne: cout << "(0..1)"; break; } cout << endl; if (node.HasAttributes()) { PrintNodeAttributes(node); } const list<string>& refs = node.GetContent(); if (!refs.empty()) { cout << " === Contents ===" << endl; for (list<string>::const_iterator ir= refs.begin(); ir != refs.end(); ++ir) { cout << " " << *ir; switch (node.GetOccurrence(*ir)) { default: case DTDElement::eOne: cout << "(1)"; break; case DTDElement::eOneOrMore: cout << "(1..*)"; break; case DTDElement::eZeroOrMore: cout << "(0..*)"; break; case DTDElement::eZeroOrOne: cout << "(0..1)"; break; } cout << endl; } } cout << endl;}void DTDParser::PrintNodeAttributes(const DTDElement& node){ const list<DTDAttribute>& att = node.GetAttributes(); cout << " === Attributes ===" << endl; for (list<DTDAttribute>::const_iterator i= att.begin(); i != att.end(); ++i) { cout << " "; cout << i->GetName(); cout << ": "; switch (i->GetType()) { case DTDAttribute::eUnknown: cout << "eUnknown"; break; case DTDAttribute::eString: cout << "eString"; break; case DTDAttribute::eEnum: cout << "eEnum"; break; case DTDAttribute::eId: cout << "eId"; break; case DTDAttribute::eIdRef: cout << "eIdRef"; break; case DTDAttribute::eIdRefs: cout << "eIdRefs"; break; case DTDAttribute::eNmtoken: cout << "eNmtoken"; break; case DTDAttribute::eNmtokens: cout << "eNmtokens"; break; case DTDAttribute::eEntity: cout << "eEntity"; break; case DTDAttribute::eEntities: cout << "eEntities"; break; case DTDAttribute::eNotation: cout << "eNotation"; break; } { const list<string>& enumV = i->GetEnumValues(); if (!enumV.empty()) { cout << " ("; for (list<string>::const_iterator ie= enumV.begin(); ie != enumV.end(); ++ie) { if (ie != enumV.begin()) { cout << ","; } cout << *ie; } cout << ")"; } } cout << ", "; switch (i->GetValueType()) { case DTDAttribute::eDefault: cout << "eDefault"; break; case DTDAttribute::eRequired: cout << "eRequired"; break; case DTDAttribute::eImplied: cout << "eImplied"; break; case DTDAttribute::eFixed: cout << "eFixed"; break; } cout << ", "; cout << "\"" << i->GetValue() << "\""; cout << endl; }}#endifEND_NCBI_SCOPE/* * ========================================================================== * $Log: dtdparser.cpp,v $ * Revision 1000.2 2004/06/01 19:42:52 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19 * * Revision 1.19 2004/05/19 17:24:18 gouriano * Corrected generation of C++ code by DTD for containers * * Revision 1.18 2004/05/17 21:03:14 gorelenk * Added include of PCH ncbi_pch.hpp * * Revision 1.17 2004/04/27 18:38:53 gouriano * In FixEmbeddedNames() not to use the same "fixed" name twice * * Revision 1.16 2004/04/01 14:14:02 lavr * Spell "occurred", "occurrence", and "occurring" * * Revision 1.15 2004/01/12 16:51:01 gouriano * Improved diagnostics when parsing a DTD * * Revision 1.14 2003/08/13 15:45:54 gouriano * implemented generation of code, which uses AnyContent objects * * Revision 1.13 2003/06/24 20:55:42 gouriano * corrected code generation and serialization of non-empty unnamed containers (XML) * * Revision 1.12 2003/06/16 14:41:05 gouriano * added possibility to convert DTD to XML schema * * Revision 1.11 2003/03/10 18:55:18 gouriano * use new structured exceptions (based on CException) * * Revision 1.10 2003/02/10 17:56:15 gouriano * make it possible to disable scope prefixes when reading and writing objects generated from ASN specification in XML format, or when converting an ASN spec into DTD. * * Revision 1.9 2003/01/21 19:34:17 gouriano * corrected parsing of entities * * Revision 1.8 2003/01/14 19:02:09 gouriano * added parsing of entities as attribute contents * * Revision 1.7 2002/12/17 16:24:43 gouriano * replaced _ASSERTs by throwing an exception * * Revision 1.6 2002/11/26 22:00:29 gouriano * added unnamed lists of sequences (or choices) as container elements * * Revision 1.5 2002/11/19 19:48:28 gouriano * added support of XML attributes of choice variants * * Revision 1.4 2002/11/14 21:05:27 gouriano * added support of XML attribute lists * * Revision 1.3 2002/10/21 16:11:13 gouriano * added parsing of external entities * * Revision 1.2 2002/10/18 14:38:56 gouriano * added parsing of internal parsed entities * * Revision 1.1 2002/10/15 13:54:01 gouriano * DTD lexer and parser, first version * * * ========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -