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 Member Functions

 ACE_Dirent (void)
 Default constructor.

 ACE_Dirent (const ACE_TCHAR *dirname)
 Constructor calls .

int open (const ACE_TCHAR *filename)
 ~ACE_Dirent (void)
 Destructor calls .

void close (void)
 Closes the directory stream and frees the structure.

ACE_DIRENT * read (void)
int read (struct ACE_DIRENT *entry, struct ACE_DIRENT **result)
long tell (void)
void seek (long loc)
void rewind (void)

Private Attributes

ACE_DIRdirp_
 Pointer to the directory stream.


Detailed Description

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

Definition at line 35 of file Dirent.h.


Constructor & Destructor Documentation

ACE_INLINE ACE_Dirent::ACE_Dirent void   ) 
 

Default constructor.

Definition at line 30 of file Dirent.inl.

00031   : dirp_ (0)
00032 {
00033 }

ACE_INLINE ACE_Dirent::ACE_Dirent const ACE_TCHAR dirname  )  [explicit]
 

Constructor calls .

Definition at line 36 of file Dirent.inl.

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

00037   : dirp_ (0)
00038 {
00039   if (this->open (dirname) == -1)
00040     ACE_ERROR ((LM_ERROR,
00041                 ACE_LIB_TEXT ("%p\n"),
00042                 ACE_LIB_TEXT ("ACE_Dirent::ACE_Dirent")));
00043 }

ACE_INLINE ACE_Dirent::~ACE_Dirent void   ) 
 

Destructor calls .

Definition at line 46 of file Dirent.inl.

References ACE_OS::closedir(), and dirp_.

00047 {
00048   if (this->dirp_ != 0)
00049     ACE_OS::closedir (this->dirp_);
00050 }


Member Function Documentation

ACE_INLINE void ACE_Dirent::close void   ) 
 

Closes the directory stream and frees the structure.

Definition at line 68 of file Dirent.inl.

References ACE_OS::closedir(), and dirp_.

00069 {
00070   if (this->dirp_ != 0)
00071     {
00072       ACE_OS::closedir (this->dirp_);
00073 
00074       // Prevent double closure
00075       this->dirp_ = 0;
00076     }
00077 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL 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 10 of file Dirent.inl.

References ACE_TCHAR, ACE_OS::closedir(), dirp_, and ACE_OS::opendir().

Referenced by ACE_Dirent().

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

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

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

Definition at line 59 of file Dirent.inl.

References dirp_, and ACE_OS::readdir_r().

00061 {
00062   return this->dirp_
00063          ? ACE_OS::readdir_r (this->dirp_, entry, result)
00064          : 0;
00065 }

ACE_INLINE ACE_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. shall not return directory entries containing empty names. It is unspecified whether entries are returned for dot or dot-dot. The pointer returned by points to data that may be overwritten by another call to on the same directory stream. This data shall not be overwritten by another call to on a different directory stream. may buffer several directory entries per actual read operation; marks for update the st_atime field of the directory each time the directory is actually read.

Definition at line 53 of file Dirent.inl.

References dirp_, and ACE_OS::readdir().

00054 {
00055   return this->dirp_ ? ACE_OS::readdir (this->dirp_) : 0;
00056 }

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 would.

Definition at line 80 of file Dirent.inl.

References dirp_, and ACE_OS::rewinddir().

00081 {
00082   if (this->dirp_)
00083     ACE_OS::rewinddir (this->dirp_);
00084 }

ACE_INLINE void ACE_Dirent::seek long  loc  ) 
 

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

Definition at line 87 of file Dirent.inl.

References dirp_, and ACE_OS::seekdir().

00088 {
00089   if (this->dirp_)
00090     ACE_OS::seekdir (this->dirp_, loc);
00091 }

ACE_INLINE long ACE_Dirent::tell void   ) 
 

Returns the current location associated with the directory stream.

Definition at line 94 of file Dirent.inl.

References dirp_, and ACE_OS::telldir().

00095 {
00096   return this->dirp_ ? ACE_OS::telldir (this->dirp_) : 0;
00097 }


Member Data Documentation

ACE_DIR* ACE_Dirent::dirp_ [private]
 

Pointer to the directory stream.

Definition at line 112 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 Thu Nov 9 11:21:36 2006 for ACE by doxygen 1.3.6