libzypp 17.31.23
IdStringType.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_IDSTRINGTYPE_H
13#define ZYPP_IDSTRINGTYPE_H
14
15#include <zypp/IdString.h>
16
18namespace zypp
19{
20
22 //
23 // CLASS NAME : IdStringType<Derived>
24 //
85 template <class Derived>
87 {
88 public:
90
91 protected:
94 void operator=(const IdStringType &) {}
96
97 private:
98 const Derived & self() const { return *static_cast<const Derived*>( this ); }
99
100 public:
101 IdString idStr() const { return self()._str; }
102
103 bool empty() const { return idStr().empty(); }
104 unsigned size() const { return idStr().size(); }
105 const char * c_str() const { return idStr().c_str(); }
106 std::string asString() const { return idStr().asString(); }
107
108 IdType id() const { return idStr().id(); }
109
110 public:
112 explicit operator bool() const
113 { return ! empty(); }
114
116 explicit operator IdString() const
117 { return idStr(); }
118
120 explicit operator std::string() const
121 { return asString(); }
122
123 public:
124 // - break it down to idString/const char* <=> idString/cont char*
125 // - handle idString(0)/NULL being the least value
126 // - everything else goes to _doCompare (no NULL)
127 static int compare( const Derived & lhs, const Derived & rhs ) { return compare( lhs.idStr(), rhs.idStr() ); }
128 static int compare( const Derived & lhs, const IdString & rhs ) { return compare( lhs.idStr(), rhs ); }
129 static int compare( const Derived & lhs, const std::string & rhs ) { return compare( lhs.idStr(), rhs.c_str() ); }
130 static int compare( const Derived & lhs, const char * rhs ) { return compare( lhs.idStr(), rhs );}
131
132 static int compare( const IdString & lhs, const Derived & rhs ) { return compare( lhs, rhs.idStr() ); }
133 static int compare( const IdString & lhs, const IdString & rhs ) { return lhs == rhs ? 0 : Derived::_doCompare( (lhs ? lhs.c_str() : (const char *)0 ),
134 (rhs ? rhs.c_str() : (const char *)0 ) ); }
135 static int compare( const IdString & lhs, const std::string & rhs ) { return compare( lhs, rhs.c_str() ); }
136 static int compare( const IdString & lhs, const char * rhs ) { return Derived::_doCompare( (lhs ? lhs.c_str() : (const char *)0 ), rhs ); }
137
138 static int compare( const std::string & lhs, const Derived & rhs ) { return compare( lhs.c_str(), rhs.idStr() ); }
139 static int compare( const std::string & lhs, const IdString & rhs ) { return compare( lhs.c_str(), rhs ); }
140 static int compare( const std::string & lhs, const std::string & rhs ) { return compare( lhs.c_str(), rhs.c_str() ); }
141 static int compare( const std::string & lhs, const char * rhs ) { return compare( lhs.c_str(), rhs ); }
142
143 static int compare( const char * lhs, const Derived & rhs ) { return compare( lhs, rhs.idStr() ); }
144 static int compare( const char * lhs, const IdString & rhs ) { return Derived::_doCompare( lhs, (rhs ? rhs.c_str() : (const char *)0 ) ); }
145 static int compare( const char * lhs, const std::string & rhs ) { return compare( lhs, rhs.c_str() ); }
146 static int compare( const char * lhs, const char * rhs ) { return Derived::_doCompare( lhs, rhs ); }
147
148 public:
149 int compare( const Derived & rhs ) const { return compare( idStr(), rhs.idStr() ); }
150 int compare( const IdStringType & rhs ) const { return compare( idStr(), rhs.idStr() ); }
151 int compare( const IdString & rhs ) const { return compare( idStr(), rhs ); }
152 int compare( const std::string & rhs ) const { return compare( idStr(), rhs.c_str() ); }
153 int compare( const char * rhs ) const { return compare( idStr(), rhs ); }
154
155 private:
156 static int _doCompare( const char * lhs, const char * rhs )
157 {
158 if ( ! lhs ) return rhs ? -1 : 0;
159 return rhs ? ::strcmp( lhs, rhs ) : 1;
160 }
161 };
163
165 template <class Derived>
166 inline std::ostream & operator<<( std::ostream & str, const IdStringType<Derived> & obj )
167 { return str << obj.c_str(); }
168
170 template <class Derived>
171 inline bool operator==( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
172 { return lhs.compare( rhs ) == 0; }
174 template <class Derived>
175 inline bool operator==( const IdStringType<Derived> & lhs, const IdString & rhs )
176 { return lhs.compare( rhs ) == 0; }
178 template <class Derived>
179 inline bool operator==( const IdStringType<Derived> & lhs, const char * rhs )
180 { return lhs.compare( rhs ) == 0; }
182 template <class Derived>
183 inline bool operator==( const IdStringType<Derived> & lhs, const std::string & rhs )
184 { return lhs.compare( rhs ) == 0; }
186 template <class Derived>
187 inline bool operator==( const IdString & lhs, const IdStringType<Derived> & rhs )
188 { return rhs.compare( lhs ) == 0; }
190 template <class Derived>
191 inline bool operator==( const char * lhs, const IdStringType<Derived> & rhs )
192 { return rhs.compare( lhs ) == 0; }
194 template <class Derived>
195 inline bool operator==( const std::string & lhs, const IdStringType<Derived> & rhs )
196 { return rhs.compare( lhs ) == 0; }
197
199 template <class Derived>
200 inline bool operator!=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
201 { return lhs.compare( rhs ) != 0; }
203 template <class Derived>
204 inline bool operator!=( const IdStringType<Derived> & lhs, const IdString & rhs )
205 { return lhs.compare( rhs ) != 0; }
207 template <class Derived>
208 inline bool operator!=( const IdStringType<Derived> & lhs, const char * rhs )
209 { return lhs.compare( rhs ) != 0; }
211 template <class Derived>
212 inline bool operator!=( const IdStringType<Derived> & lhs, const std::string & rhs )
213 { return lhs.compare( rhs ) != 0; }
215 template <class Derived>
216 inline bool operator!=( const IdString & lhs, const IdStringType<Derived> & rhs )
217 { return rhs.compare( lhs ) != 0; }
219 template <class Derived>
220 inline bool operator!=( const char * lhs, const IdStringType<Derived> & rhs )
221 { return rhs.compare( lhs ) != 0; }
223 template <class Derived>
224 inline bool operator!=( const std::string & lhs, const IdStringType<Derived> & rhs )
225 { return rhs.compare( lhs ) != 0; }
226
228 template <class Derived>
229 inline bool operator<( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
230 { return lhs.compare( rhs ) < 0; }
232 template <class Derived>
233 inline bool operator<( const IdStringType<Derived> & lhs, const IdString & rhs )
234 { return lhs.compare( rhs ) < 0; }
236 template <class Derived>
237 inline bool operator<( const IdStringType<Derived> & lhs, const char * rhs )
238 { return lhs.compare( rhs ) < 0; }
240 template <class Derived>
241 inline bool operator<( const IdStringType<Derived> & lhs, const std::string & rhs )
242 { return lhs.compare( rhs ) < 0; }
244 template <class Derived>
245 inline bool operator<( const IdString & lhs, const IdStringType<Derived> & rhs )
246 { return rhs.compare( lhs ) >= 0; }
248 template <class Derived>
249 inline bool operator<( const char * lhs, const IdStringType<Derived> & rhs )
250 { return rhs.compare( lhs ) >= 0; }
252 template <class Derived>
253 inline bool operator<( const std::string & lhs, const IdStringType<Derived> & rhs )
254 { return rhs.compare( lhs ) >= 0; }
255
257 template <class Derived>
258 inline bool operator<=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
259 { return lhs.compare( rhs ) <= 0; }
261 template <class Derived>
262 inline bool operator<=( const IdStringType<Derived> & lhs, const IdString & rhs )
263 { return lhs.compare( rhs ) <= 0; }
265 template <class Derived>
266 inline bool operator<=( const IdStringType<Derived> & lhs, const char * rhs )
267 { return lhs.compare( rhs ) <= 0; }
269 template <class Derived>
270 inline bool operator<=( const IdStringType<Derived> & lhs, const std::string & rhs )
271 { return lhs.compare( rhs ) <= 0; }
273 template <class Derived>
274 inline bool operator<=( const IdString & lhs, const IdStringType<Derived> & rhs )
275 { return rhs.compare( lhs ) > 0; }
277 template <class Derived>
278 inline bool operator<=( const char * lhs, const IdStringType<Derived> & rhs )
279 { return rhs.compare( lhs ) > 0; }
281 template <class Derived>
282 inline bool operator<=( const std::string & lhs, const IdStringType<Derived> & rhs )
283 { return rhs.compare( lhs ) > 0; }
284
286 template <class Derived>
287 inline bool operator>( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
288 { return lhs.compare( rhs ) > 0; }
290 template <class Derived>
291 inline bool operator>( const IdStringType<Derived> & lhs, const IdString & rhs )
292 { return lhs.compare( rhs ) > 0; }
294 template <class Derived>
295 inline bool operator>( const IdStringType<Derived> & lhs, const char * rhs )
296 { return lhs.compare( rhs ) > 0; }
298 template <class Derived>
299 inline bool operator>( const IdStringType<Derived> & lhs, const std::string & rhs )
300 { return lhs.compare( rhs ) > 0; }
302 template <class Derived>
303 inline bool operator>( const IdString & lhs, const IdStringType<Derived> & rhs )
304 { return rhs.compare( lhs ) <= 0; }
306 template <class Derived>
307 inline bool operator>( const char * lhs, const IdStringType<Derived> & rhs )
308 { return rhs.compare( lhs ) <= 0; }
310 template <class Derived>
311 inline bool operator>( const std::string & lhs, const IdStringType<Derived> & rhs )
312 { return rhs.compare( lhs ) <= 0; }
313
315 template <class Derived>
316 inline bool operator>=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
317 { return lhs.compare( rhs ) >= 0; }
319 template <class Derived>
320 inline bool operator>=( const IdStringType<Derived> & lhs, const IdString & rhs )
321 { return lhs.compare( rhs ) >= 0; }
323 template <class Derived>
324 inline bool operator>=( const IdStringType<Derived> & lhs, const char * rhs )
325 { return lhs.compare( rhs ) >= 0; }
327 template <class Derived>
328 inline bool operator>=( const IdStringType<Derived> & lhs, const std::string & rhs )
329 { return lhs.compare( rhs ) >= 0; }
331 template <class Derived>
332 inline bool operator>=( const IdString & lhs, const IdStringType<Derived> & rhs )
333 { return rhs.compare( lhs ) < 0; }
335 template <class Derived>
336 inline bool operator>=( const char * lhs, const IdStringType<Derived> & rhs )
337 { return rhs.compare( lhs ) < 0; }
339 template <class Derived>
340 inline bool operator>=( const std::string & lhs, const IdStringType<Derived> & rhs )
341 { return rhs.compare( lhs ) < 0; }
342
344} // namespace zypp
346#endif // ZYPP_IDSTRINGTYPE_H
Base class for creating IdString based types.
Definition: IdStringType.h:87
static int compare(const char *lhs, const std::string &rhs)
Definition: IdStringType.h:145
static int compare(const Derived &lhs, const IdString &rhs)
Definition: IdStringType.h:128
int compare(const std::string &rhs) const
Definition: IdStringType.h:152
const Derived & self() const
Definition: IdStringType.h:98
bool operator<=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
LessEqual.
Definition: IdStringType.h:258
int compare(const char *rhs) const
Definition: IdStringType.h:153
IdStringType(const IdStringType &)
Definition: IdStringType.h:93
IdString idStr() const
Definition: IdStringType.h:101
static int compare(const std::string &lhs, const Derived &rhs)
Definition: IdStringType.h:138
bool operator<(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Less.
Definition: IdStringType.h:229
static int compare(const IdString &lhs, const IdString &rhs)
Definition: IdStringType.h:133
bool operator==(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Equal.
Definition: IdStringType.h:171
bool operator>=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
GreaterEqual.
Definition: IdStringType.h:316
static int compare(const char *lhs, const char *rhs)
Definition: IdStringType.h:146
static int _doCompare(const char *lhs, const char *rhs)
Definition: IdStringType.h:156
static int compare(const IdString &lhs, const std::string &rhs)
Definition: IdStringType.h:135
const char * c_str() const
Definition: IdStringType.h:105
static int compare(const char *lhs, const Derived &rhs)
Definition: IdStringType.h:143
void operator=(const IdStringType &)
Definition: IdStringType.h:94
int compare(const IdStringType &rhs) const
Definition: IdStringType.h:150
bool operator!=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
NotEqual.
Definition: IdStringType.h:200
static int compare(const Derived &lhs, const char *rhs)
Definition: IdStringType.h:130
static int compare(const std::string &lhs, const std::string &rhs)
Definition: IdStringType.h:140
IdString::IdType IdType
Definition: IdStringType.h:89
bool empty() const
Definition: IdStringType.h:103
static int compare(const std::string &lhs, const char *rhs)
Definition: IdStringType.h:141
unsigned size() const
Definition: IdStringType.h:104
static int compare(const char *lhs, const IdString &rhs)
Definition: IdStringType.h:144
bool operator>(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Greater.
Definition: IdStringType.h:287
IdType id() const
Definition: IdStringType.h:108
static int compare(const std::string &lhs, const IdString &rhs)
Definition: IdStringType.h:139
std::ostream & operator<<(std::ostream &str, const IdStringType< Derived > &obj)
Stream output.
Definition: IdStringType.h:166
std::string asString() const
Definition: IdStringType.h:106
int compare(const Derived &rhs) const
Definition: IdStringType.h:149
static int compare(const IdString &lhs, const Derived &rhs)
Definition: IdStringType.h:132
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:127
int compare(const IdString &rhs) const
Definition: IdStringType.h:151
static int compare(const IdString &lhs, const char *rhs)
Definition: IdStringType.h:136
static int compare(const Derived &lhs, const std::string &rhs)
Definition: IdStringType.h:129
Access to the sat-pools string space.
Definition: IdString.h:43
unsigned size() const
The strings size.
Definition: IdString.cc:47
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
sat::detail::IdType IdType
Definition: IdString.h:45
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:87
IdType id() const
Expert backdoor.
Definition: IdString.h:122
std::string asString() const
Conversion to std::string
Definition: IdString.h:98
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:335
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...
bool operator>(const IdString &lhs, const char *rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: IdString.h:204
bool operator>=(const IdString &lhs, const char *rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: IdString.h:220
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...
bool operator<=(const IdString &lhs, const char *rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: IdString.h:188
Backlink to the associated PoolImpl.
Definition: PoolMember.h:89