foobar2000 SDK  2015-08-03
filehandle.h
Go to the documentation of this file.
1 namespace pfc {
2 #ifdef _WIN32
4  const fileHandle_t fileHandleInvalid = INVALID_HANDLE_VALUE;
5 #else
6  typedef int fileHandle_t;
7  const fileHandle_t fileHandleInvalid = -1;
8 #endif
9 
10  void fileHandleClose( fileHandle_t h );
11  fileHandle_t fileHandleDup( fileHandle_t h );
12 
13  class fileHandle {
14  public:
15  fileHandle( fileHandle_t val ) : h(val) {}
16  fileHandle() : h ( fileHandleInvalid ) {}
17  ~fileHandle() { close(); }
18  fileHandle( fileHandle && other ) { h = other.h; other.clear(); }
19  void operator=( fileHandle && other ) { close(); h = other.h; other.clear(); }
20  void operator=( fileHandle_t other ) { close(); h = other; }
21  void close();
22  void clear() { h = fileHandleInvalid; }
23  bool isValid() { return h != fileHandleInvalid; }
24  fileHandle_t h;
25  private:
26  fileHandle( const fileHandle & );
27  void operator=( const fileHandle & );
28  };
29 }
HANDLE fileHandle_t
Definition: filehandle.h:3
fileHandle(fileHandle &&other)
Definition: filehandle.h:18
fileHandle_t h
Definition: filehandle.h:24
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
void operator=(fileHandle_t other)
Definition: filehandle.h:20
fileHandle_t fileHandleDup(fileHandle_t h)
Definition: filehandle.cpp:17
void operator=(fileHandle &&other)
Definition: filehandle.h:19
const fileHandle_t fileHandleInvalid
Definition: filehandle.h:4
bool isValid()
Definition: filehandle.h:23
fileHandle(fileHandle_t val)
Definition: filehandle.h:15
void fileHandleClose(fileHandle_t h)
Definition: filehandle.cpp:8