Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Dirent Class Reference

Define a portable C++ directory-entry iterator based on the POSIX API. More...

#include <Dirent.h>

List of all members.

Public Methods

 ACE_Dirent (void)
 Default constructor. More...

ACE_EXPLICIT ACE_Dirent (const ACE_TCHAR *dirname)
 Constructor calls <opendir>. More...

int open (const ACE_TCHAR *filename)
 Opens the directory named by filename and associates a directory stream with it. More...

 ~ACE_Dirent (void)
 Destructor calls <closedir>. More...

void close (void)
 Closes the directory stream and frees the <ACE_DIR> structure. More...

direntread (void)
int read (struct dirent *entry, struct dirent **result)
long tell (void)
 Returns the current location associated with the directory stream. More...

void seek (long loc)
void rewind (void)

Private Attributes

ACE_DIRdirp_
 Pointer to the directory stream. More...


Detailed Description

Define a portable C++ directory-entry iterator based on the POSIX API.

Definition at line 33 of file Dirent.h.


Constructor & Destructor Documentation

ACE_INLINE ACE_Dirent::ACE_Dirent void   
 

Default constructor.

Definition at line 27 of file Dirent.i.

00028   : dirp_ (0)
00029 {
00030 }

ACE_INLINE ACE_Dirent::ACE_Dirent const ACE_TCHAR   dirname
 

Constructor calls <opendir>.

Definition at line 33 of file Dirent.i.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, LM_ERROR, and open.

00034   : dirp_ (0)
00035 {
00036   if (this->open (dirname) == -1)
00037     ACE_ERROR ((LM_ERROR,
00038                 ACE_LIB_TEXT ("%p\n"), 
00039                 ACE_LIB_TEXT ("Dirent::Dirent")));
00040 }

ACE_INLINE ACE_Dirent::~ACE_Dirent void   
 

Destructor calls <closedir>.

Definition at line 43 of file Dirent.i.

References ACE_OS_Dirent::closedir, and dirp_.

00044 {
00045   if (this->dirp_ != 0)
00046     ACE_OS_Dirent::closedir (this->dirp_);
00047 }


Member Function Documentation

ACE_INLINE void ACE_Dirent::close void   
 

Closes the directory stream and frees the <ACE_DIR> structure.

Definition at line 65 of file Dirent.i.

References ACE_OS_Dirent::closedir, and dirp_.

00066 {
00067   if (this->dirp_ != 0) 
00068     {
00069       ACE_OS_Dirent::closedir (this->dirp_);
00070 
00071       // Prevent double closure
00072       this->dirp_ = 0;
00073     }
00074 }

ACE_INLINE int ACE_Dirent::open const ACE_TCHAR   filename
 

Opens the directory named by filename and associates a directory stream with it.

Definition at line 7 of file Dirent.i.

References ACE_TCHAR, ACE_OS_Dirent::closedir, dirp_, and ACE_OS_Dirent::opendir.

Referenced by ACE_Dirent.

00008 {
00009   // If the directory stream is already open, close it to prevent
00010   // possible resource leaks.
00011 
00012   if (this->dirp_ != 0) 
00013     {
00014       ACE_OS_Dirent::closedir (this->dirp_);
00015       this->dirp_ = 0;
00016     }
00017 
00018   this->dirp_ = ACE_OS_Dirent::opendir (dirname);
00019 
00020   if (this->dirp_ == 0)
00021     return -1;
00022   else
00023     return 0;
00024 }

ACE_INLINE int ACE_Dirent::read struct dirent   entry,
struct dirent **    result
 

Has the equivalent functionality as <readdir> except that an <entry> and <result> buffer must be supplied by the caller to store the result.

Definition at line 56 of file Dirent.i.

References dirp_, and ACE_OS_Dirent::readdir_r.

00058 {
00059   return this->dirp_
00060          ? ACE_OS_Dirent::readdir_r (this->dirp_, entry, result)
00061          : 0;
00062 }

ACE_INLINE dirent * ACE_Dirent::read void   
 

Returns a pointer to a structure representing the directory entry at the current position in the directory stream to which dirp refers, and positions the directory stream at the next entry, except on read-only filesystems. It returns a NULL pointer upon reaching the end of the directory stream, or upon detecting an invalid location in the directory. <readdir> shall not return directory entries containing empty names. It is unspecified whether entries are returned for dot or dot-dot. The pointer returned by <readdir> points to data that may be overwritten by another call to <readdir> on the same directory stream. This data shall not be overwritten by another call to <readdir> on a different directory stream. <readdir> may buffer several directory entries per actual read operation; <readdir> marks for update the st_atime field of the directory each time the directory is actually read.

Definition at line 50 of file Dirent.i.

References dirp_, and ACE_OS_Dirent::readdir.

00051 {
00052   return this->dirp_ ? ACE_OS_Dirent::readdir (this->dirp_) : 0;
00053 }

ACE_INLINE void ACE_Dirent::rewind void   
 

Resets the position of the directory stream to the beginning of the directory. It also causes the directory stream to refer to the current state of the corresponding directory, as a call to <opendir> would.

Definition at line 77 of file Dirent.i.

References dirp_, and ACE_OS_Dirent::rewinddir.

00078 {
00079   if (this->dirp_)
00080     ACE_OS_Dirent::rewinddir (this->dirp_);
00081 }

ACE_INLINE void ACE_Dirent::seek long    loc
 

Sets the position of the next <readdir> operation on the directory stream. The new position reverts to the position associated with the directory stream at the time the <telldir> operation that provides loc was performed. Values returned by <telldir> are good only for the lifetime of the <ACE_DIR> pointer from which they are derived. If the directory is closed and then reopened, the <telldir> value may be invalidated due to undetected directory compaction. It is safe to use a previous <telldir> value immediately after a call to <opendir> and before any calls to readdir.

Definition at line 84 of file Dirent.i.

References dirp_, and ACE_OS_Dirent::seekdir.

00085 {
00086   if (this->dirp_)
00087     ACE_OS_Dirent::seekdir (this->dirp_, loc);
00088 }

ACE_INLINE long ACE_Dirent::tell void   
 

Returns the current location associated with the directory stream.

Definition at line 91 of file Dirent.i.

References dirp_, and ACE_OS_Dirent::telldir.

00092 {
00093   return this->dirp_ ? ACE_OS_Dirent::telldir (this->dirp_) : 0;
00094 }


Member Data Documentation

ACE_DIR* ACE_Dirent::dirp_ [private]
 

Pointer to the directory stream.

Definition at line 110 of file Dirent.h.

Referenced by close, open, read, rewind, seek, tell, and ~ACE_Dirent.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:47:13 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002