Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
PredicateList Class Reference

Represents an ordered list of Predicates, for use with Step and Filter Expressions. More...

#include <Expr.h>

Inheritance diagram for PredicateList:
Inheritance graph
[legend]
Collaboration diagram for PredicateList:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PredicateList ()
 Creates a new PredicateList.
virtual ~PredicateList ()
 Destructor, will delete all Expressions in the list, so remove any you may need.
nsresult add (Expr *aExpr)
 Adds the given Expr to the list.
nsresult evaluatePredicates (txNodeSet *aNodes, txIMatchContext *aContext)
MBool isEmpty ()
 returns true if this predicate list is empty

Protected Attributes

List predicates

Detailed Description

Represents an ordered list of Predicates, for use with Step and Filter Expressions.

Definition at line 312 of file Expr.h.


Constructor & Destructor Documentation

Creates a new PredicateList.

Definition at line 48 of file PredicateList.cpp.

{
} // PredicateList

Destructor, will delete all Expressions in the list, so remove any you may need.

Definition at line 55 of file PredicateList.cpp.

{
    txListIterator iter(&predicates);
    while (iter.hasNext()) {
        delete (Expr*)iter.next();
    }
} // ~PredicateList

Here is the call graph for this function:


Member Function Documentation

Adds the given Expr to the list.

The ownership of the given Expr is passed over the PredicateList, even on failure.

Parameters:
aExprthe Expr to add to the list
Returns:
nsresult indicating out of memory

Definition at line 68 of file PredicateList.cpp.

{
    NS_ASSERTION(aExpr, "missing expression");
    nsresult rv = predicates.add(aExpr);
    if (NS_FAILED(rv)) {
        delete aExpr;
    }
    return rv;
} // add

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 79 of file PredicateList.cpp.

{
    NS_ASSERTION(nodes, "called evaluatePredicates with NULL NodeSet");
    nsresult rv = NS_OK;

    txListIterator iter(&predicates);
    while (iter.hasNext() && !nodes->isEmpty()) {
        Expr* expr = (Expr*)iter.next();
        txNodeSetContext predContext(nodes, aContext);
        /*
         * add nodes to newNodes that match the expression
         * or, if the result is a number, add the node with the right
         * position
         */
        PRInt32 index = 0;
        while (predContext.hasNext()) {
            predContext.next();
            nsRefPtr<txAExprResult> exprResult;
            rv = expr->evaluate(&predContext, getter_AddRefs(exprResult));
            NS_ENSURE_SUCCESS(rv, rv);

            // handle default, [position() == numberValue()]
            if (exprResult->getResultType() == txAExprResult::NUMBER) {
                if ((double)predContext.position() == exprResult->numberValue()) {
                    nodes->mark(index);
                }
            }
            else if (exprResult->booleanValue()) {
                nodes->mark(index);
            }
            ++index;
        }
        // sweep the non-marked nodes
        nodes->sweep();
    }

    return NS_OK;
}

Here is the call graph for this function:

returns true if this predicate list is empty

Definition at line 122 of file PredicateList.cpp.

{
    return (MBool)(predicates.getLength() == 0);
} // isEmpty

Here is the call graph for this function:


Member Data Documentation

Definition at line 356 of file Expr.h.


The documentation for this class was generated from the following files: