FileHandle.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DEVICES_MULTIAXIS_WIN32_FILEHANDLE_H
#define SURGSIM_DEVICES_MULTIAXIS_WIN32_FILEHANDLE_H
#include <stdint.h>
#include <string>
namespace SurgSim
{
namespace Devices
{
class FileHandle
{
public:
typedef void* RawHandleType;
FileHandle();
FileHandle(FileHandle&& other);
FileHandle& operator=(FileHandle&& other);
~FileHandle();
bool isValid() const;
bool canRead() const;
bool canWrite() const;
bool hasDataToRead() const;
bool readBytes(void* dataBuffer, unsigned int bytesToRead, unsigned int* bytesActuallyRead);
RawHandleType get() const;
bool openForReadingAndWriting(const std::string& path);
bool openForReading(const std::string& path);
bool openForWriting(const std::string& path);
bool openForReadingAndMaybeWriting(const std::string& path);
void setFileOpenFlags(uint64_t flags);
uint64_t getFileOpenFlags() const;
void reset();
private:
// Prevent copy construction and copy assignment. (VS2012 does not support "= delete" yet.)
FileHandle(const FileHandle& other) /*= delete*/;
FileHandle& operator=(const FileHandle& other) /*= delete*/;
RawHandleType m_handle;
bool m_canRead;
bool m_canWrite;
uint64_t m_openFlags;
};
}; // namespace Devices
}; // namespace SurgSim
#endif // SURGSIM_DEVICES_MULTIAXIS_WIN32_FILEHANDLE_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Devices::FileHandle::operator=
FileHandle & operator=(FileHandle &&other)
Move assignment operator.
Definition: FileHandle.cpp:55
SurgSim::Devices::FileHandle::openForReading
bool openForReading(const std::string &path)
Attempts to open the file handle for reading only.
Definition: FileHandle.cpp:102
SurgSim::Devices::FileHandle::getFileOpenFlags
uint64_t getFileOpenFlags() const
Gets the flags that will be passed to CreateFile when opening the file.
Definition: FileHandle.cpp:151
SurgSim::Devices::FileHandle::isValid
bool isValid() const
Checks if the file handle is valid, i.e.
Definition: FileHandle.cpp:70
SurgSim::Devices::FileHandle::canRead
bool canRead() const
Determines if the file handle can be read from.
Definition: FileHandle.cpp:75
SurgSim::Devices::FileHandle::FileHandle
FileHandle()
Default constructor.
Definition: FileHandle.cpp:38
SurgSim::Devices::FileHandle::openForReadingAndWriting
bool openForReadingAndWriting(const std::string &path)
Attempts to open the file handle for reading and writing.
Definition: FileHandle.cpp:91
SurgSim::Devices::FileHandle::m_canRead
bool m_canRead
Definition: FileHandle.h:118
SurgSim::Devices::FileHandle::m_openFlags
uint64_t m_openFlags
Definition: FileHandle.h:120
SurgSim::Devices::FileHandle
A wrapper for an Windows-style HANDLE file descriptor.
Definition: FileHandle.h:30
SurgSim::Devices::FileHandle::canWrite
bool canWrite() const
Determines if the file handle can be written to.
Definition: FileHandle.cpp:80
SurgSim::Devices::FileHandle::openForReadingAndMaybeWriting
bool openForReadingAndMaybeWriting(const std::string &path)
Attempts to open the file handle for reading and (if permissions allow it) writing.
Definition: FileHandle.cpp:124
SurgSim::Devices::FileHandle::hasDataToRead
bool hasDataToRead() const
Checks whether this object has data available to be read.
Definition: FileHandle.cpp:156
SurgSim::Devices::FileHandle::setFileOpenFlags
void setFileOpenFlags(uint64_t flags)
Sets the flags that will be passed to CreateFile when opening the file.
Definition: FileHandle.cpp:145
SurgSim::Devices::FileHandle::openForWriting
bool openForWriting(const std::string &path)
Attempts to open the file handle for writing only.
Definition: FileHandle.cpp:113
SurgSim::Devices::FileHandle::~FileHandle
~FileHandle()
Destructor.
Definition: FileHandle.cpp:65
SurgSim::Devices::FileHandle::m_handle
RawHandleType m_handle
Definition: FileHandle.h:117
SurgSim::Devices::FileHandle::readBytes
bool readBytes(void *dataBuffer, unsigned int bytesToRead, unsigned int *bytesActuallyRead)
Reads bytes from the file handle.
Definition: FileHandle.cpp:169
SurgSim::Devices::FileHandle::reset
void reset()
Resets the file handle back to an invalid state.
Definition: FileHandle.cpp:136
SurgSim::Devices::FileHandle::RawHandleType
void * RawHandleType
Type of the raw handle used by the operating system.
Definition: FileHandle.h:35
SurgSim::Devices::FileHandle::m_canWrite
bool m_canWrite
Definition: FileHandle.h:119