libzypp  17.38.7
IdString.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_SAT_IDSTR_H
13 #define ZYPP_SAT_IDSTR_H
14 
15 #include <iosfwd>
16 #include <string>
17 #include <string_view>
18 #include <unordered_set>
19 
20 #include <boost/utility/string_ref_fwd.hpp>
21 
22 #include <zypp-core/Globals.h>
23 #include <zypp-core/base/Hash.h>
24 
26 
27 
28 #if ( LEGACY(1735) ) && !ZYPPNG
30 #endif
31 
33 namespace zypp
34 {
35 
36  class IdString;
37  using IdStringSet = std::unordered_set<IdString>;
38 
40  //
41  // CLASS NAME : IdString
42  //
52 #if ( LEGACY(1735) ) && !ZYPPNG
53  : protected sat::detail::PoolMember
54 #endif
55  {
56  public:
58 
59  public:
61  constexpr IdString() : _id( sat::detail::emptyId ) {}
62 
64  constexpr explicit IdString( IdType id_r ) : _id( id_r ) {}
65 
67  explicit IdString( const char * str_r );
68 
70  IdString( const char * str_r, unsigned len_r );
71 
73  explicit IdString( const std::string & str_r );
74 
76  explicit IdString( boost::string_ref str_r );
77 
78 #ifdef __cpp_lib_string_view
79  explicit IdString( std::string_view str_r )
80  : IdString( str_r.data(), str_r.size() )
81  {}
82 #endif
83 
84  public:
86  static const IdString Null;
87 
89  static const IdString Empty;
90 
91  public:
93  constexpr explicit operator bool() const
94  { return _id; }
95 
99  constexpr bool empty() const
100  { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
101 
103  unsigned size() const;
104 
105  public:
107  const char * c_str() const;
108 
110  std::string asString() const
111  { return c_str(); }
112 
114  explicit operator std::string() const
115  { return asString(); }
116 
117 #ifdef __cpp_lib_string_view
118 
119  std::string_view asStringView() const
120  { return { c_str(), size() }; }
121 
123  explicit operator std::string_view() const
124  { return asStringView(); }
125 #endif
126 
127  public:
129  bool compareEQ( const IdString & rhs ) const
130  { return( _id == rhs.id() ); }
131 
133  int compare( const IdString & rhs ) const;
134 
136  int compare( const char * rhs ) const;
137 
139  int compare( const std::string & rhs ) const
140  { return compare( rhs.c_str() ); }
141 
142  public:
144  IdType id() const
145  { return _id; }
146 
147  private:
149  };
151 
153  std::ostream & operator<<( std::ostream & str, const IdString & obj ) ZYPP_API;
154 
156  std::ostream & dumpOn( std::ostream & str, const IdString & obj ) ZYPP_API;
157 
159  inline bool operator==( const IdString & lhs, const IdString & rhs )
160  { return lhs.compareEQ( rhs ); }
162  inline bool operator==( const IdString & lhs, const char * rhs )
163  { return lhs.compare( rhs ) == 0; }
165  inline bool operator==( const IdString & lhs, const std::string & rhs )
166  { return lhs.compare( rhs ) == 0; }
168  inline bool operator==( const char * lhs, const IdString & rhs )
169  { return rhs.compare( lhs ) == 0; }
171  inline bool operator==( const std::string & lhs, const IdString & rhs )
172  { return rhs.compare( lhs ) == 0; }
173 
175  inline bool operator!=( const IdString & lhs, const IdString & rhs )
176  { return ! lhs.compareEQ( rhs ); }
178  inline bool operator!=( const IdString & lhs, const char * rhs )
179  { return lhs.compare( rhs ) != 0; }
181  inline bool operator!=( const IdString & lhs, const std::string & rhs )
182  { return lhs.compare( rhs ) != 0; }
184  inline bool operator!=( const char * lhs, const IdString & rhs )
185  { return rhs.compare( lhs ) != 0; }
187  inline bool operator!=( const std::string & lhs, const IdString & rhs )
188  { return rhs.compare( lhs ) != 0; }
189 
191  inline bool operator<( const IdString & lhs, const IdString & rhs )
192  { return lhs.compare( rhs ) < 0; }
194  inline bool operator<( const IdString & lhs, const char * rhs )
195  { return lhs.compare( rhs ) < 0; }
197  inline bool operator<( const IdString & lhs, const std::string & rhs )
198  { return lhs.compare( rhs ) < 0; }
200  inline bool operator<( const char * lhs, const IdString & rhs )
201  { return rhs.compare( lhs ) >= 0; }
203  inline bool operator<( const std::string & lhs, const IdString & rhs )
204  { return rhs.compare( lhs ) >= 0; }
205 
207  inline bool operator<=( const IdString & lhs, const IdString & rhs )
208  { return lhs.compare( rhs ) <= 0; }
210  inline bool operator<=( const IdString & lhs, const char * rhs )
211  { return lhs.compare( rhs ) <= 0; }
213  inline bool operator<=( const IdString & lhs, const std::string & rhs )
214  { return lhs.compare( rhs ) <= 0; }
216  inline bool operator<=( const char * lhs, const IdString & rhs )
217  { return rhs.compare( lhs ) > 0; }
219  inline bool operator<=( const std::string & lhs, const IdString & rhs )
220  { return rhs.compare( lhs ) > 0; }
221 
223  inline bool operator>( const IdString & lhs, const IdString & rhs )
224  { return lhs.compare( rhs ) > 0; }
226  inline bool operator>( const IdString & lhs, const char * rhs )
227  { return lhs.compare( rhs ) > 0; }
229  inline bool operator>( const IdString & lhs, const std::string & rhs )
230  { return lhs.compare( rhs ) > 0; }
232  inline bool operator>( const char * lhs, const IdString & rhs )
233  { return rhs.compare( lhs ) <= 0; }
235  inline bool operator>( const std::string & lhs, const IdString & rhs )
236  { return rhs.compare( lhs ) <= 0; }
237 
239  inline bool operator>=( const IdString & lhs, const IdString & rhs )
240  { return lhs.compare( rhs ) >= 0; }
242  inline bool operator>=( const IdString & lhs, const char * rhs )
243  { return lhs.compare( rhs ) >= 0; }
245  inline bool operator>=( const IdString & lhs, const std::string & rhs )
246  { return lhs.compare( rhs ) >= 0; }
248  inline bool operator>=( const char * lhs, const IdString & rhs )
249  { return rhs.compare( lhs ) < 0; }
251  inline bool operator>=( const std::string & lhs, const IdString & rhs )
252  { return rhs.compare( lhs ) < 0; }
253 
255 } // namespace zypp
257 
259 
260 #endif // ZYPP_SAT_IDSTR_H
#define LEGACY(CL)
Legacy code we still support.
Definition: Globals.h:36
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition: Capability.h:309
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition: IdString.cc:54
int compare(const std::string &rhs) const
Definition: IdString.h:139
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition: Patch.cc:122
bool operator>(const IdString &lhs, const IdString &rhs)
relates: IdString Greater
Definition: IdString.h:223
bool compareEQ(const IdString &rhs) const
Fast compare equal.
Definition: IdString.h:129
IdType id() const
Expert backdoor.
Definition: IdString.h:144
IdType _id
Definition: IdString.h:148
String related utilities and Regular expression matching.
int IdType
Generic Id type.
Definition: PoolDefines.h:42
Access to the sat-pools string space.
Definition: IdString.h:51
sat::detail::IdType IdType
Definition: IdString.h:57
constexpr IdString()
Default ctor, empty string.
Definition: IdString.h:61
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:99
std::unordered_set< IdString > IdStringSet
Definition: IdString.h:37
static const IdString Empty
Empty string.
Definition: IdString.h:89
Backlink to the associated PoolImpl.
Definition: PoolMember.h:52
static const IdType emptyId(1)
SetCompare compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
relates: SetRelationMixin Compare sets
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition: Arch.h:173
Provides API related macros.
ZYPP_DEFINE_ID_HASHABLE(::zypp::IdString)
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition: Capability.h:313
bool operator>=(const IdString &lhs, const IdString &rhs)
relates: IdString GreaterEqual
Definition: IdString.h:239
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
Definition: Capability.cc:589
bool operator<=(const IdString &lhs, const IdString &rhs)
relates: IdString LessEqual
Definition: IdString.h:207
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:86
static const IdType noId(0)
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
Definition: Capability.h:317
std::string asString() const
Conversion to std::string
Definition: IdString.h:110
constexpr IdString(IdType id_r)
Ctor from id.
Definition: IdString.h:64
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition: Capabilities.cc:65
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::IdString IdString
Definition: idstring.h:16