opensurgsim
Public Member Functions | List of all members
SurgSim::Devices::FileDescriptor Class Reference

A wrapper for an UNIX-style integer file descriptor. More...

#include <FileDescriptor.h>

Public Member Functions

 FileDescriptor ()
 Default constructor. More...
 
 FileDescriptor (FileDescriptor &&other)
 Move constructor. More...
 
FileDescriptoroperator= (FileDescriptor &&other)
 Move assignment operator. More...
 
 ~FileDescriptor ()
 Destructor.
 
bool isValid () const
 Checks if the file descriptor is valid, i.e. More...
 
bool canRead () const
 Determines if the file descriptor can be read from. More...
 
bool canWrite () const
 Determines if the file descriptor can be written to. More...
 
bool hasDataToRead () const
 Checks whether this object has data available to be read. More...
 
bool readBytes (void *dataBuffer, size_t bytesToRead, size_t *bytesActuallyRead)
 Reads bytes from the file descriptor. More...
 
int get () const
 Gets the raw underlying OS file descriptor. More...
 
bool openForReadingAndWriting (const std::string &path)
 Attempts to open the file descriptor for reading and writing. More...
 
bool openForReading (const std::string &path)
 Attempts to open the file descriptor for reading only. More...
 
bool openForWriting (const std::string &path)
 Attempts to open the file descriptor for writing only. More...
 
bool openForReadingAndMaybeWriting (const std::string &path)
 Attempts to open the file descriptor for reading and (if permissions allow it) writing. More...
 
void reset ()
 Resets the file descriptor back to an invalid state. More...
 

Detailed Description

A wrapper for an UNIX-style integer file descriptor.

Allows callers to implement RAII-style resource management.

Constructor & Destructor Documentation

§ 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]otherThe object to move. The original object will be invalidated.

Member Function Documentation

§ 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
pathFull 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
pathFull 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
pathFull 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
pathFull pathname of the file.
Returns
true if it succeeds, false if it fails.

§ operator=()

FileDescriptor & SurgSim::Devices::FileDescriptor::operator= ( FileDescriptor &&  other)

Move assignment operator.

Parameters
[in,out]otherThe 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]dataBufferBuffer to read into. Must have room for at least bytesToRead bytes of data.
bytesToReadThe number of bytes to try reading. Actual number of bytes received may be smaller.
[out]bytesActuallyReadThe 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: