libzypp 17.31.23
Range.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13//#include <zypp/base/Logger.h>
14
15#include <zypp/Range.h>
16
17using std::endl;
18
20namespace zypp
21{
22
23 namespace range_detail
24 {
30 bool overlaps( Rel lhs, Rel rhs, int cmp )
31 {
32 if ( lhs == Rel::NONE || rhs == Rel::NONE )
33 return false;
34 if ( lhs == Rel::ANY || rhs == Rel::ANY )
35 return true;
36
37 if ( lhs == Rel::NE )
38 {
39 if ( cmp < 0 )
40 {
41 // lhs < rhs
42 return( rhs == Rel::GE
43 || rhs == Rel::EQ );
44 } else if ( cmp > 0)
45 {
46 // lhs > rhs
47 return( rhs == Rel::LT
48 || rhs == Rel::EQ );
49 } else
50 {
51 //lhs == rhs
52 return ( rhs == Rel::GT
53 || rhs == Rel::LT );
54 }
55 }
56
57 if ( rhs == Rel::NE )
58 {
59 if ( cmp < 0 )
60 {
61 // lhs < rhs
62 return( lhs == Rel::LE
63 || lhs == Rel::EQ );
64 } else if ( cmp > 0)
65 {
66 // lhs > rhs
67 return( lhs == Rel::GT
68 || lhs == Rel::EQ );
69 } else
70 {
71 //lhs == rhs
72 return ( lhs == Rel::GT
73 || lhs == Rel::LT );
74 }
75 }
76
77 if ( cmp < 0 )
78 {
79 // lhs < rhs: either lhs includes greater values or rhs includes lower.
80 return( lhs == Rel::GT
81 || lhs == Rel::GE
82 || rhs == Rel::LT
83 || rhs == Rel::LE );
84 }
85
86 if ( cmp > 0 )
87 {
88 // lhs > rhs: either lhs includes lower values or rhs includes greater.
89 return( lhs == Rel::LT
90 || lhs == Rel::LE
91 || rhs == Rel::GT
92 || rhs == Rel::GE );
93 }
94
95 // lhs == rhs: either both ranges include Rel::EQ, or both head
96 // into the same direction.
97 if ( ( lhs == Rel::LE || lhs == Rel::EQ || lhs == Rel::GE )
98 && ( rhs == Rel::LE || rhs == Rel::EQ || rhs == Rel::GE ) )
99 return true;
100 if ( ( lhs == Rel::LT && ( rhs == Rel::LT || rhs == Rel::LE ) )
101 || ( lhs == Rel::GT && ( rhs == Rel::GT || rhs == Rel::GE ) )
102 || ( rhs == Rel::LT && ( lhs == Rel::LT || lhs == Rel::LE ) )
103 || ( rhs == Rel::GT && ( lhs == Rel::GT || lhs == Rel::GE ) ) )
104 return true;
105 // else
106 return false;
107
108 }
109 }
110
111
113} // namespace zypp
bool overlaps(Rel lhs, Rel rhs, int cmp)
Compute Range overlaps.
Definition: Range.cc:30
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
Relational operators.
Definition: Rel.h:44
static const Rel LT
Definition: Rel.h:52
static const Rel GT
Definition: Rel.h:54
static const Rel LE
Definition: Rel.h:53
static const Rel GE
Definition: Rel.h:55
static const Rel NONE
Definition: Rel.h:57
static const Rel NE
Definition: Rel.h:51
static const Rel ANY
Definition: Rel.h:56
static const Rel EQ
Definition: Rel.h:50