libzypp: zypp/IdString.h Source File

libzypp 17.38.6

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
25#include <zypp/sat/detail/PoolDefines.h>
26
27
28#if ( LEGACY(1735) ) && !ZYPPNG
29#include <zypp/sat/detail/PoolMember.h>
30#endif
31
33namespace zypp
34{
35
36 class IdString;
37 using IdStringSet = std::unordered_set<IdString>;
38
40 //
41 // CLASS NAME : IdString
42 //
51 class ZYPP_API IdString
52#if ( LEGACY(1735) ) && !ZYPPNG
53 : protected sat::detail::PoolMember
54#endif
55 {
56 public:
57 using IdType = sat::detail::IdType;
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
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:
148 IdType _id;
149 };
150
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 ); }
161
162 inline bool operator==( const IdString & lhs, const char * rhs )
163 { return lhs.compare( rhs ) == 0; }
164
165 inline bool operator==( const IdString & lhs, const std::string & rhs )
166 { return lhs.compare( rhs ) == 0; }
167
168 inline bool operator==( const char * lhs, const IdString & rhs )
169 { return rhs.compare( lhs ) == 0; }
170
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 ); }
177
178 inline bool operator!=( const IdString & lhs, const char * rhs )
179 { return lhs.compare( rhs ) != 0; }
180
181 inline bool operator!=( const IdString & lhs, const std::string & rhs )
182 { return lhs.compare( rhs ) != 0; }
183
184 inline bool operator!=( const char * lhs, const IdString & rhs )
185 { return rhs.compare( lhs ) != 0; }
186
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; }
193
194 inline bool operator<( const IdString & lhs, const char * rhs )
195 { return lhs.compare( rhs ) < 0; }
196
197 inline bool operator<( const IdString & lhs, const std::string & rhs )
198 { return lhs.compare( rhs ) < 0; }
199
200 inline bool operator<( const char * lhs, const IdString & rhs )
201 { return rhs.compare( lhs ) >= 0; }
202
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; }
209
210 inline bool operator<=( const IdString & lhs, const char * rhs )
211 { return lhs.compare( rhs ) <= 0; }
212
213 inline bool operator<=( const IdString & lhs, const std::string & rhs )
214 { return lhs.compare( rhs ) <= 0; }
215
216 inline bool operator<=( const char * lhs, const IdString & rhs )
217 { return rhs.compare( lhs ) > 0; }
218
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; }
225
226 inline bool operator>( const IdString & lhs, const char * rhs )
227 { return lhs.compare( rhs ) > 0; }
228
229 inline bool operator>( const IdString & lhs, const std::string & rhs )
230 { return lhs.compare( rhs ) > 0; }
231
232 inline bool operator>( const char * lhs, const IdString & rhs )
233 { return rhs.compare( lhs ) <= 0; }
234
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; }
241
242 inline bool operator>=( const IdString & lhs, const char * rhs )
243 { return lhs.compare( rhs ) >= 0; }
244
245 inline bool operator>=( const IdString & lhs, const std::string & rhs )
246 { return lhs.compare( rhs ) >= 0; }
247
248 inline bool operator>=( const char * lhs, const IdString & rhs )
249 { return rhs.compare( lhs ) < 0; }
250
251 inline bool operator>=( const std::string & lhs, const IdString & rhs )
252 { return rhs.compare( lhs ) < 0; }
253
255} // namespace zypp
257
258 ZYPP_DEFINE_ID_HASHABLE( ::zypp::IdString );
259
260#endif // ZYPP_SAT_IDSTR_H
Globals.h
Provides API related macros.
LEGACY
#define LEGACY(CL)
Legacy code we still support.
Definition Globals.h:36
Hash.h
ZYPP_DEFINE_ID_HASHABLE
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition Hash.h:26
PoolDefines.h
PoolMember.h
bool
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::IdString
constexpr IdString(IdType id_r)
Ctor from id.
Definition IdString.h:64
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *.
Definition IdString.cc:51
zypp::IdString::compare
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition IdString.cc:54
zypp::IdString::_id
IdType _id
Definition IdString.h:148
zypp::IdString::compare
int compare(const std::string &rhs) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition IdString.h:139
zypp::IdString::IdType
sat::detail::IdType IdType
Definition IdString.h:57
zypp::IdString::empty
constexpr bool empty() const
Whether the string is empty.
Definition IdString.h:99
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:144
zypp::IdString::Null
static const IdString Null
No or Null string ( Id 0 ).
Definition IdString.h:86
zypp::IdString::Empty
static const IdString Empty
Empty string.
Definition IdString.h:89
zypp::IdString::asString
std::string asString() const
Conversion to std::string.
Definition IdString.h:110
zypp::IdString::compareEQ
bool compareEQ(const IdString &rhs) const
Fast compare equal.
Definition IdString.h:129
zypp::IdString::IdString
constexpr IdString()
Default ctor, empty string.
Definition IdString.h:61
str
String related utilities and Regular expression matching.
zypp::sat::detail::emptyId
static const IdType emptyId(1)
zypp::sat::detail::noId
static const IdType noId(0)
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition PoolDefines.h:42
zypp::sat
Libsolv interface
zypp::solver::detail
Definition PoolImpl.h:110
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::IdStringSet
std::unordered_set< IdString > IdStringSet
Definition IdString.h:37
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::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
Definition Capability.cc:589
zypp::asString
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition Patch.cc:122
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::sat::detail::PoolMember
Backlink to the associated PoolImpl.
Definition PoolMember.h:53