FileHandle.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DEVICES_MULTIAXIS_WIN32_FILEHANDLE_H
17 #define SURGSIM_DEVICES_MULTIAXIS_WIN32_FILEHANDLE_H
18 
19 #include <stdint.h>
20 #include <string>
21 
22 
23 namespace SurgSim
24 {
25 namespace Devices
26 {
27 
31 {
32 public:
35  typedef void* RawHandleType;
36 
39  FileHandle();
40 
43  FileHandle(FileHandle&& other);
44 
49 
51  ~FileHandle();
52 
55  bool isValid() const;
56 
59  bool canRead() const;
60 
63  bool canWrite() const;
64 
67  bool hasDataToRead() const;
68 
74  bool readBytes(void* dataBuffer, unsigned int bytesToRead, unsigned int* bytesActuallyRead);
75 
78  RawHandleType get() const;
79 
83  bool openForReadingAndWriting(const std::string& path);
84 
88  bool openForReading(const std::string& path);
89 
93  bool openForWriting(const std::string& path);
94 
99 
102  void setFileOpenFlags(uint64_t flags);
103 
106  uint64_t getFileOpenFlags() const;
107 
110  void reset();
111 
112 private:
113  // Prevent copy construction and copy assignment. (VS2012 does not support "= delete" yet.)
114  FileHandle(const FileHandle& other) /*= delete*/;
115  FileHandle& operator=(const FileHandle& other) /*= delete*/;
116 
118  bool m_canRead;
120  uint64_t m_openFlags;
121 };
122 
123 }; // namespace Devices
124 }; // namespace SurgSim
125 
126 #endif // SURGSIM_DEVICES_MULTIAXIS_WIN32_FILEHANDLE_H
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::readBytes
bool readBytes(void *dataBuffer, unsigned int bytesToRead, unsigned int *bytesActuallyRead)
Reads bytes from the file handle.
Definition: FileHandle.cpp:169
SurgSim::Devices::FileHandle::get
RawHandleType get() const
Gets the raw underlying OS file handle.
Definition: FileHandle.cpp:85
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::m_canWrite
bool m_canWrite
Definition: FileHandle.h:119
SurgSim::Devices::FileHandle::~FileHandle
~FileHandle()
Destructor.
Definition: FileHandle.cpp:65
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
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Devices::FileHandle::isValid
bool isValid() const
Checks if the file handle is valid, i.e.
Definition: FileHandle.cpp:70
SurgSim::Devices::FileHandle::m_openFlags
uint64_t m_openFlags
Definition: FileHandle.h:120
SurgSim::Devices::FileHandle::m_canRead
bool m_canRead
Definition: FileHandle.h:118
SurgSim::Devices::FileHandle
A wrapper for an Windows-style HANDLE file descriptor.
Definition: FileHandle.h:30
SurgSim::Devices::FileHandle::RawHandleType
void * RawHandleType
Type of the raw handle used by the operating system.
Definition: FileHandle.h:35
SurgSim::Devices::FileHandle::hasDataToRead
bool hasDataToRead() const
Checks whether this object has data available to be read.
Definition: FileHandle.cpp:156
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::m_handle
RawHandleType m_handle
Definition: FileHandle.h:117
SurgSim::Devices::FileHandle::canWrite
bool canWrite() const
Determines if the file handle can be written to.
Definition: FileHandle.cpp:80
SurgSim::Devices::FileHandle::canRead
bool canRead() const
Determines if the file handle can be read from.
Definition: FileHandle.cpp:75
SurgSim::Devices::FileHandle::operator=
FileHandle & operator=(FileHandle &&other)
Move assignment operator.
Definition: FileHandle.cpp:55
SurgSim::Devices::FileHandle::reset
void reset()
Resets the file handle back to an invalid state.
Definition: FileHandle.cpp:136
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt: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::FileHandle
FileHandle()
Default constructor.
Definition: FileHandle.cpp:38