libzypp 17.31.23
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
21namespace zypp
22{
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
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
Provide set relation methods based on Derived::setRelationMixinCompare A class using this mixin must ...
bool compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg, SetCompare cmp)
Compare sets and match against SetCompare.
bool compare(const Derived &trg, SetRelation rel) const
Compare sets and match against SetRelation.
bool compare(const Derived &trg, SetCompare cmp) const
Compare sets and match against SetCompare.
DEFAULT_COPYABLE(SetRelationMixin)
bool compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg, SetRelation rel)
Compare sets and match against SetRelation.
DEFAULT_MOVABLE(SetRelationMixin)
SetCompare compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
Compare sets.
SetCompare compare(const SetRelationMixin< Derived > &trg) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool operator==(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
Equal.
bool operator!=(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
Unequal.
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...
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...
SetCompare compare(const Derived &trg) const
Compare sets.
const Derived & derived() const
Access to sublass Derived.
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
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...
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
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...
Result of set comparison (use like 'enum class SetCompare') This is the type a compare function shoul...
base::EnumClass< ESetCompareDef > SetCompare
typedef 'enum class SetCompare'
Set Relation based on SetCompare (use like 'enum class SetRelation') Comparison (== !...
base::EnumClass< ESetRelationDef > SetRelation
typedef 'enum class SetRelation'