forked from pig4210/xlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xblk.cpp
81 lines (68 loc) · 1.54 KB
/
xblk.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
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
80
81
#include "xblk.h"
#include "swap.h"
xblk::xblk()
:_start(nullptr),_end(nullptr),_size(0)
{
}
xblk::xblk(void* const starts,void* const ends)
:_start(starts),_end(ends)
{
seqswap(_start,_end);
_size = (size_t)_end - (size_t)_start;
}
xblk::xblk(void* const starts,const intptr_t sizes)
:_start(starts),_size(sizes)
{
_end = (void*)((intptr_t)starts + sizes);
if(seqswap(_start,_end))
{
_size = -(sizes);
}
}
void* xblk::start() const
{
return _start;
}
void* xblk::end() const
{
return _end;
}
size_t xblk::size() const
{
return _size;
}
xblk::PosDcrpt xblk::checkin(void* const starts,void* const ends) const
{
const unsigned char* const s = (unsigned char*)start();
const unsigned char* const e = (unsigned char*)end();
const unsigned char* ss = (unsigned char*)starts;
const unsigned char* ee = (unsigned char*)ends;
seqswap(ss,ee);
if(ss < s)
{
if(ee < s) return PD_NoIn;
if(ee > e) return PD_SubIn;
return PD_TailIn;
}
if(ss > e) return PD_NoIn;
if(ee > e) return PD_HeadIn;
return PD_WholeIn;
}
xblk::PosDcrpt xblk::checkin(void* const starts,const intptr_t sizes) const
{
return checkin(starts,(void*)((intptr_t)starts + sizes));
}
xblk::PosDcrpt xblk::checkin(const xblk &b) const
{
return checkin(b.start(),b.end());
}
bool xblk::operator==(const xblk& b) const
{
if(start() != b.start()) return false;
if(end() != b.end()) return false;
return true;
}
bool xblk::operator!=(const xblk& b) const
{
return !this->operator==(b);
}