libzypp  17.36.3
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 
18 namespace 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  };
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; }
181  template <class Derived>
182  inline bool operator==( const IdStringType<Derived> & lhs, const IdString & rhs )
183  { return lhs.compare( rhs ) == 0; }
185  template <class Derived>
186  inline bool operator==( const IdStringType<Derived> & lhs, const char * rhs )
187  { return lhs.compare( rhs ) == 0; }
189  template <class Derived>
190  inline bool operator==( const IdStringType<Derived> & lhs, const std::string & rhs )
191  { return lhs.compare( rhs ) == 0; }
193  template <class Derived>
194  inline bool operator==( const IdString & lhs, const IdStringType<Derived> & rhs )
195  { return rhs.compare( lhs ) == 0; }
197  template <class Derived>
198  inline bool operator==( const char * lhs, const IdStringType<Derived> & rhs )
199  { return rhs.compare( lhs ) == 0; }
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; }
210  template <class Derived>
211  inline bool operator!=( const IdStringType<Derived> & lhs, const IdString & rhs )
212  { return lhs.compare( rhs ) != 0; }
214  template <class Derived>
215  inline bool operator!=( const IdStringType<Derived> & lhs, const char * rhs )
216  { return lhs.compare( rhs ) != 0; }
218  template <class Derived>
219  inline bool operator!=( const IdStringType<Derived> & lhs, const std::string & rhs )
220  { return lhs.compare( rhs ) != 0; }
222  template <class Derived>
223  inline bool operator!=( const IdString & lhs, const IdStringType<Derived> & rhs )
224  { return rhs.compare( lhs ) != 0; }
226  template <class Derived>
227  inline bool operator!=( const char * lhs, const IdStringType<Derived> & rhs )
228  { return rhs.compare( lhs ) != 0; }
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; }
239  template <class Derived>
240  inline bool operator<( const IdStringType<Derived> & lhs, const IdString & rhs )
241  { return lhs.compare( rhs ) < 0; }
243  template <class Derived>
244  inline bool operator<( const IdStringType<Derived> & lhs, const char * rhs )
245  { return lhs.compare( rhs ) < 0; }
247  template <class Derived>
248  inline bool operator<( const IdStringType<Derived> & lhs, const std::string & rhs )
249  { return lhs.compare( rhs ) < 0; }
251  template <class Derived>
252  inline bool operator<( const IdString & lhs, const IdStringType<Derived> & rhs )
253  { return rhs.compare( lhs ) >= 0; }
255  template <class Derived>
256  inline bool operator<( const char * lhs, const IdStringType<Derived> & rhs )
257  { return rhs.compare( lhs ) >= 0; }
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; }
268  template <class Derived>
269  inline bool operator<=( const IdStringType<Derived> & lhs, const IdString & rhs )
270  { return lhs.compare( rhs ) <= 0; }
272  template <class Derived>
273  inline bool operator<=( const IdStringType<Derived> & lhs, const char * rhs )
274  { return lhs.compare( rhs ) <= 0; }
276  template <class Derived>
277  inline bool operator<=( const IdStringType<Derived> & lhs, const std::string & rhs )
278  { return lhs.compare( rhs ) <= 0; }
280  template <class Derived>
281  inline bool operator<=( const IdString & lhs, const IdStringType<Derived> & rhs )
282  { return rhs.compare( lhs ) > 0; }
284  template <class Derived>
285  inline bool operator<=( const char * lhs, const IdStringType<Derived> & rhs )
286  { return rhs.compare( lhs ) > 0; }
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; }
297  template <class Derived>
298  inline bool operator>( const IdStringType<Derived> & lhs, const IdString & rhs )
299  { return lhs.compare( rhs ) > 0; }
301  template <class Derived>
302  inline bool operator>( const IdStringType<Derived> & lhs, const char * rhs )
303  { return lhs.compare( rhs ) > 0; }
305  template <class Derived>
306  inline bool operator>( const IdStringType<Derived> & lhs, const std::string & rhs )
307  { return lhs.compare( rhs ) > 0; }
309  template <class Derived>
310  inline bool operator>( const IdString & lhs, const IdStringType<Derived> & rhs )
311  { return rhs.compare( lhs ) <= 0; }
313  template <class Derived>
314  inline bool operator>( const char * lhs, const IdStringType<Derived> & rhs )
315  { return rhs.compare( lhs ) <= 0; }
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; }
326  template <class Derived>
327  inline bool operator>=( const IdStringType<Derived> & lhs, const IdString & rhs )
328  { return lhs.compare( rhs ) >= 0; }
330  template <class Derived>
331  inline bool operator>=( const IdStringType<Derived> & lhs, const char * rhs )
332  { return lhs.compare( rhs ) >= 0; }
334  template <class Derived>
335  inline bool operator>=( const IdStringType<Derived> & lhs, const std::string & rhs )
336  { return lhs.compare( rhs ) >= 0; }
338  template <class Derived>
339  inline bool operator>=( const IdString & lhs, const IdStringType<Derived> & rhs )
340  { return rhs.compare( lhs ) < 0; }
342  template <class Derived>
343  inline bool operator>=( const char * lhs, const IdStringType<Derived> & rhs )
344  { return rhs.compare( lhs ) < 0; }
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
static int compare(const std::string &lhs, const char *rhs)
Definition: IdStringType.h:148
IdString idStr() const
Definition: IdStringType.h:103
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition: IdString.cc:53
IdType id() const
Definition: IdStringType.h:115
static int compare(const char *lhs, const char *rhs)
Definition: IdStringType.h:153
static int compare(const IdString &lhs, const std::string &rhs)
Definition: IdStringType.h:142
int compare(const IdStringType &rhs) const
Definition: IdStringType.h:157
IdType id() const
Expert backdoor.
Definition: IdString.h:133
String related utilities and Regular expression matching.
static int compare(const char *lhs, const std::string &rhs)
Definition: IdStringType.h:152
Access to the sat-pools string space.
Definition: IdString.h:43
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
sat::detail::IdType IdType
Definition: IdString.h:46
Base class for creating IdString based types.
Definition: IdStringType.h:86
static int _doCompare(const char *lhs, const char *rhs) ZYPP_API
Definition: IdStringType.h:163
static int compare(const std::string &lhs, const IdString &rhs)
Definition: IdStringType.h:146
static int compare(const IdString &lhs, const char *rhs)
Definition: IdStringType.h:143
static int compare(const Derived &lhs, const Derived &rhs)
Definition: IdStringType.h:134
static int compare(const Derived &lhs, const IdString &rhs)
Definition: IdStringType.h:135
static int compare(const Derived &lhs, const char *rhs)
Definition: IdStringType.h:137
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:88
Backlink to the associated PoolImpl.
Definition: PoolMember.h:88
std::string asString() const
Definition: IdStringType.h:108
static int compare(const std::string &lhs, const std::string &rhs)
Definition: IdStringType.h:147
bool empty() const
Definition: IdStringType.h:105
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
bool operator>=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Definition: IdStringType.h:323
static int compare(const char *lhs, const IdString &rhs)
Definition: IdStringType.h:151
static int compare(const Derived &lhs, const std::string &rhs)
Definition: IdStringType.h:136
bool operator>=(const IdString &lhs, const char *rhs)
Definition: IdString.h:231
unsigned size() const
The strings size.
Definition: IdString.cc:47
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
bool operator>(const IdString &lhs, const char *rhs)
Definition: IdString.h:215
IdStringType()=default
const Derived & self() const
Definition: IdStringType.h:100
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
bool operator==(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Definition: IdStringType.h:178
static int compare(const std::string &lhs, const Derived &rhs)
Definition: IdStringType.h:145
int compare(const Derived &rhs) const
Definition: IdStringType.h:156
bool operator>(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Definition: IdStringType.h:294
int compare(const IdString &rhs) const
Definition: IdStringType.h:158
static int compare(const IdString &lhs, const IdString &rhs)
Definition: IdStringType.h:140
static int compare(const char *lhs, const Derived &rhs)
Definition: IdStringType.h:150
std::string asString() const
Conversion to std::string
Definition: IdString.h:99
static int compare(const IdString &lhs, const Derived &rhs)
Definition: IdStringType.h:139
bool operator!=(const IdStringType< Derived > &lhs, const IdStringType< Derived > &rhs)
Definition: IdStringType.h:207
int compare(const char *rhs) const
Definition: IdStringType.h:160
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
unsigned size() const
Definition: IdStringType.h:106
IdStringType & operator=(const IdStringType &)=default
zypp::IdString IdString
Definition: idstring.h:16
const char * c_str() const
Definition: IdStringType.h:107
int compare(const std::string &rhs) const
Definition: IdStringType.h:159