|
opensurgsim
|
A wrapper for an Windows-style HANDLE file descriptor. More...
#include <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... | |
| FileHandle & | operator= (FileHandle &&other) |
| Move assignment operator. More... | |
| ~FileHandle () | |
| Destructor. | |
| 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... | |
A wrapper for an Windows-style HANDLE file descriptor.
Allows callers to implement RAII-style resource management.
| typedef void* SurgSim::Devices::FileHandle::RawHandleType |
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.
| SurgSim::Devices::FileHandle::FileHandle | ( | ) |
Default constructor.
Initializes the file handle to an invalid state.
| SurgSim::Devices::FileHandle::FileHandle | ( | FileHandle && | other | ) |
Move constructor.
| [in,out] | other | The object to move. The original object will be invalidated. |
| bool SurgSim::Devices::FileHandle::canRead | ( | ) | const |
Determines if the file handle can be read from.
| bool SurgSim::Devices::FileHandle::canWrite | ( | ) | const |
Determines if the file handle can be written to.
| FileHandle::RawHandleType SurgSim::Devices::FileHandle::get | ( | ) | const |
Gets the raw underlying OS file handle.
| uint64_t SurgSim::Devices::FileHandle::getFileOpenFlags | ( | ) | const |
Gets the flags that will be passed to CreateFile when opening the file.
| bool SurgSim::Devices::FileHandle::hasDataToRead | ( | ) | const |
Checks whether this object has data available to be read.
| bool SurgSim::Devices::FileHandle::isValid | ( | ) | const |
Checks if the file handle is valid, i.e.
has been opened.
| bool SurgSim::Devices::FileHandle::openForReading | ( | const std::string & | path | ) |
Attempts to open the file handle for reading only.
| path | Full pathname of the file. |
| bool SurgSim::Devices::FileHandle::openForReadingAndMaybeWriting | ( | const std::string & | path | ) |
Attempts to open the file handle for reading and (if permissions allow it) writing.
| path | Full pathname of the file. |
| bool SurgSim::Devices::FileHandle::openForReadingAndWriting | ( | const std::string & | path | ) |
Attempts to open the file handle for reading and writing.
| path | Full pathname of the file. |
| bool SurgSim::Devices::FileHandle::openForWriting | ( | const std::string & | path | ) |
Attempts to open the file handle for writing only.
| path | Full pathname of the file. |
| FileHandle & SurgSim::Devices::FileHandle::operator= | ( | FileHandle && | other | ) |
Move assignment operator.
| [in,out] | other | The object to move. The original object will be invalidated. |
| bool SurgSim::Devices::FileHandle::readBytes | ( | void * | dataBuffer, |
| unsigned int | bytesToRead, | ||
| unsigned int * | bytesActuallyRead | ||
| ) |
Reads bytes from the file handle.
| [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. |
| void SurgSim::Devices::FileHandle::reset | ( | ) |
Resets the file handle back to an invalid state.
If the handle was open, it will be closed.
| void SurgSim::Devices::FileHandle::setFileOpenFlags | ( | uint64_t | flags | ) |
Sets the flags that will be passed to CreateFile when opening the file.
| flags | The flags, a combination of zero or more Windows FILE_FLAG_* flags. |
1.8.12