Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Types | Protected Attributes | Private Member Functions
nsDirEnumerator Class Reference
Inheritance diagram for nsDirEnumerator:
Inheritance graph
[legend]
Collaboration diagram for nsDirEnumerator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsDirEnumerator ()
nsresult Init (nsILocalFileMac *parent)
NS_IMETHOD HasMoreElements (PRBool *result)
NS_IMETHOD GetNext (nsISupports **result)
NS_DECL_ISUPPORTS nsDirEnumerator ()
nsresult Init (nsILocalFile *parent)
NS_IMETHOD HasMoreElements (PRBool *result)
NS_IMETHOD GetNext (nsISupports **result)
NS_IMETHOD GetNextFile (nsIFile **result)
NS_IMETHOD Close ()
 ~nsDirEnumerator ()
NS_DECL_ISUPPORTS nsDirEnumerator ()
nsresult Init (nsILocalFileMac *parent)
NS_IMETHOD HasMoreElements (PRBool *result)
NS_IMETHOD GetNext (nsISupports **result)
NS_IMETHOD GetNextFile (nsIFile **result)
NS_IMETHOD Close ()
NS_DECL_ISUPPORTS nsDirEnumerator ()
nsresult Init (nsILocalFile *parent)
NS_IMETHOD HasMoreElements (PRBool *result)
NS_IMETHOD GetNext (nsISupports **result)
NS_IMETHOD GetNextFile (nsIFile **result)
NS_IMETHOD Close ()
 ~nsDirEnumerator ()
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.
void close ()
 Closes the directory being enumerated, releasing the system resource.

Public Attributes

readonly attribute nsIFile nextFile
 Retrieves the next file in the sequence.

Protected Types

enum  { kRequestCountPerIteration = ((4096 * 4) / sizeof(FSRef)) }

Protected Attributes

nsCOMPtr< nsILocalFileMacmNext
CInfoPBRec mCatInfo
short mItemIndex
long mDirID
Str63 mItemName
PRDirmDir
nsCOMPtr< nsILocalFilemParent
nsCOMPtr< nsILocalFilemNext
FSIterator mIterator
FSRefmFSRefsArray
PRInt32 mArrayCnt
PRInt32 mArrayIndex
nsDirmDir

Private Member Functions

 ~nsDirEnumerator ()
 ~nsDirEnumerator ()

Detailed Description

Definition at line 823 of file nsLocalFileMac.cpp.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
kRequestCountPerIteration 

Definition at line 252 of file nsLocalFileOSX.cpp.

             {
          kRequestCountPerIteration = ((4096 * 4) / sizeof(FSRef))
        };

Constructor & Destructor Documentation

Definition at line 829 of file nsLocalFileMac.cpp.

        {
        }
nsDirEnumerator::~nsDirEnumerator ( ) [inline, private]

Definition at line 907 of file nsLocalFileMac.cpp.

{}

Definition at line 269 of file nsLocalFileOS2.cpp.

                          : mDir(nsnull)
        {
        }

Definition at line 382 of file nsLocalFileOS2.cpp.

        {
            Close();
        }

Here is the call graph for this function:

Definition at line 132 of file nsLocalFileOSX.cpp.

nsDirEnumerator::~nsDirEnumerator ( ) [inline, private]

Definition at line 244 of file nsLocalFileOSX.cpp.

        {
          Close();
        }

Here is the call graph for this function:

Definition at line 645 of file nsLocalFileWin.cpp.

                          : mDir(nsnull)
        {
        }

Definition at line 760 of file nsLocalFileWin.cpp.

        {
            Close();
        }

Here is the call graph for this function:


Member Function Documentation

Closes the directory being enumerated, releasing the system resource.

Exceptions:
NS_OKif the call succeeded and the directory was closed. NS_ERROR_FAILURE if the directory close failed. It is safe to call this function many times.

Definition at line 230 of file nsLocalFileOSX.cpp.

        {
          if (mIterator) {
            ::FSCloseIterator(mIterator);
            mIterator = nsnull;
          }
          if (mFSRefsArray) {
            nsMemory::Free(mFSRefsArray);
            mFSRefsArray = nsnull;
          }
          return NS_OK;
        }

Definition at line 367 of file nsLocalFileOS2.cpp.

        {
            if (mDir)
            {
                PRStatus status = PR_CloseDir(mDir);
                NS_ASSERTION(status == PR_SUCCESS, "close failed");
                if (status != PR_SUCCESS)
                    return NS_ERROR_FAILURE;
                mDir = nsnull;
            }
            return NS_OK;
        }

Here is the caller graph for this function:

Definition at line 745 of file nsLocalFileWin.cpp.

        {
            if (mDir)
            {
                nsresult rv = CloseDir(mDir);
                NS_ASSERTION(NS_SUCCEEDED(rv), "close failed");
                if (NS_FAILED(rv))
                    return NS_ERROR_FAILURE;
                mDir = nsnull;
            }
            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 nsDirEnumerator::GetNext ( nsISupports **  result) [inline]

Definition at line 200 of file nsLocalFileOSX.cpp.

        {
            NS_ENSURE_ARG_POINTER(result);
            *result = nsnull;

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

            *result = mNext;        // might return nsnull
            NS_IF_ADDREF(*result);

            mNext = nsnull;
            return NS_OK;
        }

Here is the call graph for this function:

NS_IMETHOD nsDirEnumerator::GetNext ( nsISupports **  result) [inline]

Definition at line 340 of file nsLocalFileOS2.cpp.

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

            *result = mNext;        // might return nsnull
            NS_IF_ADDREF(*result);

            mNext = nsnull;
            return NS_OK;
        }

Here is the call graph for this function:

NS_IMETHOD nsDirEnumerator::GetNext ( nsISupports **  result) [inline]

Definition at line 718 of file nsLocalFileWin.cpp.

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

            *result = mNext;        // might return nsnull
            NS_IF_ADDREF(*result);

            mNext = nsnull;
            return NS_OK;
        }

Here is the call graph for this function:

NS_IMETHOD nsDirEnumerator::GetNext ( nsISupports **  result) [inline]

Definition at line 888 of file nsLocalFileMac.cpp.

        {
            NS_ENSURE_ARG_POINTER(result);
            *result = nsnull;

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

            *result = mNext;        // might return nsnull
            NS_IF_ADDREF(*result);

            mNext = nsnull;
            ++mItemIndex;
            return NS_OK;
        }

Here is the caller graph for this function:

Definition at line 217 of file nsLocalFileOSX.cpp.

        {
            *result = nsnull;
            PRBool hasMore = PR_FALSE;
            nsresult rv = HasMoreElements(&hasMore);
            if (NS_FAILED(rv) || !hasMore)
                return rv;
            *result = mNext;
            NS_IF_ADDREF(*result);
            mNext = nsnull;
            return NS_OK;
        }

Here is the call graph for this function:

Definition at line 354 of file nsLocalFileOS2.cpp.

        {
            *result = nsnull;
            PRBool hasMore = PR_FALSE;
            nsresult rv = HasMoreElements(&hasMore);
            if (NS_FAILED(rv) || !hasMore)
                return rv;
            *result = mNext;
            NS_IF_ADDREF(*result);
            mNext = nsnull;
            return NS_OK;
        }

Here is the call graph for this function:

Definition at line 732 of file nsLocalFileWin.cpp.

        {
            *result = nsnull;
            PRBool hasMore = PR_FALSE;
            nsresult rv = HasMoreElements(&hasMore);
            if (NS_FAILED(rv) || !hasMore)
                return rv;
            *result = mNext;
            NS_IF_ADDREF(*result);
            mNext = nsnull;
            return NS_OK;
        }

Here is the call 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 163 of file nsLocalFileOSX.cpp.

        {
          if (mNext == nsnull) {
            if (mArrayIndex >= mArrayCnt) {
              ItemCount actualCnt;
              OSErr err = ::FSGetCatalogInfoBulk(mIterator,
                                           kRequestCountPerIteration,
                                           &actualCnt,
                                           nsnull,
                                           kFSCatInfoNone,
                                           nsnull,
                                           mFSRefsArray,
                                           nsnull,
                                           nsnull);
            
              if (err == noErr || err == errFSNoMoreItems) {
                mArrayCnt = actualCnt;
                mArrayIndex = 0;
              }
            }
            if (mArrayIndex < mArrayCnt) {
              nsLocalFile *newFile = new nsLocalFile;
              if (!newFile)
                return NS_ERROR_OUT_OF_MEMORY;
              FSRef fsRef = mFSRefsArray[mArrayIndex];
              if (NS_FAILED(newFile->InitWithFSRef(&fsRef)))
                return NS_ERROR_FAILURE;
              mArrayIndex++;
              mNext = newFile;
            } 
          }
          *result = mNext != nsnull;
          if (!*result)
            Close();
          return NS_OK;
        }

Here is the call graph for this function:

Definition at line 296 of file nsLocalFileOS2.cpp.

        {
            nsresult rv;
            if (mNext == nsnull && mDir)
            {
                PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH);
                if (entry == nsnull)
                {
                    // end of dir entries

                    PRStatus status = PR_CloseDir(mDir);
                    if (status != PR_SUCCESS)
                        return NS_ERROR_FAILURE;
                    mDir = nsnull;

                    *result = PR_FALSE;
                    return NS_OK;
                }

                nsCOMPtr<nsIFile> file;
                rv = mParent->Clone(getter_AddRefs(file));
                if (NS_FAILED(rv))
                    return rv;

                rv = file->AppendNative(nsDependentCString(entry->name));
                if (NS_FAILED(rv))
                    return rv;

                // make sure the thing exists.  If it does, try the next one.
                PRBool exists;
                rv = file->Exists(&exists);
                if (NS_FAILED(rv) || !exists)
                {
                    return HasMoreElements(result);
                }

                mNext = do_QueryInterface(file);
            }
            *result = mNext != nsnull;
            if (!*result)
                Close();
            return NS_OK;
        }

Here is the call graph for this function:

Definition at line 672 of file nsLocalFileWin.cpp.

        {
            nsresult rv;
            if (mNext == nsnull && mDir)
            {
                nsString name;
                rv = ReadDir(mDir, PR_SKIP_BOTH, name);
                if (NS_FAILED(rv))
                    return rv;
                if (name.IsEmpty()) 
                {
                    // end of dir entries
                    if (NS_FAILED(CloseDir(mDir)))
                        return NS_ERROR_FAILURE;

                    mDir = nsnull;

                    *result = PR_FALSE;
                    return NS_OK;
                }

                nsCOMPtr<nsIFile> file;
                rv = mParent->Clone(getter_AddRefs(file));
                if (NS_FAILED(rv))
                    return rv;

                rv = file->Append(name);
                if (NS_FAILED(rv))
                    return rv;

                // make sure the thing exists.  If it does, try the next one.
                PRBool exists;
                rv = file->Exists(&exists);
                if (NS_FAILED(rv) || !exists)
                {
                    return HasMoreElements(result);
                }

                mNext = do_QueryInterface(file);
            }
            *result = mNext != nsnull;
            if (!*result) 
                Close();
            return NS_OK;
        }

Here is the call graph for this function:

Definition at line 857 of file nsLocalFileMac.cpp.

        {
            nsresult rv = NS_OK;
            if (mNext == nsnull) 
            {
                mItemName[0] = 0;
                mCatInfo.dirInfo.ioFDirIndex = mItemIndex;
                mCatInfo.dirInfo.ioDrDirID = mDirID;
                
                OSErr err = ::PBGetCatInfoSync(&mCatInfo);
                if (err == fnfErr)
                {
                    // end of dir entries
                    *result = PR_FALSE;
                    return  NS_OK;
                }
                
                // Make a new nsILocalFile for the new element
                FSSpec  tempSpec;
                tempSpec.vRefNum = mCatInfo.hFileInfo.ioVRefNum;
                tempSpec.parID = mDirID;
                ::BlockMoveData(mItemName, tempSpec.name, mItemName[0] + 1);
                
                rv = NS_NewLocalFileWithFSSpec(&tempSpec, PR_TRUE, getter_AddRefs(mNext));
                if (NS_FAILED(rv)) 
                    return rv;
            }
            *result = mNext != nsnull;
            return NS_OK;
        }

Here is the caller graph for this function:

Definition at line 139 of file nsLocalFileOSX.cpp.

        {
          NS_ENSURE_ARG(parent);
          
          OSErr err;
          nsresult rv;
          FSRef parentRef;
          
          rv = parent->GetFSRef(&parentRef);
          if (NS_FAILED(rv))
            return rv;
          
          mFSRefsArray = (FSRef *)nsMemory::Alloc(sizeof(FSRef)
                                                  * kRequestCountPerIteration);
          if (!mFSRefsArray)
            return NS_ERROR_OUT_OF_MEMORY;
          
          err = ::FSOpenIterator(&parentRef, kFSIterateFlat, &mIterator);
          if (err != noErr)
            return MacErrorMapper(err);
                              
          return NS_OK;
        }

Here is the call graph for this function:

Definition at line 273 of file nsLocalFileOS2.cpp.

        {
            nsCAutoString filepath;
            parent->GetNativeTarget(filepath);

            if (filepath.IsEmpty())
            {
                parent->GetNativePath(filepath);
            }

            if (filepath.IsEmpty())
            {
                return NS_ERROR_UNEXPECTED;
            }

            mDir = PR_OpenDir(filepath.get());
            if (mDir == nsnull)    // not a directory?
                return NS_ERROR_FAILURE;

            mParent = parent;
            return NS_OK;
        }

Here is the call graph for this function:

Definition at line 649 of file nsLocalFileWin.cpp.

        {
            nsAutoString filepath;
            parent->GetTarget(filepath);

            if (filepath.IsEmpty())
            {
                parent->GetPath(filepath);
            }

            if (filepath.IsEmpty())
            {
                return NS_ERROR_UNEXPECTED;
            }

            nsresult rv = OpenDir(filepath, &mDir);
            if (NS_FAILED(rv))
                return rv;

            mParent = parent;
            return NS_OK;
        }

Here is the call graph for this function:

Definition at line 833 of file nsLocalFileMac.cpp.

        {
            NS_ENSURE_ARG(parent);
            nsresult rv;
            FSSpec fileSpec;

            rv = parent->GetFSSpec(&fileSpec);
            if (NS_FAILED(rv))
                return rv;

            OSErr err;
            Boolean isDirectory;
            
            err = ::FSpGetDirectoryID(&fileSpec, &mDirID, &isDirectory);
            if (err || !isDirectory)
                return NS_ERROR_FILE_NOT_DIRECTORY;
                            
            mCatInfo.hFileInfo.ioNamePtr = mItemName;
            mCatInfo.hFileInfo.ioVRefNum = fileSpec.vRefNum;
            mItemIndex = 1;
                    
            return NS_OK;
        }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 260 of file nsLocalFileOSX.cpp.

Definition at line 260 of file nsLocalFileOSX.cpp.

CInfoPBRec nsDirEnumerator::mCatInfo [protected]

Definition at line 912 of file nsLocalFileMac.cpp.

Definition at line 388 of file nsLocalFileOS2.cpp.

Definition at line 766 of file nsLocalFileWin.cpp.

Definition at line 914 of file nsLocalFileMac.cpp.

Definition at line 259 of file nsLocalFileOSX.cpp.

short nsDirEnumerator::mItemIndex [protected]

Definition at line 913 of file nsLocalFileMac.cpp.

Str63 nsDirEnumerator::mItemName [protected]

Definition at line 915 of file nsLocalFileMac.cpp.

FSIterator nsDirEnumerator::mIterator [protected]

Definition at line 258 of file nsLocalFileOSX.cpp.

Definition at line 390 of file nsLocalFileOS2.cpp.

Definition at line 910 of file nsLocalFileMac.cpp.

Definition at line 389 of file nsLocalFileOS2.cpp.

Retrieves the next file in the sequence.

The "nextFile" element is the first element upon the first call. This attribute is null if there is no next element.

Definition at line 58 of file nsIDirectoryEnumerator.idl.


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