Seeed Grove ++  v0.0.1-2019
Linux C++ Library For Seeed Grove Devices
SG::FD Class Referencefinal

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

Detailed Description

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.

Constructor & Destructor Documentation

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.

Exceptions
std::invalid_argumentif the file does not exist.
std::system_errorif the file cannot be opened for the given read/write access mode.

References fd, and SG::file_does_not_exist().

Here is the call graph for this function:

SG::FD::~FD ( void  )

Destructor.

References fd.

Member Function Documentation

bool SG::FD::is_valid ( void  ) const
inline

Determine if the file handle is valid.

References fd.

Member Data Documentation

int SG::FD::fd

File descriptor.

Referenced by FD(), is_valid(), and ~FD().


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