Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsGlobalHistory::SearchEnumerator Class Reference

#include <nsGlobalHistory.h>

Inheritance diagram for nsGlobalHistory::SearchEnumerator:
Inheritance graph
[legend]
Collaboration diagram for nsGlobalHistory::SearchEnumerator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SearchEnumerator (searchQuery *aQuery, mdb_column aHiddenColumn, nsGlobalHistory *aHistory)
virtual ~SearchEnumerator ()
 SearchEnumerator (searchQuery *aQuery, mdb_column aHiddenColumn, nsGlobalHistory *aHistory)
virtual ~SearchEnumerator ()
NS_DECL_ISUPPORTS NS_IMETHOD HasMoreElements (PRBool *_result)
NS_DECL_ISUPPORTS NS_IMETHOD HasMoreElements (PRBool *_result)
NS_IMETHOD GetNext (nsISupports **_result)
NS_IMETHOD GetNext (nsISupports **_result)
virtual nsresult Init (nsIMdbEnv *aEnv, nsIMdbTable *aTable)
virtual nsresult Init (nsIMdbEnv *aEnv, nsIMdbTable *aTable)
boolean hasMoreElements ()
 Called to determine whether or not the enumerator has any elements that can be returned via getNext().
nsISupports getNext ()
 Called to retrieve the next element in the enumerator.

Protected Member Functions

virtual PRBool IsResult (nsIMdbRow *aRow)
virtual nsresult ConvertToISupports (nsIMdbRow *aRow, nsISupports **aResult)
PRBool RowMatches (nsIMdbRow *aRow, searchQuery *aQuery)
virtual PRBool IsResult (nsIMdbRow *aRow)
virtual nsresult ConvertToISupports (nsIMdbRow *aRow, nsISupports **aResult)
PRBool RowMatches (nsIMdbRow *aRow, searchQuery *aQuery)

Protected Attributes

searchQuerymQuery
mdb_column mHiddenColumn
nsGlobalHistorymHistory
nsHashtable mUniqueRows
nsCString mFindUriPrefix
nsIMdbEnvmEnv

Detailed Description

Definition at line 414 of file nsGlobalHistory.h.


Constructor & Destructor Documentation

nsGlobalHistory::SearchEnumerator::SearchEnumerator ( searchQuery aQuery,
mdb_column  aHiddenColumn,
nsGlobalHistory aHistory 
) [inline]

Definition at line 417 of file nsGlobalHistory.h.

                                                :
      mQuery(aQuery),
      mHiddenColumn(aHiddenColumn),
      mHistory(aHistory)
    {}

Definition at line 3845 of file nsGlobalHistory.cpp.

Here is the call graph for this function:

nsGlobalHistory::SearchEnumerator::SearchEnumerator ( searchQuery aQuery,
mdb_column  aHiddenColumn,
nsGlobalHistory aHistory 
) [inline]

Definition at line 411 of file nsGlobalHistory.h.

                                                :
      mQuery(aQuery),
      mHiddenColumn(aHiddenColumn),
      mHistory(aHistory)
    {}

Member Function Documentation

virtual nsresult nsGlobalHistory::SearchEnumerator::ConvertToISupports ( nsIMdbRow aRow,
nsISupports **  aResult 
) [protected, virtual]

Implements nsMdbTableEnumerator.

nsresult nsGlobalHistory::SearchEnumerator::ConvertToISupports ( nsIMdbRow aRow,
nsISupports **  aResult 
) [protected, virtual]

Implements nsMdbTableEnumerator.

Definition at line 4142 of file nsGlobalHistory.cpp.

{
  mdb_err err;
  nsresult rv;
  
  nsCOMPtr<nsIRDFResource> resource;
  if (mQuery->groupBy == 0) {
    // no column to group by
    // just create a resource based on the URL of the current row
    mdbYarn yarn;
    err = aRow->AliasCellYarn(mEnv, mHistory->kToken_URLColumn, &yarn);
    if (err != 0) return NS_ERROR_FAILURE;

    
    const char* startPtr = (const char*)yarn.mYarn_Buf;
    rv = gRDFService->GetResource(
            Substring(startPtr, startPtr+yarn.mYarn_Fill),
            getter_AddRefs(resource));
    if (NS_FAILED(rv)) return rv;

    *aResult = resource;
    NS_ADDREF(*aResult);
    return NS_OK;
  }

  // we have a group by, so now we recreate the find url, but add a
  // query for the row asked for by groupby
  mdbYarn groupByValue;
  err = aRow->AliasCellYarn(mEnv, mQuery->groupBy, &groupByValue);
  if (err != 0) return NS_ERROR_FAILURE;

  if (mFindUriPrefix.IsEmpty())
    mHistory->GetFindUriPrefix(*mQuery, PR_FALSE, mFindUriPrefix);
  
  nsCAutoString findUri(mFindUriPrefix);

  const char* startPtr = (const char *)groupByValue.mYarn_Buf;
  findUri.Append(Substring(startPtr, startPtr+groupByValue.mYarn_Fill));
  findUri.Append('\0');

  rv = gRDFService->GetResource(findUri, getter_AddRefs(resource));
  if (NS_FAILED(rv)) return rv;

  *aResult = resource;
  NS_ADDREF(*aResult);
  return NS_OK;
}

Here is the call graph for this function:

nsISupports nsISimpleEnumerator::getNext ( ) [inherited]

Called to retrieve the next element in the enumerator.

The "next" element is the first element upon the first call. Must be pre-ceeded by a call to hasMoreElements() which returns PR_TRUE. This method is generally called within a loop to iterate over the elements in the enumerator.

See also:
hasMoreElements()
Returns:
NS_OK if the call succeeded in returning a non-null value through the out parameter. NS_ERROR_FAILURE if there are no more elements to enumerate.
the next element in the enumeration.

Here is the caller graph for this function:

NS_IMETHOD nsMdbTableEnumerator::GetNext ( nsISupports **  _result) [inherited]
NS_IMETHODIMP nsMdbTableEnumerator::GetNext ( nsISupports **  _result) [inherited]

Definition at line 445 of file nsGlobalHistory.cpp.

{
  nsresult rv;

  PRBool hasMore;
  rv = HasMoreElements(&hasMore);
  if (NS_FAILED(rv)) return rv;

  if (! hasMore)
    return NS_ERROR_UNEXPECTED;

  rv = ConvertToISupports(mCurrent, _result);

  NS_RELEASE(mCurrent);
  mCurrent = nsnull;

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Called to determine whether or not the enumerator has any elements that can be returned via getNext().

This method is generally used to determine whether or not to initiate or continue iteration over the enumerator, though it can be called without subsequent getNext() calls. Does not affect internal state of enumerator.

See also:
getNext()
Returns:
PR_TRUE if there are remaining elements in the enumerator. PR_FALSE if there are no more elements in the enumerator.

Here is the caller graph for this function:

Definition at line 414 of file nsGlobalHistory.cpp.

{
  if (! mCurrent) {
    mdb_err err;

    while (1) {
      mdb_pos pos;
      err = mCursor->NextRow(mEnv, &mCurrent, &pos);
      if (err != 0) return NS_ERROR_FAILURE;

      // If there are no more rows, then bail.
      if (! mCurrent)
        break;

      // If this is a result, the stop.
      if (IsResult(mCurrent))
        break;

      // Otherwise, drop the ref to the row we retrieved, and continue
      // on to the next one.
      NS_RELEASE(mCurrent);
      mCurrent = nsnull;
    }
  }

  *_result = (mCurrent != nsnull);
  return NS_OK;
}

Here is the caller graph for this function:

virtual nsresult nsMdbTableEnumerator::Init ( nsIMdbEnv aEnv,
nsIMdbTable aTable 
) [virtual, inherited]
nsresult nsMdbTableEnumerator::Init ( nsIMdbEnv aEnv,
nsIMdbTable aTable 
) [virtual, inherited]

Definition at line 374 of file nsGlobalHistory.cpp.

{
  NS_PRECONDITION(aEnv != nsnull, "null ptr");
  if (! aEnv)
    return NS_ERROR_NULL_POINTER;

  NS_PRECONDITION(aTable != nsnull, "null ptr");
  if (! aTable)
    return NS_ERROR_NULL_POINTER;

  mEnv = aEnv;
  NS_ADDREF(mEnv);

  mTable = aTable;
  NS_ADDREF(mTable);

  mdb_err err;
  err = mTable->GetTableRowCursor(mEnv, -1, &mCursor);
  if (err != 0) return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual PRBool nsGlobalHistory::SearchEnumerator::IsResult ( nsIMdbRow aRow) [protected, virtual]

Implements nsMdbTableEnumerator.

Implements nsMdbTableEnumerator.

Definition at line 3934 of file nsGlobalHistory.cpp.

{
  if (HasCell(mEnv, aRow, mHiddenColumn))
    return PR_FALSE;
  
  mdb_err err;

  mdbYarn groupColumnValue = { nsnull, 0, 0, 0, 0, nsnull};
  if (mQuery->groupBy!=0) {

    // if we have a 'groupby', then we use the hashtable to make sure
    // we only match the FIRST row with the column value that we're
    // grouping by
    
    err = aRow->AliasCellYarn(mEnv, mQuery->groupBy, &groupColumnValue);
    if (err!=0) return PR_FALSE;
    if (!groupColumnValue.mYarn_Buf) return PR_FALSE;

    const char* startPtr = (const char*)groupColumnValue.mYarn_Buf;
    nsCStringKey key(Substring(startPtr,
                               startPtr +  groupColumnValue.mYarn_Fill));

    void *otherRow = mUniqueRows.Get(&key);

    // Hey! we've seen this row before, so ignore it
    if (otherRow) return PR_FALSE;
  }

  // now do the actual match
  if (!mHistory->RowMatches(aRow, mQuery, PR_FALSE))
    return PR_FALSE;

  if (mQuery->groupBy != 0) {
    // we got this far, so we must have matched.
    // add ourselves to the hashtable so we don't match rows like this
    // in the future
    const char* startPtr = (const char*)groupColumnValue.mYarn_Buf;
    nsCStringKey key(Substring(startPtr,
                               startPtr + groupColumnValue.mYarn_Fill));
    
    // note - weak ref, don't worry about releasing
    mUniqueRows.Put(&key, (void *)aRow);
  }

  return PR_TRUE;
}

Here is the call graph for this function:


Member Data Documentation

nsIMdbEnv * nsMdbTableEnumerator::mEnv [protected, inherited]

Definition at line 79 of file nsGlobalHistory.h.

Definition at line 433 of file nsGlobalHistory.h.

Definition at line 429 of file nsGlobalHistory.h.

Definition at line 430 of file nsGlobalHistory.h.

Definition at line 428 of file nsGlobalHistory.h.

Definition at line 431 of file nsGlobalHistory.h.


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