Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
RelationalExpr Class Reference

Represents a RelationalExpr, an expression that compares it's lvalue to it's rvalue using: = : equal to < : less than

: greater than

<= : less than or equal to >= : greater than or equal to. More...

#include <Expr.h>

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

List of all members.

Public Types

enum  RelationalExprType {
  EQUAL, NOT_EQUAL, LESS_THAN, GREATER_THAN,
  LESS_OR_EQUAL, GREATER_OR_EQUAL
}

Public Member Functions

 RelationalExpr (nsAutoPtr< Expr > &aLeftExpr, nsAutoPtr< Expr > &aRightExpr, RelationalExprType aOp)
virtual nsresult evaluate (txIEvalContext *aContext, txAExprResult **aResult)=0
 Evaluates this Expr based on the given context node and processor state.

Public Attributes

 TX_DECL_EXPR
u8 op
char affinity
u8 flags
CollSeqpColl
ExprpLeft
ExprpRight
ExprListpList
Token token
Token span
int iTable
int iColumn
AggInfopAggInfo
int iAgg
int iRightJoinTable
SelectpSelect
TablepTab
SchemapSchema

Private Member Functions

PRBool compareResults (txIEvalContext *aContext, txAExprResult *aLeft, txAExprResult *aRight)
 Compares the two ExprResults based on XPath 1.0 Recommendation (section 3.4)

Private Attributes

nsAutoPtr< ExprmLeftExpr
nsAutoPtr< ExprmRightExpr
RelationalExprType mOp

Detailed Description

Represents a RelationalExpr, an expression that compares it's lvalue to it's rvalue using: = : equal to < : less than

: greater than

<= : less than or equal to >= : greater than or equal to.

Definition at line 550 of file Expr.h.


Member Enumeration Documentation

Enumerator:
EQUAL 
NOT_EQUAL 
LESS_THAN 
GREATER_THAN 
LESS_OR_EQUAL 
GREATER_OR_EQUAL 

Definition at line 553 of file Expr.h.


Constructor & Destructor Documentation

RelationalExpr::RelationalExpr ( nsAutoPtr< Expr > &  aLeftExpr,
nsAutoPtr< Expr > &  aRightExpr,
RelationalExprType  aOp 
) [inline]

Definition at line 562 of file Expr.h.

        : mLeftExpr(aLeftExpr),
          mRightExpr(aRightExpr),
          mOp(aOp)
    {
    }

Member Function Documentation

PRBool RelationalExpr::compareResults ( txIEvalContext aContext,
txAExprResult aLeft,
txAExprResult aRight 
) [private]

Compares the two ExprResults based on XPath 1.0 Recommendation (section 3.4)

Definition at line 47 of file RelationalExpr.cpp.

{
    short ltype = aLeft->getResultType();
    short rtype = aRight->getResultType();
    nsresult rv = NS_OK;

    // Handle case for just Left NodeSet or Both NodeSets
    if (ltype == txAExprResult::NODESET) {
        if (rtype == txAExprResult::BOOLEAN) {
            BooleanResult leftBool(aLeft->booleanValue());
            return compareResults(aContext, &leftBool, aRight);
        }

        txNodeSet* nodeSet = NS_STATIC_CAST(txNodeSet*, aLeft);
        nsRefPtr<StringResult> strResult;
        rv = aContext->recycler()->getStringResult(getter_AddRefs(strResult));
        NS_ENSURE_SUCCESS(rv, rv);

        PRInt32 i;
        for (i = 0; i < nodeSet->size(); ++i) {
            strResult->mValue.Truncate();
            txXPathNodeUtils::appendNodeValue(nodeSet->get(i),
                                              strResult->mValue);
            if (compareResults(aContext, strResult, aRight)) {
                return PR_TRUE;
            }
        }

        return PR_FALSE;
    }

    // Handle case for Just Right NodeSet
    if (rtype == txAExprResult::NODESET) {
        if (ltype == txAExprResult::BOOLEAN) {
            BooleanResult rightBool(aRight->booleanValue());
            return compareResults(aContext, aLeft, &rightBool);
        }

        txNodeSet* nodeSet = NS_STATIC_CAST(txNodeSet*, aRight);
        nsRefPtr<StringResult> strResult;
        rv = aContext->recycler()->getStringResult(getter_AddRefs(strResult));
        NS_ENSURE_SUCCESS(rv, rv);

        PRInt32 i;
        for (i = 0; i < nodeSet->size(); ++i) {
            strResult->mValue.Truncate();
            txXPathNodeUtils::appendNodeValue(nodeSet->get(i),
                                              strResult->mValue);
            if (compareResults(aContext, aLeft, strResult)) {
                return PR_TRUE;
            }
        }

        return PR_FALSE;
    }

    // Neither is a NodeSet
    if (mOp == EQUAL || mOp == NOT_EQUAL) {
        PRBool result;
        nsAString *lString, *rString;

        // If either is a bool, compare as bools.
        if (ltype == txAExprResult::BOOLEAN ||
            rtype == txAExprResult::BOOLEAN) {
            result = aLeft->booleanValue() == aRight->booleanValue();
        }

        // If either is a number, compare as numbers.
        else if (ltype == txAExprResult::NUMBER ||
                 rtype == txAExprResult::NUMBER) {
            double lval = aLeft->numberValue();
            double rval = aRight->numberValue();
#if defined(XP_WIN)
            if (Double::isNaN(lval) || Double::isNaN(rval))
                result = PR_FALSE;
            else
                result = lval == rval;
#else
            result = lval == rval;
#endif
        }

        // Otherwise compare as strings. Try to use the stringobject in
        // StringResult if possible since that is a common case.
        else if ((lString = aLeft->stringValuePointer())) {
            if ((rString = aRight->stringValuePointer())) {
                result = lString->Equals(*rString);
            }
            else {
                nsAutoString rStr;
                aRight->stringValue(rStr);
                result = rStr.Equals(*lString);
            }
        }
        else if ((rString = aRight->stringValuePointer())) {
            nsAutoString lStr;
            aLeft->stringValue(lStr);
            result = rString->Equals(lStr);
        }
        else {
            nsAutoString lStr, rStr;
            aLeft->stringValue(lStr);
            aRight->stringValue(rStr);
            result = lStr.Equals(rStr);
        }

        return mOp == EQUAL ? result : !result;
    }

    double leftDbl = aLeft->numberValue();
    double rightDbl = aRight->numberValue();
#if defined(XP_WIN)
    if (Double::isNaN(leftDbl) || Double::isNaN(rightDbl))
        return PR_FALSE;
#endif

    switch (mOp) {
        case LESS_THAN:
        {
            return leftDbl < rightDbl;
        }
        case LESS_OR_EQUAL:
        {
            return leftDbl <= rightDbl;
        }
        case GREATER_THAN:
        {
            return leftDbl > rightDbl;
        }
        case GREATER_OR_EQUAL:
        {
            return leftDbl >= rightDbl;
        }
        default:
        {
            NS_NOTREACHED("We should have caught all cases");
        }
    }

    return PR_FALSE;
}

Here is the call graph for this function:

virtual nsresult Expr::evaluate ( txIEvalContext aContext,
txAExprResult **  aResult 
) [pure virtual, inherited]

Evaluates this Expr based on the given context node and processor state.

Parameters:
contextthe context node for evaluation of this Expr
psthe ContextState containing the stack information needed for evaluation
Returns:
the result of the evaluation

Here is the caller graph for this function:


Member Data Documentation

char Expr::affinity [inherited]

Definition at line 951 of file sqliteInt.h.

u8 Expr::flags [inherited]

Definition at line 952 of file sqliteInt.h.

int Expr::iAgg [inherited]

Definition at line 962 of file sqliteInt.h.

int Expr::iColumn [inherited]

Definition at line 959 of file sqliteInt.h.

Definition at line 963 of file sqliteInt.h.

int Expr::iTable [inherited]

Definition at line 959 of file sqliteInt.h.

Definition at line 577 of file Expr.h.

Definition at line 579 of file Expr.h.

Definition at line 578 of file Expr.h.

u8 Expr::op [inherited]

Reimplemented in MultiplicativeExpr, BooleanExpr, and AdditiveExpr.

Definition at line 950 of file sqliteInt.h.

AggInfo* Expr::pAggInfo [inherited]

Definition at line 961 of file sqliteInt.h.

CollSeq* Expr::pColl [inherited]

Definition at line 953 of file sqliteInt.h.

Expr* Expr::pLeft [inherited]

Definition at line 954 of file sqliteInt.h.

ExprList* Expr::pList [inherited]

Definition at line 955 of file sqliteInt.h.

Expr * Expr::pRight [inherited]

Definition at line 954 of file sqliteInt.h.

Schema* Expr::pSchema [inherited]

Definition at line 967 of file sqliteInt.h.

Select* Expr::pSelect [inherited]

Definition at line 964 of file sqliteInt.h.

Table* Expr::pTab [inherited]

Definition at line 966 of file sqliteInt.h.

Token Expr::span [inherited]

Definition at line 958 of file sqliteInt.h.

Token Expr::token [inherited]

Definition at line 957 of file sqliteInt.h.

Definition at line 571 of file Expr.h.


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