Example #1
0
// 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
}
Example #2
0
// 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;
}
Example #3
0
// Sequence.
int MHParseNode::GetSeqCount()
{
    if (m_nNodeType != PNSeq)
    {
        Failure("Expected sequence");
    }

    MHParseSequence *pSeq = (MHParseSequence *)this;
    return pSeq->Size();
}
Example #4
0
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);
}
Example #5
0
// Return the number of items in the sequence.
int MHParseNode::GetArgCount()
{
    if (m_nNodeType == PNTagged)
    {
        MHPTagged *pTag = (MHPTagged *)this;
        return pTag->m_Args.Size();
    }
    else if (m_nNodeType == PNSeq)
    {
        MHParseSequence *pSeq = (MHParseSequence *)this;
        return pSeq->Size();
    }
    else
    {
        Failure("Expected tagged value");
    }

    return 0; // To keep the compiler happy
}