1 //===--------------------- Range.cpp -----------------------------*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Utility/Range.h"
15 using namespace lldb_utility;
17 Range::Range(const Range &rng) : m_low(rng.m_low), m_high(rng.m_high) {
21 Range::Range(Range::ValueType low, Range::ValueType high)
22 : m_low(low), m_high(high) {
26 void Range::InitRange() {
27 if (m_low == OPEN_END) {
28 if (m_high == OPEN_END)
31 // make an empty range
38 Range &Range::operator=(const Range &rhs) {
40 this->m_low = rhs.m_low;
41 this->m_high = rhs.m_high;
46 void Range::Flip() { std::swap(m_high, m_low); }
48 void Range::Intersection(const Range &other) {
49 m_low = std::max(m_low, other.m_low);
50 m_high = std::min(m_high, other.m_high);
53 void Range::Union(const Range &other) {
54 m_low = std::min(m_low, other.m_low);
55 m_high = std::max(m_high, other.m_high);
58 void Range::Iterate(RangeCallback callback) {
59 ValueType counter = m_low;
60 while (counter <= m_high) {
61 bool should_continue = callback(counter);
68 bool Range::IsEmpty() { return (m_low > m_high); }
70 Range::ValueType Range::GetSize() {
71 if (m_high == OPEN_END)
74 return m_high - m_low + 1;