btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / debugger / types / TargetAddressRange.h
blob74feac6d9c5db4ec11338fed546385aa2a8699f4
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef TARGET_ADDRESS_RANGE_H
6 #define TARGET_ADDRESS_RANGE_H
8 #include <algorithm>
10 #include "Types.h"
13 class TargetAddressRange {
14 public:
15 TargetAddressRange()
17 fStart(0),
18 fSize(0)
22 TargetAddressRange(target_addr_t start, target_size_t size)
24 fStart(start),
25 fSize(size)
29 TargetAddressRange(const TargetAddressRange& other)
31 fStart(other.fStart),
32 fSize(other.fSize)
36 TargetAddressRange& operator=(const TargetAddressRange& other)
38 fStart = other.fStart;
39 fSize = other.fSize;
40 return *this;
43 bool operator==(const TargetAddressRange& other) const
45 return fStart == other.fStart && fSize == other.fSize;
48 bool operator!=(const TargetAddressRange& other) const
50 return !(*this == other);
53 target_addr_t Start() const
55 return fStart;
58 target_size_t Size() const
60 return fSize;
63 target_addr_t End() const
65 return fStart + fSize;
68 bool Contains(target_addr_t address) const
70 return address >= Start() && address < End();
73 bool Contains(const TargetAddressRange& other) const
75 return Start() <= other.Start() && End() >= other.End();
78 bool IntersectsWith(const TargetAddressRange& other) const
80 return Contains(other.Start()) || other.Contains(Start());
83 TargetAddressRange& operator|=(const TargetAddressRange& other)
85 if (fSize == 0)
86 return *this = other;
88 if (other.fSize > 0) {
89 target_addr_t end = std::max(End(), other.End());
90 fStart = std::min(fStart, other.fStart);
91 fSize = end - fStart;
94 return *this;
97 private:
98 target_addr_t fStart;
99 target_size_t fSize;
103 #endif // TARGET_ADDRESS_RANGE_H