Back to index

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

#include <nsMsgSearchBoolExpression.h>

Collaboration diagram for nsMsgSearchBoolExpression:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMsgSearchBoolExpression (nsIMsgSearchTerm *aNewTerm, char *aEncodingString=NULL)
 nsMsgSearchBoolExpression (nsMsgSearchBoolExpression *, nsMsgSearchBoolExpression *, nsMsgSearchBooleanOperator boolOp)
 nsMsgSearchBoolExpression ()
 ~nsMsgSearchBoolExpression ()
PRBool OfflineEvaluate (nsIMsgDBHdr *msgToMatch, const char *defaultCharset, nsIMsgSearchScopeTerm *scope, nsIMsgDatabase *db, const char *headers, PRUint32 headerSize, PRBool Filtering)
PRInt32 CalcEncodeStrSize ()
void GenerateEncodeStr (nsCString *buffer)

Static Public Member Functions

static nsMsgSearchBoolExpressionAddSearchTerm (nsMsgSearchBoolExpression *aOrigExpr, nsIMsgSearchTerm *aNewTerm, char *aEncodingStr)
static nsMsgSearchBoolExpressionAddExpressionTree (nsMsgSearchBoolExpression *aOrigExpr, nsMsgSearchBoolExpression *aExpression, PRBool aBoolOp)

Public Attributes

nsMsgSearchBoolExpressionm_leftChild
nsMsgSearchBoolExpressionm_rightChild
nsMsgSearchBooleanOperator m_boolOp

Protected Member Functions

nsMsgSearchBoolExpressionleftToRightAddTerm (nsIMsgSearchTerm *newTerm, char *encodingStr)

Protected Attributes

nsIMsgSearchTermm_term
nsCString m_encodingStr

Detailed Description

Definition at line 72 of file nsMsgSearchBoolExpression.h.


Constructor & Destructor Documentation

nsMsgSearchBoolExpression::nsMsgSearchBoolExpression ( nsIMsgSearchTerm aNewTerm,
char *  aEncodingString = NULL 
)

Definition at line 100 of file nsMsgLocalSearch.cpp.

{
    m_term = newTerm;
    m_encodingStr = encodingStr;
    m_boolOp = nsMsgSearchBooleanOp::BooleanAND;

    // this expression does not contain sub expressions
    m_leftChild = nsnull;
    m_rightChild = nsnull;
}

Definition at line 115 of file nsMsgLocalSearch.cpp.

{
    m_leftChild = expr1;
    m_rightChild = expr2;
    m_boolOp = boolOp;

    m_term = nsnull;
}

Definition at line 92 of file nsMsgLocalSearch.cpp.

Here is the caller graph for this function:

Definition at line 126 of file nsMsgLocalSearch.cpp.

{
  // we must recursively destroy all sub expressions before we destroy ourself.....We leave search terms alone!
  delete m_leftChild;
  delete m_rightChild;
}

Member Function Documentation

Definition at line 78 of file nsMsgLocalSearch.cpp.

{
  if (!aOrigExpr->m_term && !aOrigExpr->m_leftChild && !aOrigExpr->m_rightChild)
  {
      // just use the original expression tree...
      // delete the original since we have a new original to use
      delete aOrigExpr;
      return aExpression;
  }

  nsMsgSearchBoolExpression * newExpr = new nsMsgSearchBoolExpression (aOrigExpr, aExpression, aBoolOp);  
  return (newExpr) ? newExpr : aOrigExpr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsMsgSearchBoolExpression * nsMsgSearchBoolExpression::AddSearchTerm ( nsMsgSearchBoolExpression aOrigExpr,
nsIMsgSearchTerm aNewTerm,
char *  aEncodingStr 
) [static]

Definition at line 71 of file nsMsgLocalSearch.cpp.

{
    return aOrigExpr->leftToRightAddTerm(aNewTerm, aEncodingStr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file nsMsgLocalSearch.cpp.

{
    if (!m_term && (!m_leftChild || !m_rightChild))   // is the expression empty?
        return 0;    
    if (m_term)  // are we a leaf node?
        return m_encodingStr.Length();
    if (m_boolOp == nsMsgSearchBooleanOp::BooleanOR)
        return sizeOfORTerm + m_leftChild->CalcEncodeStrSize() + m_rightChild->CalcEncodeStrSize();
    if (m_boolOp == nsMsgSearchBooleanOp::BooleanAND)
        return sizeOfANDTerm + m_leftChild->CalcEncodeStrSize() + m_rightChild->CalcEncodeStrSize();
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 218 of file nsMsgLocalSearch.cpp.

{
    if ((!m_term && (!m_leftChild || !m_rightChild))) // is expression empty?
        return;
    
    if (m_term) // are we a leaf expression?
    {
        *buffer += m_encodingStr;
        return;
    }
    
    // add encode strings of each sub expression
    if (m_boolOp == nsMsgSearchBooleanOp::BooleanOR) 
    {
        *buffer += " (OR";

        m_leftChild->GenerateEncodeStr(buffer);  // insert left expression into the buffer
        m_rightChild->GenerateEncodeStr(buffer);  // insert right expression into the buffer
        
        // HACK ALERT!!! if last returned character in the buffer is now a ' ' then we need to remove it because we don't want
        // a ' ' to preceded the closing paren in the OR encoding.
        PRUint32 lastCharPos = buffer->Length() - 1;
        if (buffer->CharAt(lastCharPos) == ' ')
        {
            buffer->Truncate(lastCharPos);
        }
        
        *buffer += ')';
    }
    else if (m_boolOp == nsMsgSearchBooleanOp::BooleanAND)
    {
        m_leftChild->GenerateEncodeStr(buffer); // insert left expression
        m_rightChild->GenerateEncodeStr(buffer);
    }
    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsMsgSearchBoolExpression * nsMsgSearchBoolExpression::leftToRightAddTerm ( nsIMsgSearchTerm newTerm,
char *  encodingStr 
) [protected]

Definition at line 134 of file nsMsgLocalSearch.cpp.

{
    // we have a base case where this is the first term being added to the expression:
    if (!m_term && !m_leftChild && !m_rightChild)
    {
        m_term = newTerm;
        m_encodingStr = encodingStr;
        return this;
    }

    nsMsgSearchBoolExpression * tempExpr = new nsMsgSearchBoolExpression (newTerm,encodingStr);
    if (tempExpr)  // make sure creation succeeded
    {
      PRBool booleanAnd;
      newTerm->GetBooleanAnd(&booleanAnd);
      nsMsgSearchBoolExpression * newExpr = new nsMsgSearchBoolExpression (this, tempExpr, booleanAnd);  
      if (newExpr)
         return newExpr;
      else
         delete tempExpr;    // clean up memory allocation in case of failure
    }
    return this;   // in case we failed to create a new expression, return self
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsMsgSearchBoolExpression::OfflineEvaluate ( nsIMsgDBHdr msgToMatch,
const char *  defaultCharset,
nsIMsgSearchScopeTerm scope,
nsIMsgDatabase db,
const char *  headers,
PRUint32  headerSize,
PRBool  Filtering 
)

Definition at line 160 of file nsMsgLocalSearch.cpp.

{
    PRBool result = PR_TRUE;    // always default to false positives
    PRBool isAnd;

    if (m_term) // do we contain just a search term?
    {
      nsMsgSearchOfflineMail::ProcessSearchTerm(msgToMatch, m_term,
        defaultCharset, scope, db, headers, headerSize, Filtering, &result);
      return result;
    }
    
    // otherwise we must recursively determine the value of our sub expressions

    isAnd = (m_boolOp == nsMsgSearchBooleanOp::BooleanAND);

    if (m_leftChild)
    {
        result = m_leftChild->OfflineEvaluate(msgToMatch, defaultCharset,
          scope, db, headers, headerSize, Filtering);
        // If (TRUE and OR) or (FALSE and AND) return result
        if (result ^ isAnd)
          return result;
    }

    // If we got this far, either there was no leftChild (which is impossible)
    // or we got (FALSE and OR) or (TRUE and AND) from the first result. That
    // means the outcome depends entirely on the rightChild.
    if (m_rightChild)
        result = m_rightChild->OfflineEvaluate(msgToMatch, defaultCharset,
          scope, db, headers, headerSize, Filtering);

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 118 of file nsMsgSearchBoolExpression.h.

Definition at line 126 of file nsMsgSearchBoolExpression.h.

Definition at line 116 of file nsMsgSearchBoolExpression.h.

Definition at line 117 of file nsMsgSearchBoolExpression.h.

Definition at line 123 of file nsMsgSearchBoolExpression.h.


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