opensurgsim
FileHandle.h
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 
98  bool openForReadingAndMaybeWriting(const std::string& path);
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 
117  RawHandleType m_handle;
118  bool m_canRead;
119  bool m_canWrite;
120  uint64_t m_openFlags;
121 };
122 
123 }; // namespace Devices
124 }; // namespace SurgSim
125 
126 #endif // SURGSIM_DEVICES_MULTIAXIS_WIN32_FILEHANDLE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
FileHandle & operator=(FileHandle &&other)
Move assignment operator.
Definition: FileHandle.cpp:55
bool openForReading(const std::string &path)
Attempts to open the file handle for reading only.
Definition: FileHandle.cpp:102
uint64_t getFileOpenFlags() const
Gets the flags that will be passed to CreateFile when opening the file.
Definition: FileHandle.cpp:151
bool isValid() const
Checks if the file handle is valid, i.e.
Definition: FileHandle.cpp:70
bool canRead() const
Determines if the file handle can be read from.
Definition: FileHandle.cpp:75
FileHandle()
Default constructor.
Definition: FileHandle.cpp:38
bool openForReadingAndWriting(const std::string &path)
Attempts to open the file handle for reading and writing.
Definition: FileHandle.cpp:91
A wrapper for an Windows-style HANDLE file descriptor.
Definition: FileHandle.h:30
bool canWrite() const
Determines if the file handle can be written to.
Definition: FileHandle.cpp:80
bool openForReadingAndMaybeWriting(const std::string &path)
Attempts to open the file handle for reading and (if permissions allow it) writing.
Definition: FileHandle.cpp:124
bool hasDataToRead() const
Checks whether this object has data available to be read.
Definition: FileHandle.cpp:156
void setFileOpenFlags(uint64_t flags)
Sets the flags that will be passed to CreateFile when opening the file.
Definition: FileHandle.cpp:145
bool openForWriting(const std::string &path)
Attempts to open the file handle for writing only.
Definition: FileHandle.cpp:113
~FileHandle()
Destructor.
Definition: FileHandle.cpp:65
bool readBytes(void *dataBuffer, unsigned int bytesToRead, unsigned int *bytesActuallyRead)
Reads bytes from the file handle.
Definition: FileHandle.cpp:169
void reset()
Resets the file handle back to an invalid state.
Definition: FileHandle.cpp:136
void * RawHandleType
Type of the raw handle used by the operating system.
Definition: FileHandle.h:35