-
Notifications
You must be signed in to change notification settings - Fork 561
/
wrapper.h
79 lines (62 loc) · 1.02 KB
/
wrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _WRAPPER_H_
#define _WRAPPER_H_
class Object
{
private:
PyObject* p;
// GCC freaks out if these are private, but it doesn't use them (?)
// Object(const Object& illegal);
// void operator=(const Object& illegal);
public:
Object(PyObject* _p = 0)
{
p = _p;
}
~Object()
{
Py_XDECREF(p);
}
Object& operator=(PyObject* pNew)
{
Py_XDECREF(p);
p = pNew;
return *this;
}
bool IsValid() const { return p != 0; }
void Attach(PyObject* _p)
{
Py_XDECREF(p);
p = _p;
}
PyObject* Detach()
{
PyObject* pT = p;
p = 0;
return pT;
}
operator PyObject*()
{
return p;
}
PyObject* Get()
{
return p;
}
};
#ifdef WINVER
struct RegKey
{
HKEY hkey;
RegKey()
{
hkey = 0;
}
~RegKey()
{
if (hkey != 0)
RegCloseKey(hkey);
}
operator HKEY() { return hkey; }
};
#endif
#endif // _WRAPPER_H_