libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 //#include "zypp/base/Logger.h" 00014 00015 #include "zypp/Range.h" 00016 00017 using std::endl; 00018 00020 namespace zypp 00021 { 00022 00023 namespace range_detail 00024 { 00030 bool overlaps( Rel lhs, Rel rhs, int cmp ) 00031 { 00032 if ( lhs == Rel::NONE || rhs == Rel::NONE ) 00033 return false; 00034 if ( lhs == Rel::ANY || rhs == Rel::ANY ) 00035 return true; 00036 00037 if ( lhs == Rel::NE ) 00038 { 00039 if ( cmp < 0 ) 00040 { 00041 // lhs < rhs 00042 return( rhs == Rel::GE 00043 || rhs == Rel::EQ ); 00044 } else if ( cmp > 0) 00045 { 00046 // lhs > rhs 00047 return( rhs == Rel::LT 00048 || rhs == Rel::EQ ); 00049 } else 00050 { 00051 //lhs == rhs 00052 return ( rhs == Rel::GT 00053 || rhs == Rel::LT ); 00054 } 00055 } 00056 00057 if ( rhs == Rel::NE ) 00058 { 00059 if ( cmp < 0 ) 00060 { 00061 // lhs < rhs 00062 return( lhs == Rel::LE 00063 || lhs == Rel::EQ ); 00064 } else if ( cmp > 0) 00065 { 00066 // lhs > rhs 00067 return( lhs == Rel::GT 00068 || lhs == Rel::EQ ); 00069 } else 00070 { 00071 //lhs == rhs 00072 return ( lhs == Rel::GT 00073 || lhs == Rel::LT ); 00074 } 00075 } 00076 00077 if ( cmp < 0 ) 00078 { 00079 // lhs < rhs: either lhs includes greater values or rhs includes lower. 00080 return( lhs == Rel::GT 00081 || lhs == Rel::GE 00082 || rhs == Rel::LT 00083 || rhs == Rel::LE ); 00084 } 00085 00086 if ( cmp > 0 ) 00087 { 00088 // lhs > rhs: either lhs includes lower values or rhs includes greater. 00089 return( lhs == Rel::LT 00090 || lhs == Rel::LE 00091 || rhs == Rel::GT 00092 || rhs == Rel::GE ); 00093 } 00094 00095 // lhs == rhs: either both ranges include Rel::EQ, or both head 00096 // into the same direction. 00097 if ( ( lhs == Rel::LE || lhs == Rel::EQ || lhs == Rel::GE ) 00098 && ( rhs == Rel::LE || rhs == Rel::EQ || rhs == Rel::GE ) ) 00099 return true; 00100 if ( ( lhs == Rel::LT && ( rhs == Rel::LT || rhs == Rel::LE ) ) 00101 || ( lhs == Rel::GT && ( rhs == Rel::GT || rhs == Rel::GE ) ) 00102 || ( rhs == Rel::LT && ( lhs == Rel::LT || lhs == Rel::LE ) ) 00103 || ( rhs == Rel::GT && ( lhs == Rel::GT || lhs == Rel::GE ) ) ) 00104 return true; 00105 // else 00106 return false; 00107 00108 } 00109 } 00110 00111 00113 } // namespace zypp