libzypp  17.7.0
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 TCompare = 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  { return range_detail::overlaps( op, rhs.op, TCompare()( value, rhs.value ) ); }
61  };
63 
64  template<class Tp, class TCompare>
65  inline bool overlaps( const Range<Tp,TCompare> & lhs,
66  const Range<Tp,TCompare> & rhs )
67  { return lhs.overlaps( rhs ); }
68 
70 
71  template<class Tp, class TCompare>
72  inline bool operator==( const Range<Tp,TCompare> & lhs,
73  const Range<Tp,TCompare> & rhs )
74  {
75  return( lhs.op == rhs.op
76  && ( lhs.op == Rel::ANY
77  || lhs.op == Rel::NONE
78  || relCompare( Rel::EQ, lhs.value, rhs.value, TCompare() )
79  )
80  );
81  }
82 
83  template<class Tp, class TCompare>
84  inline bool operator!=( const Range<Tp,TCompare> & lhs,
85  const Range<Tp,TCompare> & rhs )
86  { return ! ( lhs == rhs ); }
87 
89 } // namespace zypp
91 #endif // ZYPP_RANGE_H
Range()
Default ctor: Rel::ANY.
Definition: Range.h:42
Range(const Tp &value_r)
Ctor taking Tp (Rel::EQ).
Definition: Range.h:47
Relational operators.
Definition: Rel.h:43
static const Rel EQ
Definition: Rel.h:50
static const Rel ANY
Definition: Rel.h:56
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
bool overlaps(Rel lhs, Rel rhs, int cmp)
Compute Range overlaps.
Definition: Range.cc:30
Rel op
Definition: Range.h:37
Tp value
Definition: Range.h:39
bool overlaps(const Range &rhs) const
Return whether two Ranges overlap.
Definition: Range.h:59
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
Range(Rel op_r, const Tp &value_r)
Ctor taking Rel and Tp.
Definition: Range.h:53
bool overlaps(const Range< Tp, TCompare > &lhs, const Range< Tp, TCompare > &rhs)
Definition: Range.h:65
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
static const Rel NONE
Definition: Rel.h:57