-
Notifications
You must be signed in to change notification settings - Fork 2
/
basetypes.cpp
53 lines (42 loc) · 870 Bytes
/
basetypes.cpp
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
#include "stdafx.h"
#include "basetypes.h"
#include "utils.h"
void Handle::swap(Handle &other)
{
using std::swap;
swap(this->value, other.value);
}
Handle::operator void *() const
{
return this->value;
}
Handle & Handle::operator=(Handle other)
{
return other.swap(*this), *this;
}
Handle::~Handle()
{
if (valid(this->value)) {
CloseHandle(value);
}
}
Handle::Handle(Handle const &other) : value(other.value)
{
if (valid(this->value)) {
CheckAndThrow(DuplicateHandle(GetCurrentProcess(), this->value, GetCurrentProcess(),
&this->value, MAXIMUM_ALLOWED, TRUE, DUPLICATE_SAME_ACCESS));
}
}
Handle::Handle(void *const value) : value(value)
{
if (!valid(value)) {
throw std::invalid_argument("invalid handle");
}
}
Handle::Handle() : value()
{
}
bool Handle::valid(void *const value)
{
return value && value != reinterpret_cast<void *>(-1);
}