Used in combination with shared_ptr to reference count open file descriptors. More...
#include <sg_FD.hpp>
Public Member Functions | |
FD (const int i=-1) | |
Constructor. Optionally takes an existing open file descriptor. More... | |
FD (const std::string &filename) | |
Constructor. Requires the name of the file to be opened. File is opened in read-write mode. More... | |
FD (const std::string &filename, const int mode) | |
Constructor. Requires the name of the file to be opened and the mode (O_RDONLY, O_WRONLY, O_RDWR). More... | |
FD (const bool throw_on_error, const std::string &filename, const int mode) | |
Constructor. Can be explicitly told to throw or not throw if the filename doesn't exist or cannot be opened. More... | |
~FD (void) | |
Destructor. More... | |
bool | is_valid (void) const |
Determine if the file handle is valid. More... | |
Public Attributes | |
int | fd |
File descriptor. More... | |
Used in combination with shared_ptr to reference count open file descriptors.
This ensures that the file handle isn't prematurely closed when shared between different objects. For example, in objects that derive from SG::GroveI2CDigital, the open file handle to /dev/i2c-1
may be shared between several objects and must not be closed until the last object goes out of scope.
SG::FD::FD | ( | const int | i = -1 | ) |
Constructor. Optionally takes an existing open file descriptor.
SG::FD::FD | ( | const std::string & | filename | ) |
Constructor. Requires the name of the file to be opened. File is opened in read-write mode.
SG::FD::FD | ( | const std::string & | filename, |
const int | mode | ||
) |
Constructor. Requires the name of the file to be opened and the mode (O_RDONLY, O_WRONLY, O_RDWR).
SG::FD::FD | ( | const bool | throw_on_error, |
const std::string & | filename, | ||
const int | mode | ||
) |
Constructor. Can be explicitly told to throw or not throw if the filename doesn't exist or cannot be opened.
std::invalid_argument | if the file does not exist. |
std::system_error | if the file cannot be opened for the given read/write access mode. |
References fd, and SG::file_does_not_exist().
SG::FD::~FD | ( | void | ) |
Destructor.
References fd.
|
inline |
Determine if the file handle is valid.
References fd.
int SG::FD::fd |
File descriptor.
Referenced by FD(), is_valid(), and ~FD().