blob: 158d1e729d48e85624685734a0b9d29b8b2893b4 (
plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
//===--------------------- Range.cpp -----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Utility/Range.h"
using namespace lldb_utility;
Range::Range (const Range& rng) :
m_low(rng.m_low),
m_high(rng.m_high)
{
InitRange();
}
Range::Range (Range::ValueType low,
Range::ValueType high) :
m_low(low),
m_high(high)
{
InitRange();
}
void
Range::InitRange ()
{
if (m_low == OPEN_END)
{
if (m_high == OPEN_END)
m_low = 0;
else
{
// make an empty range
m_low = 1;
m_high = 0;
}
}
}
Range&
Range::operator = (const Range& rhs)
{
if (&rhs != this)
{
this->m_low = rhs.m_low;
this->m_high = rhs.m_high;
}
return *this;
}
void
Range::Flip ()
{
std::swap(m_high, m_low);
}
void
Range::Intersection (const Range& other)
{
m_low = std::max(m_low,other.m_low);
m_high = std::min(m_high,other.m_high);
}
void
Range::Union (const Range& other)
{
m_low = std::min(m_low,other.m_low);
m_high = std::max(m_high,other.m_high);
}
void
Range::Iterate (RangeCallback callback)
{
ValueType counter = m_low;
while (counter <= m_high)
{
bool should_continue = callback(counter);
if (!should_continue)
return;
counter++;
}
}
bool
Range::IsEmpty ()
{
return (m_low > m_high);
}
Range::ValueType
Range::GetSize ()
{
if (m_high == OPEN_END)
return OPEN_END;
if (m_high >= m_low)
return m_high - m_low + 1;
return 0;
}
|