libzypp  13.10.6
Range.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_RANGE_H
13 #define ZYPP_RANGE_H
14 
15 #include "zypp/RelCompare.h"
16 
18 namespace zypp
19 {
20 
21  namespace range_detail
22  {
23  bool overlaps( Rel lhs, Rel rhs, int cmp );
24  }
25 
27  //
28  // CLASS NAME : Range
29  //
33  template<class _Tp, class _Compare = Compare<_Tp> >
34  struct Range
35  {
39  _Tp value;
40 
43  : op( Rel::ANY )
44  {}
45 
47  Range( const _Tp & value_r )
48  : op( Rel::EQ )
49  , value( value_r )
50  {}
51 
53  Range( Rel op_r, const _Tp & value_r )
54  : op( op_r )
55  , value( value_r )
56  {}
57 
59  bool overlaps( const Range & rhs ) const
60  {
61  return range_detail::overlaps( op, rhs.op,
62  _Compare()( value, rhs.value ) );
63  }
64  };
66 
67  template<class _Tp, class _Compare>
68  inline bool overlaps( const Range<_Tp,_Compare> & lhs,
69  const Range<_Tp,_Compare> & rhs )
70  { return lhs.overlaps( rhs ); }
71 
73 
74  template<class _Tp, class _Compare>
75  inline bool operator==( const Range<_Tp,_Compare> & lhs,
76  const Range<_Tp,_Compare> & rhs )
77  {
78  return( lhs.op == rhs.op
79  && ( lhs.op == Rel::ANY
80  || lhs.op == Rel::NONE
81  || relCompare( Rel::EQ, lhs.value, rhs.value,
82  _Compare() )
83  )
84  );
85  }
86 
87  template<class _Tp, class _Compare>
88  inline bool operator!=( const Range<_Tp,_Compare> & lhs,
89  const Range<_Tp,_Compare> & rhs )
90  { return ! ( lhs == rhs ); }
91 
93 } // namespace zypp
95 #endif // ZYPP_RANGE_H
bool operator!=(const CountryCode &lhs, const CountryCode &rhs)
Relational operators.
Definition: Rel.h:43
static const Rel EQ
Definition: Rel.h:50
static const Rel ANY
Definition: Rel.h:56
Rel op
Definition: Range.h:37
Range()
Default ctor: Rel::ANY.
Definition: Range.h:42
bool overlaps(const Range &rhs) const
Return whether two Ranges overlap.
Definition: Range.h:59
bool overlaps(Rel lhs, Rel rhs, int cmp)
Compute Range overlaps.
Definition: Range.cc:30
Range(Rel op_r, const _Tp &value_r)
Ctor taking Rel and _Tp.
Definition: Range.h:53
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:309
_Tp value
Definition: Range.h:39
bool overlaps(const Range< _Tp, _Compare > &lhs, const Range< _Tp, _Compare > &rhs)
Definition: Range.h:68
Range(const _Tp &value_r)
Ctor taking _Tp (Rel::EQ).
Definition: Range.h:47
static const Rel NONE
Definition: Rel.h:57