A wrapper for an UNIX-style integer file descriptor.
More...
#include <FileDescriptor.h>
A wrapper for an UNIX-style integer file descriptor.
Allows callers to implement RAII-style resource management.
§ FileDescriptor() [1/2]
SurgSim::Devices::FileDescriptor::FileDescriptor |
( |
| ) |
|
Default constructor.
Initializes the file descriptor to an invalid state.
§ FileDescriptor() [2/2]
SurgSim::Devices::FileDescriptor::FileDescriptor |
( |
FileDescriptor && |
other | ) |
|
Move constructor.
- Parameters
-
[in,out] | other | The object to move. The original object will be invalidated. |
§ canRead()
bool SurgSim::Devices::FileDescriptor::canRead |
( |
| ) |
const |
Determines if the file descriptor can be read from.
- Returns
- true if the descriptor has been open for reading.
§ canWrite()
bool SurgSim::Devices::FileDescriptor::canWrite |
( |
| ) |
const |
Determines if the file descriptor can be written to.
- Returns
- true if the descriptor has been open for writing.
§ get()
int SurgSim::Devices::FileDescriptor::get |
( |
| ) |
const |
Gets the raw underlying OS file descriptor.
- Returns
- The raw file descriptor.
§ hasDataToRead()
bool SurgSim::Devices::FileDescriptor::hasDataToRead |
( |
| ) |
const |
Checks whether this object has data available to be read.
- Returns
- true if there is data currently available.
§ isValid()
bool SurgSim::Devices::FileDescriptor::isValid |
( |
| ) |
const |
Checks if the file descriptor is valid, i.e.
has been opened.
- Returns
- true if valid, false if not.
§ openForReading()
bool SurgSim::Devices::FileDescriptor::openForReading |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for reading only.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
§ openForReadingAndMaybeWriting()
bool SurgSim::Devices::FileDescriptor::openForReadingAndMaybeWriting |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for reading and (if permissions allow it) writing.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
§ openForReadingAndWriting()
bool SurgSim::Devices::FileDescriptor::openForReadingAndWriting |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for reading and writing.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
§ openForWriting()
bool SurgSim::Devices::FileDescriptor::openForWriting |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for writing only.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
§ operator=()
Move assignment operator.
- Parameters
-
[in,out] | other | The object to move. The original object will be invalidated. |
- Returns
- A reference to this object.
§ readBytes()
bool SurgSim::Devices::FileDescriptor::readBytes |
( |
void * |
dataBuffer, |
|
|
size_t |
bytesToRead, |
|
|
size_t * |
bytesActuallyRead |
|
) |
| |
Reads bytes from the file descriptor.
- Parameters
-
[out] | dataBuffer | Buffer to read into. Must have room for at least bytesToRead bytes of data. |
| bytesToRead | The number of bytes to try reading. Actual number of bytes received may be smaller. |
[out] | bytesActuallyRead | The number of bytes that were actually read into the buffer. |
- Returns
- true if it succeeds, false if it fails.
§ reset()
void SurgSim::Devices::FileDescriptor::reset |
( |
| ) |
|
Resets the file descriptor back to an invalid state.
If the descriptor was open, it will be closed.
The documentation for this class was generated from the following files:
- SurgSim/Devices/MultiAxis/linux/FileDescriptor.h
- SurgSim/Devices/MultiAxis/linux/FileDescriptor.cpp