All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
SurgSim::Device::FileHandle Class Reference

A wrapper for an Windows-style HANDLE file descriptor. More...

#include <SurgSim/Devices/MultiAxis/win32/FileHandle.h>

Public Types

typedef void * RawHandleType
 Type of the raw handle used by the operating system. More...
 

Public Member Functions

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

Private Member Functions

 FileHandle (const FileHandle &other)
 
FileHandleoperator= (const FileHandle &other)
 

Private Attributes

RawHandleType m_handle
 
bool m_canRead
 
bool m_canWrite
 
uint64_t m_openFlags
 

Detailed Description

A wrapper for an Windows-style HANDLE file descriptor.

Allows callers to implement RAII-style resource management.

Member Typedef Documentation

Type of the raw handle used by the operating system.

Defined this way to avoid including <windows.h> just for the sake of defining HANDLE.

Constructor & Destructor Documentation

SurgSim::Device::FileHandle::FileHandle ( )

Default constructor.

Initializes the file handle to an invalid state.

SurgSim::Device::FileHandle::FileHandle ( FileHandle &&  other)

Move constructor.

Parameters
[in,out]otherThe object to move. The original object will be invalidated.
SurgSim::Device::FileHandle::~FileHandle ( )

Destructor.

SurgSim::Device::FileHandle::FileHandle ( const FileHandle other)
private

Member Function Documentation

bool SurgSim::Device::FileHandle::canRead ( ) const

Determines if the file handle can be read from.

Returns
true if the handle has been open for reading.
bool SurgSim::Device::FileHandle::canWrite ( ) const

Determines if the file handle can be written to.

Returns
true if the handle has been open for writing.
FileHandle::RawHandleType SurgSim::Device::FileHandle::get ( ) const

Gets the raw underlying OS file handle.

Returns
The raw file handle.
uint64_t SurgSim::Device::FileHandle::getFileOpenFlags ( ) const

Gets the flags that will be passed to CreateFile when opening the file.

Returns
The value passed to setFileOpenFlags (or if never set, a default value).
bool SurgSim::Device::FileHandle::hasDataToRead ( ) const

Checks whether this object has data available to be read.

Returns
true if there is data currently available.
bool SurgSim::Device::FileHandle::isValid ( ) const

Checks if the file handle is valid, i.e.

has been opened.

Returns
true if valid, false if not.
bool SurgSim::Device::FileHandle::openForReading ( const std::string &  path)

Attempts to open the file handle for reading only.

Parameters
pathFull pathname of the file.
Returns
true if it succeeds, false if it fails.
bool SurgSim::Device::FileHandle::openForReadingAndMaybeWriting ( const std::string &  path)

Attempts to open the file handle for reading and (if permissions allow it) writing.

Parameters
pathFull pathname of the file.
Returns
true if it succeeds, false if it fails.
bool SurgSim::Device::FileHandle::openForReadingAndWriting ( const std::string &  path)

Attempts to open the file handle for reading and writing.

Parameters
pathFull pathname of the file.
Returns
true if it succeeds, false if it fails.
bool SurgSim::Device::FileHandle::openForWriting ( const std::string &  path)

Attempts to open the file handle for writing only.

Parameters
pathFull pathname of the file.
Returns
true if it succeeds, false if it fails.
FileHandle & SurgSim::Device::FileHandle::operator= ( FileHandle &&  other)

Move assignment operator.

Parameters
[in,out]otherThe object to move. The original object will be invalidated.
Returns
A reference to this object.
FileHandle& SurgSim::Device::FileHandle::operator= ( const FileHandle other)
private
bool SurgSim::Device::FileHandle::readBytes ( void *  dataBuffer,
unsigned int  bytesToRead,
unsigned int *  bytesActuallyRead 
)

Reads bytes from the file handle.

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.
void SurgSim::Device::FileHandle::reset ( )

Resets the file handle back to an invalid state.

If the handle was open, it will be closed.

void SurgSim::Device::FileHandle::setFileOpenFlags ( uint64_t  flags)

Sets the flags that will be passed to CreateFile when opening the file.

Parameters
flagsThe flags, a combination of zero or more Windows FILE_FLAG_* flags.

Member Data Documentation

bool SurgSim::Device::FileHandle::m_canRead
private
bool SurgSim::Device::FileHandle::m_canWrite
private
RawHandleType SurgSim::Device::FileHandle::m_handle
private
uint64_t SurgSim::Device::FileHandle::m_openFlags
private

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