sbuild  1.7.1
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
sbuild::mntstream Class Reference

Access mounts. More...

#include <mntstream.h>

+ Collaboration diagram for sbuild::mntstream:

Classes

struct  mntentry
 An entry in a mntstream. More...
 

Public Types

enum  error_code { MNT_OPEN, MNT_READ }
 Error codes. More...
 
typedef sbuild::custom_error
< error_code
error
 Exception type.
 

Public Member Functions

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

Private Member Functions

void read (int quantity=1)
 Read mntents from the underlying FILE stream into the data deque. More...
 

Private Attributes

std::string file
 The file name.
 
FILE * mntfile
 The underlying FILE stream.
 
std::deque< mntentrydata
 A list of mntentries represents the mount file stream as a LIFO stack.
 
bool error_status
 Error status.
 
bool eof_status
 End of File status.
 

Friends

mntstreamoperator>> (mntstream &stream, mntentry &entry)
 The overloaded extraction operator. More...
 

Detailed Description

Access mounts.

This is a wrapper around the setmntent(3), getmntent(3) and endmntent(3) functions, which are used to read a stream of "mntents" through multiple getmntent() calls.

mntstream calls setmntent() and endmntent() automatically, and represents each mntent as a mntstream::mntentry. Like reading from and istream by pulling data out with the >> "extraction operator", mntentries are also extracted from the mntstream with the >> operator.

Member Enumeration Documentation

Error codes.

Enumerator
MNT_OPEN 

Failed to open mount file.

MNT_READ 

Failed to read mount file.

Constructor & Destructor Documentation

sbuild::mntstream::mntstream ( const std::string &  file)

The constructor.

Parameters
filethe file to read.

References open().

Member Function Documentation

bool sbuild::mntstream::bad ( ) const

Check for errors.

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

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

References error_status.

Referenced by operator!().

+ Here is the caller graph for this function:

void sbuild::mntstream::close ( )

Close the mount file.

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

See Also
open()

References data, eof_status, error_status, file, and mntfile.

Referenced by ~mntstream().

+ Here is the caller graph for this function:

bool sbuild::mntstream::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 mntstream is empty, otherwise false.

References eof_status.

Referenced by operator!().

+ Here is the caller graph for this function:

void sbuild::mntstream::open ( const std::string &  file)

Open a mount file for reading.

This uses the openmnt(3) call to open the underlying FILE stream. Any previously open mount file is closed before opening the new one. The mntstream error state is set if the open fails, and an exception will be thrown.

Parameters
filethe file to read.
See Also
close()

References eof_status, error_status, file, MNT_OPEN, mntfile, and read().

Referenced by mntstream().

+ Here is the caller graph for this function:

sbuild::mntstream::operator bool ( )

Check if the mntstream status is good.

Returns
true if the status is good (eof() and bad() both return false).
bool sbuild::mntstream::operator! ( )

Check if the mntstream status is bad.

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

References bad(), and eof().

void sbuild::mntstream::read ( int  quantity = 1)
private

Read mntents from the underlying FILE stream into the data deque.

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

Parameters
quantitythe number of mntents to read.
Todo:
Add mntentry constructor to do automatic struct mntent to mntentry conversion.

References data, error_status, file, MNT_READ, and mntfile.

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

+ Here is the caller graph for this function:

Friends And Related Function Documentation

mntstream& operator>> ( mntstream stream,
mntentry entry 
)
friend

The overloaded extraction operator.

This is used to pull mntentries from a mntstream.

Parameters
streamthe mntstream to get input from.
entrythe mntentry to set.
Returns
the mntstream.

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