1 : // Copyright 2011 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // This file contains internals for the AddressRange, AddressSpace and
16 : // AddressRangeMap implementations. It is not meant to be included directly.
17 :
18 : #ifndef SYZYGY_CORE_ADDRESS_SPACE_INTERNAL_H_
19 : #define SYZYGY_CORE_ADDRESS_SPACE_INTERNAL_H_
20 :
21 : #include <utility>
22 :
23 : namespace core {
24 :
25 : namespace internal {
26 :
27 : // A comparison functor for std::pair<AddressRange, AddressRange> that is used
28 : // by the AddressRangeMap.
29 : template<typename SourceRangeType, typename DestinationRangeType>
30 : struct RangePairLess {
31 : typedef std::pair<SourceRangeType, DestinationRangeType> RangePair;
32 :
33 E : bool operator()(const RangePair& ranges1, const RangePair& ranges2) const {
34 E : if (ranges1.first.Intersects(ranges2.first))
35 E : return false;
36 E : return ranges1.first < ranges2.first;
37 E : }
38 : };
39 :
40 : // A utility function for doing a comparison between two address ranges. This
41 : // comparison endows them a with a complete ordering.
42 : template <typename AddressRangeType>
43 : struct CompleteAddressRangeLess {
44 : bool operator()(const AddressRangeType& range1,
45 E : const AddressRangeType& range2) {
46 E : if (range1.start() < range2.start())
47 E : return true;
48 E : if (range2.start() < range1.start())
49 E : return false;
50 E : return range1.size() < range2.size();
51 E : }
52 : };
53 :
54 : // A utility function for comparing a pair of AddressRange objects using the
55 : // full ordering compare function.
56 : template <typename FirstAddressRange, typename SecondAddressRange>
57 : struct CompleteAddressRangePairLess {
58 : bool operator()(
59 : const std::pair<FirstAddressRange, SecondAddressRange>& pair1,
60 E : const std::pair<FirstAddressRange, SecondAddressRange>& pair2) {
61 E : if (CompleteAddressRangeLess<FirstAddressRange>()(pair1.first, pair2.first))
62 E : return true;
63 E : if (CompleteAddressRangeLess<FirstAddressRange>()(pair2.first, pair1.first))
64 E : return false;
65 : return CompleteAddressRangeLess<SecondAddressRange>()(pair1.second,
66 E : pair2.second);
67 E : }
68 : };
69 :
70 : } // namespace internal
71 :
72 : } // namespace core
73 :
74 : #endif // SYZYGY_CORE_ADDRESS_SPACE_INTERNAL_H_
|