libzypp  17.23.8
SetRelationMixin.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
11 #ifndef ZYPP_BASE_SETRELATIONMIXIN_H
12 #define ZYPP_BASE_SETRELATIONMIXIN_H
13 
14 #include <iosfwd>
15 #include <string>
16 
17 #include <zypp/base/Easy.h>
18 #include <zypp/base/EnumClass.h>
19 
21 namespace zypp
22 {
28  struct ESetCompareDef {
29  enum Enum {
31  equal = (1<<0),
32  properSubset = (1<<1),
33  properSuperset = (1<<2),
34  disjoint = (1<<3),
35  };
37  static const std::string & asString( Enum val_r );
38  };
40  typedef base::EnumClass<ESetCompareDef> SetCompare;
41 
43  inline std::ostream & operator<<( std::ostream & str, const SetCompare::Enum & obj )
44  { return str << SetCompare::asString( obj ); }
46  inline std::ostream & operator<<( std::ostream & str, const SetCompare & obj )
47  { return str << obj.asEnum(); }
48 
57  struct ESetRelationDef {
58  enum Enum {
59  uncomparable = SetCompare::uncomparable,
60  equal = SetCompare::equal,
61  properSubset = SetCompare::properSubset,
62  properSuperset = SetCompare::properSuperset,
63  disjoint = SetCompare::disjoint,
66  };
68  static const std::string & asString( Enum val_r );
69  };
71  typedef base::EnumClass<ESetRelationDef> SetRelation;
72 
74  inline std::ostream & operator<<( std::ostream & str, const SetRelation::Enum & obj )
75  { return str << SetRelation::asString( obj ); }
77  inline std::ostream & operator<<( std::ostream & str, const SetRelation & obj )
78  { return str << obj.asEnum(); }
79 
81  inline bool operator==( const SetRelation::Enum & lhs, const SetCompare::Enum & rhs )
82  { return( lhs&rhs || !(lhs|rhs) ); }
84  inline bool operator==( const SetRelation::Enum & lhs, const SetCompare & rhs )
85  { return( lhs == rhs.asEnum() ); }
87  inline bool operator==( const SetRelation & lhs, const SetCompare::Enum & rhs )
88  { return( lhs.asEnum() == rhs ); }
90  inline bool operator==( const SetRelation & lhs, const SetCompare & rhs )
91  { return( lhs.asEnum() == rhs.asEnum() ); }
93  inline bool operator==( const SetCompare::Enum & lhs, const SetRelation::Enum & rhs )
94  { return( rhs == lhs ); }
96  inline bool operator==( const SetCompare::Enum & lhs, const SetRelation & rhs )
97  { return( rhs == lhs ); }
99  inline bool operator==( const SetCompare & lhs, const SetRelation::Enum & rhs )
100  { return( rhs == lhs ); }
102  inline bool operator==( const SetCompare & lhs, const SetRelation & rhs )
103  { return( rhs == lhs ); }
104 
106  inline bool operator!=( const SetRelation::Enum & lhs, const SetCompare::Enum & rhs )
107  { return !( lhs == rhs ); }
109  inline bool operator!=( const SetRelation::Enum & lhs, const SetCompare & rhs )
110  { return !( lhs == rhs ); }
112  inline bool operator!=( const SetRelation & lhs, const SetCompare::Enum & rhs )
113  { return !( lhs == rhs ); }
115  inline bool operator!=( const SetRelation & lhs, const SetCompare & rhs )
116  { return !( lhs == rhs ); }
118  inline bool operator!=( const SetCompare::Enum & lhs, const SetRelation::Enum & rhs )
119  { return !( lhs == rhs ); }
121  inline bool operator!=( const SetCompare::Enum & lhs, const SetRelation & rhs )
122  { return !( lhs == rhs ); }
124  inline bool operator!=( const SetCompare & lhs, const SetRelation::Enum & rhs )
125  { return !( lhs == rhs ); }
127  inline bool operator!=( const SetCompare & lhs, const SetRelation & rhs )
128  { return !( lhs == rhs ); }
129 
131  namespace base
132  {
143  template <class Derived>
145  {
146  public:
148  SetCompare compare( const Derived & trg ) const
149  { return derived().setRelationMixinCompare( trg ); }
151  SetCompare compare( const SetRelationMixin<Derived> & trg ) const
152  { return compare( trg.derived() ); }
153 
155  bool compare( const Derived & trg, SetCompare cmp ) const
156  { return compare( trg ) == cmp; }
158  bool compare( const SetRelationMixin<Derived> & trg, SetCompare cmp ) const
159  { return compare( trg ) == cmp; }
160 
162  bool compare( const Derived & trg, SetRelation rel ) const
163  { return compare( trg ) == rel; }
165  bool compare( const SetRelationMixin<Derived> & trg, SetRelation rel ) const
166  { return compare( trg ) == rel; }
167 
168  protected:
173 
174  private:
176  const Derived & derived() const
177  { return *static_cast<const Derived*>( this ); }
178  };
179 
181  template <class Derived>
182  inline SetCompare compare( const SetRelationMixin<Derived> & src, const SetRelationMixin<Derived> & trg )
183  { return src.compare( trg ); }
184 
186  template <class Derived>
187  inline bool compare( const SetRelationMixin<Derived> & src, const SetRelationMixin<Derived> & trg, SetCompare cmp )
188  { return src.compare( trg, cmp ); }
189 
191  template <class Derived>
192  inline bool compare( const SetRelationMixin<Derived> & src, const SetRelationMixin<Derived> & trg, SetRelation rel )
193  { return src.compare( trg, rel ); }
194 
196  template <class Derived>
197  inline bool operator==( const SetRelationMixin<Derived> & src, const SetRelationMixin<Derived> & trg )
198  { return src.compare( trg, SetRelation::equal ); }
199 
201  template <class Derived>
202  inline bool operator!=( const SetRelationMixin<Derived> & src, const SetRelationMixin<Derived> & trg )
203  { return !( src == trg ); }
204 
212 #define SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN(DERIVED_TYPE,OTHER_TYPE) \
213  inline SetCompare compare( const base::SetRelationMixin<DERIVED_TYPE> & src, OTHER_TYPE trg ) \
214  { return src.compare( DERIVED_TYPE(trg) ); } \
215  inline SetCompare compare( OTHER_TYPE src, const base::SetRelationMixin<DERIVED_TYPE> & trg ) \
216  { return DERIVED_TYPE(src).compare( trg ); } \
217  \
218  inline bool compare( const base::SetRelationMixin<DERIVED_TYPE> & src, OTHER_TYPE trg, SetCompare cmp ) \
219  { return src.compare( DERIVED_TYPE(trg), cmp ); } \
220  inline bool compare( OTHER_TYPE src, const base::SetRelationMixin<DERIVED_TYPE> & trg, SetCompare cmp ) \
221  { return DERIVED_TYPE(src).compare( trg, cmp ); } \
222  \
223  inline bool compare( const base::SetRelationMixin<DERIVED_TYPE> & src, OTHER_TYPE trg, SetRelation rel ) \
224  { return src.compare( DERIVED_TYPE(trg), rel ); } \
225  inline bool compare( OTHER_TYPE src, const base::SetRelationMixin<DERIVED_TYPE> & trg, SetRelation rel ) \
226  { return DERIVED_TYPE(src).compare( trg, rel ); } \
227  \
228  inline bool operator==( const base::SetRelationMixin<DERIVED_TYPE> & src, OTHER_TYPE trg ) \
229  { return src.compare( DERIVED_TYPE(trg), SetRelation::equal ); } \
230  inline bool operator==( OTHER_TYPE src, const base::SetRelationMixin<DERIVED_TYPE> & trg ) \
231  { return DERIVED_TYPE(src).compare( trg, SetRelation::equal ); } \
232  \
233  inline bool operator!=( const base::SetRelationMixin<DERIVED_TYPE> & src, OTHER_TYPE trg ) \
234  { return !( src == trg ); } \
235  inline bool operator!=( OTHER_TYPE src, const base::SetRelationMixin<DERIVED_TYPE> & trg ) \
236  { return !( src == trg ); }
237 
238  } // namespace base
240 } // namespace zypp
242 #endif // ZYPP_BASE_SETRELATIONMIXIN_H
zypp::base::SetRelationMixin
Provide set relation methods based on Derived::setRelationMixinCompare A class using this mixin must ...
Definition: SetRelationMixin.h:144
zypp::base::SetRelationMixin::operator!=
bool operator!=(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
Definition: SetRelationMixin.h:202
zypp::ESetCompareDef::disjoint
"{ }"
Definition: SetRelationMixin.h:34
zypp::ESetRelationDef::equal
"{==}"
Definition: SetRelationMixin.h:60
zypp::operator==
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:84
EnumClass.h
zypp::base::SetRelationMixin::compare
bool compare(const SetRelationMixin< Derived > &trg, SetRelation rel) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:165
zypp::ESetCompareDef::properSuperset
"{>}"
Definition: SetRelationMixin.h:33
zypp::base::SetRelationMixin::compare
bool compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg, SetCompare cmp)
Definition: SetRelationMixin.h:187
zypp::base::SetRelationMixin::compare
SetCompare compare(const SetRelationMixin< Derived > &trg) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:151
zypp::ESetCompareDef::equal
"{=}"
Definition: SetRelationMixin.h:31
zypp::ESetRelationDef::disjoint
"{ }"
Definition: SetRelationMixin.h:63
zypp::ESetCompareDef::properSubset
"{<}"
Definition: SetRelationMixin.h:32
zypp::ESetRelationDef::properSuperset
"{>>}"
Definition: SetRelationMixin.h:62
zypp::base::SetRelationMixin::compare
bool compare(const SetRelationMixin< Derived > &trg, SetCompare cmp) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:158
zypp::ESetRelationDef
Set Relation based on SetCompare (use like 'enum class SetRelation') Comparison (== !...
Definition: SetRelationMixin.h:57
zypp::base::SetRelationMixin::DEFAULT_COPYABLE
DEFAULT_COPYABLE(SetRelationMixin)
zypp::base::SetRelationMixin::derived
const Derived & derived() const
Access to sublass Derived.
Definition: SetRelationMixin.h:176
zypp::base::SetRelationMixin::operator==
bool operator==(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
Definition: SetRelationMixin.h:197
zypp::ESetRelationDef::Enum
Enum
Definition: SetRelationMixin.h:58
zypp::ESetCompareDef::Enum
Enum
Definition: SetRelationMixin.h:29
zypp::base::SetRelationMixin::compare
SetCompare compare(const Derived &trg) const
Compare sets.
Definition: SetRelationMixin.h:148
zypp::ESetCompareDef::uncomparable
"{?}"
Definition: SetRelationMixin.h:30
zypp::ESetRelationDef::superset
"{>=}"
Definition: SetRelationMixin.h:65
zypp::base::SetRelationMixin::compare
bool compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg, SetRelation rel)
Definition: SetRelationMixin.h:192
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::ESetRelationDef::subset
"{<=}"
Definition: SetRelationMixin.h:64
zypp::ESetCompareDef::SetCompare
base::EnumClass< ESetCompareDef > SetCompare
Definition: SetRelationMixin.h:40
zypp::base::SetRelationMixin::compare
bool compare(const Derived &trg, SetCompare cmp) const
Compare sets and match against SetCompare.
Definition: SetRelationMixin.h:155
zypp::ESetRelationDef::properSubset
"{<<}"
Definition: SetRelationMixin.h:61
zypp::base::SetRelationMixin::compare
SetCompare compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
Definition: SetRelationMixin.h:182
zypp::ESetCompareDef::asString
static const std::string & asString(Enum val_r)
String representantion.
Definition: SetRelationMixin.cc:18
zypp::ESetRelationDef::asString
static const std::string & asString(Enum val_r)
String representantion.
Definition: SetRelationMixin.cc:30
zypp::asString
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
Definition: DefaultIntegral.h:98
zypp::operator!=
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:109
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
zypp::ESetRelationDef::uncomparable
"{??}"
Definition: SetRelationMixin.h:59
zypp::base::SetRelationMixin::SetRelationMixin
SetRelationMixin()
Definition: SetRelationMixin.h:169
zypp::base::SetRelationMixin::DEFAULT_MOVABLE
DEFAULT_MOVABLE(SetRelationMixin)
str
String related utilities and Regular expression matching.
Easy.h
zypp::ESetRelationDef::SetRelation
base::EnumClass< ESetRelationDef > SetRelation
Definition: SetRelationMixin.h:71
zypp::ESetCompareDef
Result of set comparison (use like 'enum class SetCompare') This is the type a compare function shoul...
Definition: SetRelationMixin.h:28
zypp::base::SetRelationMixin::~SetRelationMixin
~SetRelationMixin()
Definition: SetRelationMixin.h:172
zypp::base::SetRelationMixin::compare
bool compare(const Derived &trg, SetRelation rel) const
Compare sets and match against SetRelation.
Definition: SetRelationMixin.h:162