libzypp: zypp/IdStringType.h Source File

libzypp 17.36.6

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>
86 class IdStringType : protected sat::detail::PoolMember
87 {
88 public:
89 using IdType = IdString::IdType;
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
IdString.h
bool
zypp::IdStringType
Base class for creating IdString based types.
Definition IdStringType.h:87
zypp::IdStringType::IdType
IdString::IdType IdType
Definition IdStringType.h:89
zypp::IdStringType::IdStringType
IdStringType(IdStringType &&) noexcept=default
zypp::IdStringType::compare
static int compare(const char *lhs, const std::string &rhs)
Definition IdStringType.h:152
zypp::IdStringType::compare
static int compare(const Derived &lhs, const IdString &rhs)
Definition IdStringType.h:135
zypp::IdStringType::compare
int compare(const std::string &rhs) const
Definition IdStringType.h:159
zypp::IdStringType::self
const Derived & self() const
Definition IdStringType.h:100
zypp::IdStringType::operator<=
bool operator<=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
LessEqual.
Definition IdStringType.h:265
zypp::IdStringType::compare
int compare(const char *rhs) const
Definition IdStringType.h:160
zypp::IdStringType::idStr
IdString idStr() const
Definition IdStringType.h:103
zypp::IdStringType::compare
static int compare(const std::string &lhs, const Derived &rhs)
Definition IdStringType.h:145
zypp::IdStringType::operator<
bool operator<(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Less.
Definition IdStringType.h:236
zypp::IdStringType::compare
static int compare(const IdString &lhs, const IdString &rhs)
Definition IdStringType.h:140
zypp::IdStringType::operator==
bool operator==(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Equal.
Definition IdStringType.h:178
zypp::IdStringType::operator>=
bool operator>=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
GreaterEqual.
Definition IdStringType.h:323
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:153
zypp::IdStringType::compare
static int compare(const IdString &lhs, const std::string &rhs)
Definition IdStringType.h:142
zypp::IdStringType::c_str
const char * c_str() const
Definition IdStringType.h:107
zypp::IdStringType::compare
static int compare(const char *lhs, const Derived &rhs)
Definition IdStringType.h:150
zypp::IdStringType::compare
int compare(const IdStringType &rhs) const
Definition IdStringType.h:157
zypp::IdStringType::operator!=
bool operator!=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
NotEqual.
Definition IdStringType.h:207
zypp::IdStringType::compare
static int compare(const Derived &lhs, const char *rhs)
Definition IdStringType.h:137
zypp::IdStringType::compare
static int compare(const std::string &lhs, const std::string &rhs)
Definition IdStringType.h:147
zypp::IdStringType::empty
bool empty() const
Definition IdStringType.h:105
zypp::IdStringType::compare
static int compare(const std::string &lhs, const char *rhs)
Definition IdStringType.h:148
zypp::IdStringType::size
unsigned size() const
Definition IdStringType.h:106
zypp::IdStringType::compare
static int compare(const char *lhs, const IdString &rhs)
Definition IdStringType.h:151
zypp::IdStringType::_doCompare
static int _doCompare(const char *lhs, const char *rhs) ZYPP_API
Definition IdStringType.h:163
zypp::IdStringType::operator>
bool operator>(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Greater.
Definition IdStringType.h:294
zypp::IdStringType::id
IdType id() const
Definition IdStringType.h:115
zypp::IdStringType::IdStringType
IdStringType(const IdStringType &)=default
zypp::IdStringType::compare
static int compare(const std::string &lhs, const IdString &rhs)
Definition IdStringType.h:146
zypp::IdStringType::operator<<
std::ostream & operator<<(std::ostream &str, const IdStringType< Derived > &obj)
Stream output.
Definition IdStringType.h:173
zypp::IdStringType::asString
std::string asString() const
Definition IdStringType.h:108
zypp::IdStringType::compare
int compare(const Derived &rhs) const
Definition IdStringType.h:156
zypp::IdStringType::compare
static int compare(const IdString &lhs, const Derived &rhs)
Definition IdStringType.h:139
zypp::IdStringType::compare
static int compare(const Derived &lhs, const Derived &rhs)
Definition IdStringType.h:134
zypp::IdStringType::compare
int compare(const IdString &rhs) const
Definition IdStringType.h:158
zypp::IdStringType::compare
static int compare(const IdString &lhs, const char *rhs)
Definition IdStringType.h:143
zypp::IdStringType::compare
static int compare(const Derived &lhs, const std::string &rhs)
Definition IdStringType.h:136
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:44
zypp::IdString::size
unsigned size() const
The strings size.
Definition IdString.cc:47
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *
Definition IdString.cc:50
zypp::IdString::IdType
sat::detail::IdType IdType
Definition IdString.h:46
zypp::IdString::empty
constexpr bool empty() const
Whether the string is empty.
Definition IdString.h:88
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:133
zypp::IdString::asString
std::string asString() const
Conversion to std::string
Definition IdString.h:99
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::operator<
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition StrMatcher.cc:340
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
zypp::operator>
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
zypp::operator>=
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
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
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<=
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
zypp::sat::detail::PoolMember
Backlink to the associated PoolImpl.
Definition PoolMember.h:89