]> git.saurik.com Git - apple/system_cmds.git/blob - CPPUtil/UtilAbsInterval.hpp
4fe9c3129105493ce7ce8289043863c2935e17a7
[apple/system_cmds.git] / CPPUtil / UtilAbsInterval.hpp
1 //
2 // UtilAbsInterval.h
3 // CPPUtil
4 //
5 // Created by James McIlree on 4/14/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
7 //
8
9 #ifndef __CPPUtil__UtilAbsInterval__
10 #define __CPPUtil__UtilAbsInterval__
11
12 typedef TRange<AbsTime> AbsInterval;
13
14 struct AbsIntervalLocationVsAbsTimeComparator {
15 bool operator()(const AbsInterval& activity, const AbsTime& time) const {
16 return activity.location() < time;
17 }
18
19 bool operator()(const AbsTime& time, const AbsInterval& activity) const {
20 return time < activity.location();
21 }
22 };
23
24 struct AbsIntervalMaxVsAbsTimeComparator {
25 bool operator()(const AbsInterval& activity, const AbsTime& time) const {
26 return activity.max() < time;
27 }
28
29 bool operator()(const AbsTime& time, const AbsInterval& activity) const {
30 return time < activity.max();
31 }
32 };
33
34 //
35 // Takes a vector of sorted non overlapping AbsInterval(s), and a timespan. Returns a pointer to the
36 // youngest AbsInterval that intersects the timespan. Returns NULL if no interval intersects.
37 //
38 // vec: XXXXXXX XXXXXXXX XXXXX XXXXXX
39 // ts: MMMMMMMMMMMMMMM
40 // ret: XXXXXXX
41 //
42 // ----------------------------------
43 //
44 // vec: XXXXXXXX XXXXX XXXXXX
45 // ts: MMMMMMMMMMMMMMM
46 // ret: XXXXXXXX
47 //
48 // ----------------------------------
49 //
50 // vec: XXXXX XXXXXX
51 // ts: MMMMMMMMMMMMMMM
52 // ret: XXXXX
53 //
54 // ----------------------------------
55 //
56 // vec: XXXXXX
57 // ts: MMMMMMMMMMMMMMM
58 // ret: NULL
59 //
60
61 const AbsInterval* interval_beginning_timespan(const std::vector<AbsInterval>& intervals, AbsInterval timespan);
62
63 //
64 // Takes a vector of sorted non overlapping AbsInterval(s), and a timespan. Returns a pointer to the
65 // oldest AbsInterval that intersects the timespan. Returns NULL if no interval intersects.
66 //
67 // vec: XXXXXXX XXXXXXXX XXXXX XXXXXX
68 // ts: MMMMMMMMMMMMMMM
69 // ret: XXXXXXX
70 //
71 // ----------------------------------
72 //
73 // vec: XXXXXXXX XXXXX XXXXXX
74 // ts: MMMMMMMMMMMMMMM
75 // ret: XXXXXXXX
76 //
77 // ----------------------------------
78 //
79 // vec: XXXXX XXXXXX
80 // ts: MMMMMMMMMMMMMMM
81 // ret: XXXXX
82 //
83 // ----------------------------------
84 //
85 // vec: XXXXXX
86 // ts: MMMMMMMMMMMMMMM
87 // ret: NULL
88 //
89
90 const AbsInterval* interval_ending_timespan(const std::vector<AbsInterval>& intervals, AbsInterval timespan);
91
92 #endif /* defined(__CPPUtil__UtilAbsInterval__) */