libzypp 17.37.17
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:
92 IdStringType() = default;
93 IdStringType(const IdStringType &) = default;
94 IdStringType &operator=(const IdStringType &) = default;
95 IdStringType(IdStringType &&) noexcept = default;
96 IdStringType &operator=(IdStringType &&) noexcept = default;
97 ~IdStringType() = default;
98
99 private:
100 const Derived & self() const { return *static_cast<const Derived*>( this ); }
101
102 public:
103 IdString idStr() const { return self()._str; }
104
105 bool empty() const { return idStr().empty(); }
106 unsigned size() const { return idStr().size(); }
107 const char * c_str() const { return idStr().c_str(); }
108 std::string asString() const { return idStr().asString(); }
109
110#ifdef __cpp_lib_string_view
111 std::string_view asStringView() const { return idStr().asStringView(); }
112 explicit operator std::string_view() const { return asStringView(); }
113#endif
114
115 IdType id() const { return idStr().id(); }
116
117 public:
119 explicit operator bool() const
120 { return ! empty(); }
121
123 explicit operator IdString() const
124 { return idStr(); }
125
127 explicit operator std::string() const
128 { return asString(); }
129
130 public:
131 // - break it down to idString/const char* <=> idString/cont char*
132 // - handle idString(0)/NULL being the least value
133 // - everything else goes to _doCompare (no NULL)
134 static int compare( const Derived & lhs, const Derived & rhs ) { return compare( lhs.idStr(), rhs.idStr() ); }
135 static int compare( const Derived & lhs, const IdString & rhs ) { return compare( lhs.idStr(), rhs ); }
136 static int compare( const Derived & lhs, const std::string & rhs ) { return compare( lhs.idStr(), rhs.c_str() ); }
137 static int compare( const Derived & lhs, const char * rhs ) { return compare( lhs.idStr(), rhs );}
138
139 static int compare( const IdString & lhs, const Derived & rhs ) { return compare( lhs, rhs.idStr() ); }
140 static int compare( const IdString & lhs, const IdString & rhs ) { return lhs == rhs ? 0 : Derived::_doCompare( (lhs ? lhs.c_str() : (const char *)0 ),
141 (rhs ? rhs.c_str() : (const char *)0 ) ); }
142 static int compare( const IdString & lhs, const std::string & rhs ) { return compare( lhs, rhs.c_str() ); }
143 static int compare( const IdString & lhs, const char * rhs ) { return Derived::_doCompare( (lhs ? lhs.c_str() : (const char *)0 ), rhs ); }
144
145 static int compare( const std::string & lhs, const Derived & rhs ) { return compare( lhs.c_str(), rhs.idStr() ); }
146 static int compare( const std::string & lhs, const IdString & rhs ) { return compare( lhs.c_str(), rhs ); }
147 static int compare( const std::string & lhs, const std::string & rhs ) { return compare( lhs.c_str(), rhs.c_str() ); }
148 static int compare( const std::string & lhs, const char * rhs ) { return compare( lhs.c_str(), rhs ); }
149
150 static int compare( const char * lhs, const Derived & rhs ) { return compare( lhs, rhs.idStr() ); }
151 static int compare( const char * lhs, const IdString & rhs ) { return Derived::_doCompare( lhs, (rhs ? rhs.c_str() : (const char *)0 ) ); }
152 static int compare( const char * lhs, const std::string & rhs ) { return compare( lhs, rhs.c_str() ); }
153 static int compare( const char * lhs, const char * rhs ) { return Derived::_doCompare( lhs, rhs ); }
154
155 public:
156 int compare( const Derived & rhs ) const { return compare( idStr(), rhs.idStr() ); }
157 int compare( const IdStringType & rhs ) const { return compare( idStr(), rhs.idStr() ); }
158 int compare( const IdString & rhs ) const { return compare( idStr(), rhs ); }
159 int compare( const std::string & rhs ) const { return compare( idStr(), rhs.c_str() ); }
160 int compare( const char * rhs ) const { return compare( idStr(), rhs ); }
161
162 private:
163 static inline int _doCompare( const char * lhs, const char * rhs ) ZYPP_API
164 {
165 if ( ! lhs ) return rhs ? -1 : 0;
166 return rhs ? ::strcmp( lhs, rhs ) : 1;
167 }
168 };
169
170
172 template <class Derived>
173 inline std::ostream & operator<<( std::ostream & str, const IdStringType<Derived> & obj )
174 { return str << obj.c_str(); }
175
177 template <class Derived>
178 inline bool operator==( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
179 { return lhs.compare( rhs ) == 0; }
180
181 template <class Derived>
182 inline bool operator==( const IdStringType<Derived> & lhs, const IdString & rhs )
183 { return lhs.compare( rhs ) == 0; }
184
185 template <class Derived>
186 inline bool operator==( const IdStringType<Derived> & lhs, const char * rhs )
187 { return lhs.compare( rhs ) == 0; }
188
189 template <class Derived>
190 inline bool operator==( const IdStringType<Derived> & lhs, const std::string & rhs )
191 { return lhs.compare( rhs ) == 0; }
192
193 template <class Derived>
194 inline bool operator==( const IdString & lhs, const IdStringType<Derived> & rhs )
195 { return rhs.compare( lhs ) == 0; }
196
197 template <class Derived>
198 inline bool operator==( const char * lhs, const IdStringType<Derived> & rhs )
199 { return rhs.compare( lhs ) == 0; }
200
201 template <class Derived>
202 inline bool operator==( const std::string & lhs, const IdStringType<Derived> & rhs )
203 { return rhs.compare( lhs ) == 0; }
204
206 template <class Derived>
207 inline bool operator!=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
208 { return lhs.compare( rhs ) != 0; }
209
210 template <class Derived>
211 inline bool operator!=( const IdStringType<Derived> & lhs, const IdString & rhs )
212 { return lhs.compare( rhs ) != 0; }
213
214 template <class Derived>
215 inline bool operator!=( const IdStringType<Derived> & lhs, const char * rhs )
216 { return lhs.compare( rhs ) != 0; }
217
218 template <class Derived>
219 inline bool operator!=( const IdStringType<Derived> & lhs, const std::string & rhs )
220 { return lhs.compare( rhs ) != 0; }
221
222 template <class Derived>
223 inline bool operator!=( const IdString & lhs, const IdStringType<Derived> & rhs )
224 { return rhs.compare( lhs ) != 0; }
225
226 template <class Derived>
227 inline bool operator!=( const char * lhs, const IdStringType<Derived> & rhs )
228 { return rhs.compare( lhs ) != 0; }
229
230 template <class Derived>
231 inline bool operator!=( const std::string & lhs, const IdStringType<Derived> & rhs )
232 { return rhs.compare( lhs ) != 0; }
233
235 template <class Derived>
236 inline bool operator<( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
237 { return lhs.compare( rhs ) < 0; }
238
239 template <class Derived>
240 inline bool operator<( const IdStringType<Derived> & lhs, const IdString & rhs )
241 { return lhs.compare( rhs ) < 0; }
242
243 template <class Derived>
244 inline bool operator<( const IdStringType<Derived> & lhs, const char * rhs )
245 { return lhs.compare( rhs ) < 0; }
246
247 template <class Derived>
248 inline bool operator<( const IdStringType<Derived> & lhs, const std::string & rhs )
249 { return lhs.compare( rhs ) < 0; }
250
251 template <class Derived>
252 inline bool operator<( const IdString & lhs, const IdStringType<Derived> & rhs )
253 { return rhs.compare( lhs ) >= 0; }
254
255 template <class Derived>
256 inline bool operator<( const char * lhs, const IdStringType<Derived> & rhs )
257 { return rhs.compare( lhs ) >= 0; }
258
259 template <class Derived>
260 inline bool operator<( const std::string & lhs, const IdStringType<Derived> & rhs )
261 { return rhs.compare( lhs ) >= 0; }
262
264 template <class Derived>
265 inline bool operator<=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
266 { return lhs.compare( rhs ) <= 0; }
267
268 template <class Derived>
269 inline bool operator<=( const IdStringType<Derived> & lhs, const IdString & rhs )
270 { return lhs.compare( rhs ) <= 0; }
271
272 template <class Derived>
273 inline bool operator<=( const IdStringType<Derived> & lhs, const char * rhs )
274 { return lhs.compare( rhs ) <= 0; }
275
276 template <class Derived>
277 inline bool operator<=( const IdStringType<Derived> & lhs, const std::string & rhs )
278 { return lhs.compare( rhs ) <= 0; }
279
280 template <class Derived>
281 inline bool operator<=( const IdString & lhs, const IdStringType<Derived> & rhs )
282 { return rhs.compare( lhs ) > 0; }
283
284 template <class Derived>
285 inline bool operator<=( const char * lhs, const IdStringType<Derived> & rhs )
286 { return rhs.compare( lhs ) > 0; }
287
288 template <class Derived>
289 inline bool operator<=( const std::string & lhs, const IdStringType<Derived> & rhs )
290 { return rhs.compare( lhs ) > 0; }
291
293 template <class Derived>
294 inline bool operator>( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
295 { return lhs.compare( rhs ) > 0; }
296
297 template <class Derived>
298 inline bool operator>( const IdStringType<Derived> & lhs, const IdString & rhs )
299 { return lhs.compare( rhs ) > 0; }
300
301 template <class Derived>
302 inline bool operator>( const IdStringType<Derived> & lhs, const char * rhs )
303 { return lhs.compare( rhs ) > 0; }
304
305 template <class Derived>
306 inline bool operator>( const IdStringType<Derived> & lhs, const std::string & rhs )
307 { return lhs.compare( rhs ) > 0; }
308
309 template <class Derived>
310 inline bool operator>( const IdString & lhs, const IdStringType<Derived> & rhs )
311 { return rhs.compare( lhs ) <= 0; }
312
313 template <class Derived>
314 inline bool operator>( const char * lhs, const IdStringType<Derived> & rhs )
315 { return rhs.compare( lhs ) <= 0; }
316
317 template <class Derived>
318 inline bool operator>( const std::string & lhs, const IdStringType<Derived> & rhs )
319 { return rhs.compare( lhs ) <= 0; }
320
322 template <class Derived>
323 inline bool operator>=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
324 { return lhs.compare( rhs ) >= 0; }
325
326 template <class Derived>
327 inline bool operator>=( const IdStringType<Derived> & lhs, const IdString & rhs )
328 { return lhs.compare( rhs ) >= 0; }
329
330 template <class Derived>
331 inline bool operator>=( const IdStringType<Derived> & lhs, const char * rhs )
332 { return lhs.compare( rhs ) >= 0; }
333
334 template <class Derived>
335 inline bool operator>=( const IdStringType<Derived> & lhs, const std::string & rhs )
336 { return lhs.compare( rhs ) >= 0; }
337
338 template <class Derived>
339 inline bool operator>=( const IdString & lhs, const IdStringType<Derived> & rhs )
340 { return rhs.compare( lhs ) < 0; }
341
342 template <class Derived>
343 inline bool operator>=( const char * lhs, const IdStringType<Derived> & rhs )
344 { return rhs.compare( lhs ) < 0; }
345
346 template <class Derived>
347 inline bool operator>=( const std::string & lhs, const IdStringType<Derived> & rhs )
348 { return rhs.compare( lhs ) < 0; }
349
351} // namespace zypp
353#endif // ZYPP_IDSTRINGTYPE_H
Base class for creating IdString based types.
IdString::IdType IdType
IdStringType(IdStringType &&) noexcept=default
static int compare(const char *lhs, const std::string &rhs)
static int compare(const Derived &lhs, const IdString &rhs)
int compare(const std::string &rhs) const
const Derived & self() const
bool operator<=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
LessEqual.
int compare(const char *rhs) const
IdString idStr() const
static int compare(const std::string &lhs, const Derived &rhs)
bool operator<(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Less.
static int compare(const IdString &lhs, const IdString &rhs)
bool operator==(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Equal.
bool operator>=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
GreaterEqual.
IdStringType()=default
IdStringType & operator=(const IdStringType &)=default
static int compare(const char *lhs, const char *rhs)
static int compare(const IdString &lhs, const std::string &rhs)
const char * c_str() const
static int compare(const char *lhs, const Derived &rhs)
int compare(const IdStringType &rhs) const
bool operator!=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
NotEqual.
static int compare(const Derived &lhs, const char *rhs)
static int compare(const std::string &lhs, const std::string &rhs)
bool empty() const
static int compare(const std::string &lhs, const char *rhs)
unsigned size() const
static int compare(const char *lhs, const IdString &rhs)
static int _doCompare(const char *lhs, const char *rhs) ZYPP_API
bool operator>(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Greater.
IdType id() const
IdStringType(const IdStringType &)=default
static int compare(const std::string &lhs, const IdString &rhs)
std::ostream & operator<<(std::ostream &str, const IdStringType< Derived > &obj)
Stream output.
std::string asString() const
int compare(const Derived &rhs) const
static int compare(const IdString &lhs, const Derived &rhs)
static int compare(const Derived &lhs, const Derived &rhs)
int compare(const IdString &rhs) const
static int compare(const IdString &lhs, const char *rhs)
static int compare(const Derived &lhs, const std::string &rhs)
Access to the sat-pools string space.
Definition IdString.h:44
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:46
constexpr bool empty() const
Whether the string is empty.
Definition IdString.h:88
IdType id() const
Expert backdoor.
Definition IdString.h:133
std::string asString() const
Conversion to std::string
Definition IdString.h:99
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
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:215
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:231
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
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:199
Backlink to the associated PoolImpl.
Definition PoolMember.h:89