HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_Handle.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_Handle.h (SYS Library, C++)
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __SYS_HANDLE_H_INCLUDED__
14 #define __SYS_HANDLE_H_INCLUDED__
15 
16 #include "SYS_API.h"
17 
18 
19 typedef void * SYS_WinHandle;
20 typedef int SYS_UnixHandle;
21 
22 // We assume that sizeof(SYS_WinHandle) > sizeof(UnixHandle) so we use that as
23 // the invalid value.
24 #define SYS_INVALID_HANDLE SYS_WinHandle(-1)
25 
26 
27 /// Platform independent handle for marshalling between Unix file
28 /// descriptors (int) and Windows HANDLE objects (which are assumed
29 /// to be void *).
31 {
32 public:
34  : myWinHandle(SYS_INVALID_HANDLE)
35  {
36  }
37  explicit
39  : myWinHandle(SYS_INVALID_HANDLE)
40  {
41  if (h >= 0)
42  myUnixHandle = h;
43  }
44  explicit
46  : myWinHandle(h)
47  {
48  }
49 
50  void invalidate()
51  { myWinHandle = SYS_INVALID_HANDLE; }
52  bool isValid() const
53  { return (myWinHandle != SYS_INVALID_HANDLE); }
54 
56  { return myUnixHandle; }
58  { myUnixHandle = h; }
59 
61  { return myWinHandle; }
63  { myWinHandle = h; }
64 
65 private:
66  // These are NOT two separate data members because SYS_Handle is a union!
67  SYS_WinHandle myWinHandle;
68  SYS_UnixHandle myUnixHandle;
69 };
70 
71 /// Closes the file if it's valid and invalidates it.
72 SYS_API void SYShandleClose(SYS_Handle& handle);
73 
74 #endif // __SYS_HANDLE_H_INCLUDED__
SYS_Handle(SYS_WinHandle h)
Definition: SYS_Handle.h:45
SYS_Handle(SYS_UnixHandle h)
Definition: SYS_Handle.h:38
int SYS_UnixHandle
Definition: SYS_Handle.h:20
void invalidate()
Definition: SYS_Handle.h:50
void * SYS_WinHandle
Definition: SYS_Handle.h:19
void setWinHandle(SYS_WinHandle h)
Definition: SYS_Handle.h:62
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
SYS_WinHandle winHandle() const
Definition: SYS_Handle.h:60
SYS_API void SYShandleClose(SYS_Handle &handle)
Closes the file if it's valid and invalidates it.
void setUnixHandle(SYS_UnixHandle h)
Definition: SYS_Handle.h:57
bool isValid() const
Definition: SYS_Handle.h:52
#define SYS_API
Definition: SYS_API.h:11
SYS_UnixHandle unixHandle() const
Definition: SYS_Handle.h:55
#define SYS_INVALID_HANDLE
Definition: SYS_Handle.h:24