// Get the Nth entry. MHParseNode *MHParseNode::GetArgN(int n) { if (m_nNodeType == PNTagged) { MHPTagged *pTag = (MHPTagged *)this; if (n < 0 || n >= pTag->m_Args.Size()) { Failure("Argument not found"); } return pTag->m_Args.GetAt(n); } else if (m_nNodeType == PNSeq) { MHParseSequence *pSeq = (MHParseSequence *)this; if (n < 0 || n >= pSeq->Size()) { Failure("Argument not found"); } return pSeq->GetAt(n); } else { Failure("Expected tagged value"); } return 0; // To keep the compiler happy }
// Get an argument with a specific tag. Returns NULL if it doesn't exist. // There is a defined order of tags for both the binary and textual representations. // Unfortunately they're not the same. MHParseNode *MHParseNode::GetNamedArg(int nTag) { MHParseSequence *pArgs = NULL; if (m_nNodeType == PNTagged) { pArgs = &((MHPTagged *)this)->m_Args; } else if (m_nNodeType == PNSeq) { pArgs = (MHParseSequence *)this; } else { Failure("Expected tagged value or sequence"); } for (int i = 0; i < pArgs->Size(); i++) { MHParseNode *p = pArgs->GetAt(i); if (p && p->m_nNodeType == PNTagged && ((MHPTagged *)p)->m_TagNo == nTag) { return p; } } return NULL; }
MHParseNode *MHParseNode::GetSeqN(int n) { if (m_nNodeType != PNSeq) { Failure("Expected sequence"); } MHParseSequence *pSeq = (MHParseSequence *)this; if (n < 0 || n >= pSeq->Size()) { Failure("Argument not found"); } return pSeq->GetAt(n); }