libzypp 17.38.15

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#include <string.h> // for strcmp
17
18#if ( LEGACY(1735) ) && !ZYPPNG
19#include <zypp/sat/detail/PoolMember.h>
20#endif
21
23 namespace zypp
24{
25
27 //
28 // CLASS NAME : IdStringType<Derived>
29 //
90 template <class Derived>
91 class IdStringType
92 #if ( LEGACY(1735) ) && !ZYPPNG
93 : protected sat::detail::PoolMember
94 #endif
95 {
96 public:
97 using IdType = IdString::IdType;
98
99 protected:
100 IdStringType() = default;
101 IdStringType(const IdStringType &) = default;
102 IdStringType &operator=(const IdStringType &) = default;
103 IdStringType(IdStringType &&) noexcept = default;
104 IdStringType &operator=(IdStringType &&) noexcept = default;
105 ~IdStringType() = default;
106
107 private:
108 const Derived & self() const { return *static_cast<const Derived*>( this ); }
109
110 public:
111 IdString idStr() const { return self()._str; }
112
113 bool empty() const { return idStr().empty(); }
114 unsigned size() const { return idStr().size(); }
115 const char * c_str() const { return idStr().c_str(); }
116 std::string asString() const { return idStr().asString(); }
117
118#ifdef __cpp_lib_string_view
119 std::string_view asStringView() const { return idStr().asStringView(); }
120 explicit operator std::string_view() const { return asStringView(); }
121#endif
122
123 IdType id() const { return idStr().id(); }
124
125 public:
127 explicit operator bool() const
128 { return ! empty(); }
129
131 explicit operator IdString() const
132 { return idStr(); }
133
135 explicit operator std::string() const
136 { return asString(); }
137
138 public:
139 // - break it down to idString/const char* <=> idString/cont char*
140 // - handle idString(0)/NULL being the least value
141 // - everything else goes to _doCompare (no NULL)
142 static int compare( const Derived & lhs, const Derived & rhs ) { return compare( lhs.idStr(), rhs.idStr() ); }
143 static int compare( const Derived & lhs, const IdString & rhs ) { return compare( lhs.idStr(), rhs ); }
144 static int compare( const Derived & lhs, const std::string & rhs ) { return compare( lhs.idStr(), rhs.c_str() ); }
145 static int compare( const Derived & lhs, const char * rhs ) { return compare( lhs.idStr(), rhs );}
146
147 static int compare( const IdString & lhs, const Derived & rhs ) { return compare( lhs, rhs.idStr() ); }
148 static int compare( const IdString & lhs, const IdString & rhs ) { return lhs == rhs ? 0 : Derived::_doCompare( (lhs ? lhs.c_str() : (const char *)0 ),
149 (rhs ? rhs.c_str() : (const char *)0 ) ); }
150 static int compare( const IdString & lhs, const std::string & rhs ) { return compare( lhs, rhs.c_str() ); }
151 static int compare( const IdString & lhs, const char * rhs ) { return Derived::_doCompare( (lhs ? lhs.c_str() : (const char *)0 ), rhs ); }
152
153 static int compare( const std::string & lhs, const Derived & rhs ) { return compare( lhs.c_str(), rhs.idStr() ); }
154 static int compare( const std::string & lhs, const IdString & rhs ) { return compare( lhs.c_str(), rhs ); }
155 static int compare( const std::string & lhs, const std::string & rhs ) { return compare( lhs.c_str(), rhs.c_str() ); }
156 static int compare( const std::string & lhs, const char * rhs ) { return compare( lhs.c_str(), rhs ); }
157
158 static int compare( const char * lhs, const Derived & rhs ) { return compare( lhs, rhs.idStr() ); }
159 static int compare( const char * lhs, const IdString & rhs ) { return Derived::_doCompare( lhs, (rhs ? rhs.c_str() : (const char *)0 ) ); }
160 static int compare( const char * lhs, const std::string & rhs ) { return compare( lhs, rhs.c_str() ); }
161 static int compare( const char * lhs, const char * rhs ) { return Derived::_doCompare( lhs, rhs ); }
162
163 public:
164 int compare( const Derived & rhs ) const { return compare( idStr(), rhs.idStr() ); }
165 int compare( const IdStringType & rhs ) const { return compare( idStr(), rhs.idStr() ); }
166 int compare( const IdString & rhs ) const { return compare( idStr(), rhs ); }
167 int compare( const std::string & rhs ) const { return compare( idStr(), rhs.c_str() ); }
168 int compare( const char * rhs ) const { return compare( idStr(), rhs ); }
169
170 private:
171 static inline int _doCompare( const char * lhs, const char * rhs ) ZYPP_API
172 {
173 if ( ! lhs ) return rhs ? -1 : 0;
174 return rhs ? ::strcmp( lhs, rhs ) : 1;
175 }
176 };
177
178
180 template <class Derived>
181 inline std::ostream & operator<<( std::ostream & str, const IdStringType<Derived> & obj )
182 { return str << obj.c_str(); }
183
185 template <class Derived>
186 inline bool operator==( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
187 { return lhs.compare( rhs ) == 0; }
188
189 template <class Derived>
190 inline bool operator==( const IdStringType<Derived> & lhs, const IdString & rhs )
191 { return lhs.compare( rhs ) == 0; }
192
193 template <class Derived>
194 inline bool operator==( const IdStringType<Derived> & lhs, const char * rhs )
195 { return lhs.compare( rhs ) == 0; }
196
197 template <class Derived>
198 inline bool operator==( const IdStringType<Derived> & lhs, const std::string & rhs )
199 { return lhs.compare( rhs ) == 0; }
200
201 template <class Derived>
202 inline bool operator==( const IdString & lhs, const IdStringType<Derived> & rhs )
203 { return rhs.compare( lhs ) == 0; }
204
205 template <class Derived>
206 inline bool operator==( const char * lhs, const IdStringType<Derived> & rhs )
207 { return rhs.compare( lhs ) == 0; }
208
209 template <class Derived>
210 inline bool operator==( const std::string & lhs, const IdStringType<Derived> & rhs )
211 { return rhs.compare( lhs ) == 0; }
212
214 template <class Derived>
215 inline bool operator!=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
216 { return lhs.compare( rhs ) != 0; }
217
218 template <class Derived>
219 inline bool operator!=( const IdStringType<Derived> & lhs, const IdString & rhs )
220 { return lhs.compare( rhs ) != 0; }
221
222 template <class Derived>
223 inline bool operator!=( const IdStringType<Derived> & lhs, const char * rhs )
224 { return lhs.compare( rhs ) != 0; }
225
226 template <class Derived>
227 inline bool operator!=( const IdStringType<Derived> & lhs, const std::string & rhs )
228 { return lhs.compare( rhs ) != 0; }
229
230 template <class Derived>
231 inline bool operator!=( const IdString & lhs, const IdStringType<Derived> & rhs )
232 { return rhs.compare( lhs ) != 0; }
233
234 template <class Derived>
235 inline bool operator!=( const char * lhs, const IdStringType<Derived> & rhs )
236 { return rhs.compare( lhs ) != 0; }
237
238 template <class Derived>
239 inline bool operator!=( const std::string & lhs, const IdStringType<Derived> & rhs )
240 { return rhs.compare( lhs ) != 0; }
241
243 template <class Derived>
244 inline bool operator<( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
245 { return lhs.compare( rhs ) < 0; }
246
247 template <class Derived>
248 inline bool operator<( const IdStringType<Derived> & lhs, const IdString & rhs )
249 { return lhs.compare( rhs ) < 0; }
250
251 template <class Derived>
252 inline bool operator<( const IdStringType<Derived> & lhs, const char * rhs )
253 { return lhs.compare( rhs ) < 0; }
254
255 template <class Derived>
256 inline bool operator<( const IdStringType<Derived> & lhs, const std::string & rhs )
257 { return lhs.compare( rhs ) < 0; }
258
259 template <class Derived>
260 inline bool operator<( const IdString & lhs, const IdStringType<Derived> & rhs )
261 { return rhs.compare( lhs ) >= 0; }
262
263 template <class Derived>
264 inline bool operator<( const char * lhs, const IdStringType<Derived> & rhs )
265 { return rhs.compare( lhs ) >= 0; }
266
267 template <class Derived>
268 inline bool operator<( const std::string & lhs, const IdStringType<Derived> & rhs )
269 { return rhs.compare( lhs ) >= 0; }
270
272 template <class Derived>
273 inline bool operator<=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
274 { return lhs.compare( rhs ) <= 0; }
275
276 template <class Derived>
277 inline bool operator<=( const IdStringType<Derived> & lhs, const IdString & rhs )
278 { return lhs.compare( rhs ) <= 0; }
279
280 template <class Derived>
281 inline bool operator<=( const IdStringType<Derived> & lhs, const char * rhs )
282 { return lhs.compare( rhs ) <= 0; }
283
284 template <class Derived>
285 inline bool operator<=( const IdStringType<Derived> & lhs, const std::string & rhs )
286 { return lhs.compare( rhs ) <= 0; }
287
288 template <class Derived>
289 inline bool operator<=( const IdString & lhs, const IdStringType<Derived> & rhs )
290 { return rhs.compare( lhs ) > 0; }
291
292 template <class Derived>
293 inline bool operator<=( const char * lhs, const IdStringType<Derived> & rhs )
294 { return rhs.compare( lhs ) > 0; }
295
296 template <class Derived>
297 inline bool operator<=( const std::string & lhs, const IdStringType<Derived> & rhs )
298 { return rhs.compare( lhs ) > 0; }
299
301 template <class Derived>
302 inline bool operator>( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
303 { return lhs.compare( rhs ) > 0; }
304
305 template <class Derived>
306 inline bool operator>( const IdStringType<Derived> & lhs, const IdString & rhs )
307 { return lhs.compare( rhs ) > 0; }
308
309 template <class Derived>
310 inline bool operator>( const IdStringType<Derived> & lhs, const char * rhs )
311 { return lhs.compare( rhs ) > 0; }
312
313 template <class Derived>
314 inline bool operator>( const IdStringType<Derived> & lhs, const std::string & rhs )
315 { return lhs.compare( rhs ) > 0; }
316
317 template <class Derived>
318 inline bool operator>( const IdString & lhs, const IdStringType<Derived> & rhs )
319 { return rhs.compare( lhs ) <= 0; }
320
321 template <class Derived>
322 inline bool operator>( const char * lhs, const IdStringType<Derived> & rhs )
323 { return rhs.compare( lhs ) <= 0; }
324
325 template <class Derived>
326 inline bool operator>( const std::string & lhs, const IdStringType<Derived> & rhs )
327 { return rhs.compare( lhs ) <= 0; }
328
330 template <class Derived>
331 inline bool operator>=( const IdStringType<Derived> & lhs, const IdStringType<Derived> & rhs )
332 { return lhs.compare( rhs ) >= 0; }
333
334 template <class Derived>
335 inline bool operator>=( const IdStringType<Derived> & lhs, const IdString & rhs )
336 { return lhs.compare( rhs ) >= 0; }
337
338 template <class Derived>
339 inline bool operator>=( const IdStringType<Derived> & lhs, const char * rhs )
340 { return lhs.compare( rhs ) >= 0; }
341
342 template <class Derived>
343 inline bool operator>=( const IdStringType<Derived> & lhs, const std::string & rhs )
344 { return lhs.compare( rhs ) >= 0; }
345
346 template <class Derived>
347 inline bool operator>=( const IdString & lhs, const IdStringType<Derived> & rhs )
348 { return rhs.compare( lhs ) < 0; }
349
350 template <class Derived>
351 inline bool operator>=( const char * lhs, const IdStringType<Derived> & rhs )
352 { return rhs.compare( lhs ) < 0; }
353
354 template <class Derived>
355 inline bool operator>=( const std::string & lhs, const IdStringType<Derived> & rhs )
356 { return rhs.compare( lhs ) < 0; }
357
359} // namespace zypp
361#endif // ZYPP_IDSTRINGTYPE_H
LEGACY
#define LEGACY(CL)
Legacy code we still support.
Definition Globals.h:40
IdString.h
PoolMember.h
bool
zypp::IdStringType
Base class for creating IdString based types.
Definition IdStringType.h:95
zypp::IdStringType::IdType
IdString::IdType IdType
Definition IdStringType.h:97
zypp::IdStringType::IdStringType
IdStringType(IdStringType &&) noexcept=default
zypp::IdStringType::compare
static int compare(const char *lhs, const std::string &rhs)
Definition IdStringType.h:160
zypp::IdStringType::compare
static int compare(const Derived &lhs, const IdString &rhs)
Definition IdStringType.h:143
zypp::IdStringType::compare
int compare(const std::string &rhs) const
Definition IdStringType.h:167
zypp::IdStringType::self
const Derived & self() const
Definition IdStringType.h:108
zypp::IdStringType::compare
int compare(const char *rhs) const
Definition IdStringType.h:168
zypp::IdStringType::idStr
IdString idStr() const
Definition IdStringType.h:111
zypp::IdStringType::compare
static int compare(const std::string &lhs, const Derived &rhs)
Definition IdStringType.h:153
zypp::IdStringType::compare
static int compare(const IdString &lhs, const IdString &rhs)
Definition IdStringType.h:148
zypp::IdStringType::IdStringType
IdStringType()=default
zypp::IdStringType::operator=
IdStringType & operator=(const IdStringType &)=default
zypp::IdStringType::compare
static int compare(const char *lhs, const char *rhs)
Definition IdStringType.h:161
zypp::IdStringType::compare
static int compare(const IdString &lhs, const std::string &rhs)
Definition IdStringType.h:150
zypp::IdStringType::c_str
const char * c_str() const
Definition IdStringType.h:115
zypp::IdStringType::compare
static int compare(const char *lhs, const Derived &rhs)
Definition IdStringType.h:158
zypp::IdStringType::compare
int compare(const IdStringType &rhs) const
Definition IdStringType.h:165
zypp::IdStringType::compare
static int compare(const Derived &lhs, const char *rhs)
Definition IdStringType.h:145
zypp::IdStringType::compare
static int compare(const std::string &lhs, const std::string &rhs)
Definition IdStringType.h:155
zypp::IdStringType::empty
bool empty() const
Definition IdStringType.h:113
zypp::IdStringType::compare
static int compare(const std::string &lhs, const char *rhs)
Definition IdStringType.h:156
zypp::IdStringType::size
unsigned size() const
Definition IdStringType.h:114
zypp::IdStringType::compare
static int compare(const char *lhs, const IdString &rhs)
Definition IdStringType.h:159
zypp::IdStringType::_doCompare
static int _doCompare(const char *lhs, const char *rhs) ZYPP_API
Definition IdStringType.h:171
zypp::IdStringType::id
IdType id() const
Definition IdStringType.h:123
zypp::IdStringType::IdStringType
IdStringType(const IdStringType &)=default
zypp::IdStringType::compare
static int compare(const std::string &lhs, const IdString &rhs)
Definition IdStringType.h:154
zypp::IdStringType::asString
std::string asString() const
Definition IdStringType.h:116
zypp::IdStringType::compare
int compare(const Derived &rhs) const
Definition IdStringType.h:164
zypp::IdStringType::compare
static int compare(const IdString &lhs, const Derived &rhs)
Definition IdStringType.h:147
zypp::IdStringType::compare
static int compare(const Derived &lhs, const Derived &rhs)
Definition IdStringType.h:142
zypp::IdStringType::compare
int compare(const IdString &rhs) const
Definition IdStringType.h:166
zypp::IdStringType::compare
static int compare(const IdString &lhs, const char *rhs)
Definition IdStringType.h:151
zypp::IdStringType::compare
static int compare(const Derived &lhs, const std::string &rhs)
Definition IdStringType.h:144
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *.
Definition IdString.cc:51
zypp::IdString::IdType
sat::detail::IdType IdType
Definition IdString.h:57
zypp::IdString::IdString
constexpr IdString()
Default ctor, empty string.
Definition IdString.h:61
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::operator>
bool operator>(const IdString &lhs, const IdString &rhs)
relates: IdString Greater
Definition IdString.h:223
zypp::operator>=
bool operator>=(const IdString &lhs, const IdString &rhs)
relates: IdString GreaterEqual
Definition IdString.h:239
zypp::operator<
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
Definition Capability.h:317
zypp::operator!=
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:313
zypp::operator<=
bool operator<=(const IdString &lhs, const IdString &rhs)
relates: IdString LessEqual
Definition IdString.h:207
zypp::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:309
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
string.h
zypp::sat::detail::PoolMember
Backlink to the associated PoolImpl.
Definition PoolMember.h:53