SourceMod SDK  1.7
AutoHandleRooter.h
1 
32 #ifndef _INCLUDE_SOURCEMOD_AUTO_HANDLE_ROOTER_H_
33 #define _INCLUDE_SOURCEMOD_AUTO_HANDLE_ROOTER_H_
34 
35 #include <IHandleSys.h>
36 
38 {
39 public:
40  AutoHandleRooter(Handle_t hndl)
41  {
42  if (hndl != BAD_HANDLE)
43  this->hndl = handlesys->FastCloneHandle(hndl);
44  else
45  this->hndl = BAD_HANDLE;
46  }
47 
49  {
50  if (hndl != BAD_HANDLE)
51  {
52  HandleSecurity sec(g_pCoreIdent, g_pCoreIdent);
53  handlesys->FreeHandle(hndl, &sec);
54  }
55  }
56 
57  Handle_t getHandle()
58  {
59  return hndl;
60  }
61 private:
62  Handle_t hndl;
63 };
64 
66 {
67  Handle_t original;
68  HandleSecurity sec;
69  AutoHandleRooter ahr;
70 public:
71  AutoHandleCloner(Handle_t original, HandleSecurity sec)
72  : original(original), sec(sec), ahr(original)
73  {
74  }
75 
77  {
78  if (original != BAD_HANDLE)
79  {
80  handlesys->FreeHandle(original, &sec);
81  }
82  }
83 
84  Handle_t getClone()
85  {
86  return ahr.getHandle();
87  }
88 };
89 
90 #endif /* _INCLUDE_SOURCEMOD_AUTO_HANDLE_ROOTER_H_ */
91 
Defines the interface for creating, reading, and removing Handles.
#define BAD_HANDLE
Definition: IHandleSys.h:62
Definition: AutoHandleRooter.h:65
Definition: AutoHandleRooter.h:37