sbuild::dirstream Class Reference

Access directories. More...

#include <sbuild-dirstream.h>

Collaboration diagram for sbuild::dirstream:

Collaboration graph
[legend]
List of all members.

Public Types

enum  error_code { DIR_OPEN, DIR_READ }
 Error codes. More...
typedef custom_error< error_codeerror
 Exception type.

Public Member Functions

 dirstream (std::string const &dir)
 The constructor.
virtual ~dirstream ()
 The destructor.
void open (std::string const &dirname)
 Open a directory for reading.
void close ()
 Close the directory.
bool eof () const
 Check for End Of File.
bool bad () const
 Check for errors.
 operator bool ()
 Check if the dirstream status is good.
bool operator! ()
 Check if the dirstream status is bad.

Private Member Functions

void read (int quantity=1)
 Read dirents from the underlying DIR stream into the data deque.

Private Attributes

std::string dirname
 The directory name.
DIR * dir
 The underlying DIR stream.
std::deque< direntrydata
 A list of direntries represents the directory stream as a LIFO stack.
bool error_status
 Error status.
bool eof_status
 End of File status.

Friends

dirstreamoperator>> (dirstream &stream, direntry &entry)
 The overloaded extraction operator.

Detailed Description

Access directories.

This is a wrapper around the opendir(3), readdir(3) and closedir(3) functions, which are used to read a stream of "dirents" through multiple readdir() calls.

dirstream calls opendir() and closedir() automatically, and represents each dirent as a dirstream::direntry. Like reading from and istream by pulling data out with the >> "extraction operator", direntries are also extracted from the dirstream with the >> operator.

Definition at line 116 of file sbuild-dirstream.h.


Member Typedef Documentation

typedef custom_error<error_code> sbuild::dirstream::error

Exception type.

Definition at line 127 of file sbuild-dirstream.h.


Member Enumeration Documentation

enum sbuild::dirstream::error_code

Error codes.

Enumerator:
DIR_OPEN  Failed to open directory.
DIR_READ  Failed to read directory.

Definition at line 120 of file sbuild-dirstream.h.


Constructor & Destructor Documentation

dirstream::dirstream ( std::string const &  dir  ) 

The constructor.

Parameters:
dir the directory to read.

Definition at line 55 of file sbuild-dirstream.cc.

References open().

Here is the call graph for this function:

dirstream::~dirstream (  )  [virtual]

The destructor.

Definition at line 66 of file sbuild-dirstream.cc.

References close().

Here is the call graph for this function:


Member Function Documentation

void dirstream::open ( std::string const &  dirname  ) 

Open a directory for reading.

This uses the opendir(3) call to open the underlying DIR stream. Any previously open directory is closed before opening the new one. The dirstream error state is set if the open fails, and an exception will be thrown.

Parameters:
dirname the directory to read.
See also:
close()

Definition at line 72 of file sbuild-dirstream.cc.

References dir, DIR_OPEN, eof_status, error_status, and read().

Referenced by dirstream().

Here is the call graph for this function:

Here is the caller graph for this function:

void dirstream::close (  ) 

Close the directory.

This uses the closedir(3) call to close the underlying DIR stream. All cached data is deleted and the error state set until open() is called.

See also:
open()

Definition at line 119 of file sbuild-dirstream.cc.

References data, dir, dirname, eof_status, and error_status.

Referenced by ~dirstream().

Here is the caller graph for this function:

bool dirstream::eof (  )  const

Check for End Of File.

Note that the end of file status is only set adter a read fails, so this should be checked after each read.

Returns:
true if the dirstream is empty, otherwise false.

Definition at line 133 of file sbuild-dirstream.cc.

References eof_status.

Referenced by operator bool(), and operator!().

Here is the caller graph for this function:

bool dirstream::bad (  )  const

Check for errors.

If there is an error, the dirstream is unusable until the next open() call.

Returns:
true if the dirstream is in an error state, otherwise false.

Definition at line 139 of file sbuild-dirstream.cc.

References error_status.

Referenced by operator bool(), and operator!().

Here is the caller graph for this function:

sbuild::dirstream::operator bool (  ) 

Check if the dirstream status is good.

Returns:
true if the status is good (eof() and bad() both return false).

Definition at line 144 of file sbuild-dirstream.cc.

References bad(), and eof().

Here is the call graph for this function:

bool sbuild::dirstream::operator! (  ) 

Check if the dirstream status is bad.

Returns:
true if the status is bad (eof() or bad() return true).

Definition at line 150 of file sbuild-dirstream.cc.

References bad(), and eof().

Here is the call graph for this function:

void dirstream::read ( int  quantity = 1  )  [private]

Read dirents from the underlying DIR stream into the data deque.

If the read fails, the error state will be set, and an exception will be thrown.

Parameters:
quantity the number of dirents to read.

Definition at line 89 of file sbuild-dirstream.cc.

References data, dir, DIR_READ, and error_status.

Referenced by open(), and sbuild::operator>>().

Here is the caller graph for this function:


Friends And Related Function Documentation

dirstream& operator>> ( dirstream stream,
direntry entry 
) [friend]

The overloaded extraction operator.

This is used to pull direntries from a dirstream.

Parameters:
stream the dirstream to get input from.
entry the direntry to set.
Returns:
the dirstream.

Definition at line 157 of file sbuild-dirstream.cc.


Member Data Documentation

std::string sbuild::dirstream::dirname [private]

The directory name.

Definition at line 209 of file sbuild-dirstream.h.

Referenced by close().

DIR* sbuild::dirstream::dir [private]

The underlying DIR stream.

Definition at line 212 of file sbuild-dirstream.h.

Referenced by close(), open(), and read().

std::deque<direntry> sbuild::dirstream::data [private]

A list of direntries represents the directory stream as a LIFO stack.

Definition at line 218 of file sbuild-dirstream.h.

Referenced by close(), sbuild::operator>>(), and read().

bool sbuild::dirstream::error_status [private]

Error status.

Definition at line 221 of file sbuild-dirstream.h.

Referenced by bad(), close(), open(), and read().

bool sbuild::dirstream::eof_status [private]

End of File status.

Definition at line 224 of file sbuild-dirstream.h.

Referenced by close(), eof(), open(), and sbuild::operator>>().


The documentation for this class was generated from the following files:
Generated on Sat Jan 27 16:14:03 2007 for schroot by  doxygen 1.5.1