libzypp 17.37.10

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
19#include <boost/utility/string_ref_fwd.hpp>
20
21#include <zypp-core/Globals.h>
22#include <zypp/sat/detail/PoolMember.h>
23
25 namespace zypp
26{
27
28 class IdString;
29 using IdStringSet = std::unordered_set<IdString>;
30
32 //
33 // CLASS NAME : IdString
34 //
43 class ZYPP_API IdString : protected sat::detail::PoolMember
44 {
45 public:
46 using IdType = sat::detail::IdType;
47
48 public:
50 constexpr IdString() : _id( sat::detail::emptyId ) {}
51
53 constexpr explicit IdString( IdType id_r ) : _id( id_r ) {}
54
56 explicit IdString( const char * str_r );
57
59 IdString( const char * str_r, unsigned len_r );
60
62 explicit IdString( const std::string & str_r );
63
65 explicit IdString( boost::string_ref str_r );
66
67#ifdef __cpp_lib_string_view
68 explicit IdString( std::string_view str_r )
69 : IdString( str_r.data(), str_r.size() )
70 {}
71#endif
72
73 public:
75 static const IdString Null;
76
78 static const IdString Empty;
79
80 public:
82 constexpr explicit operator bool() const
83 { return _id; }
84
88 constexpr bool empty() const
89 { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
90
92 unsigned size() const;
93
94 public:
96 const char * c_str() const;
97
99 std::string asString() const
100 { return c_str(); }
101
103 explicit operator std::string() const
104 { return asString(); }
105
106#ifdef __cpp_lib_string_view
108 std::string_view asStringView() const
109 { return { c_str(), size() }; }
110
112 explicit operator std::string_view() const
113 { return asStringView(); }
114#endif
115
116 public:
118 bool compareEQ( const IdString & rhs ) const
119 { return( _id == rhs.id() ); }
120
122 int compare( const IdString & rhs ) const;
123
125 int compare( const char * rhs ) const;
126
128 int compare( const std::string & rhs ) const
129 { return compare( rhs.c_str() ); }
130
131 public:
133 IdType id() const
134 { return _id; }
135
136 private:
137 IdType _id;
138 };
139
140
142 std::ostream & operator<<( std::ostream & str, const IdString & obj ) ZYPP_API;
143
145 std::ostream & dumpOn( std::ostream & str, const IdString & obj ) ZYPP_API;
146
148 inline bool operator==( const IdString & lhs, const IdString & rhs )
149 { return lhs.compareEQ( rhs ); }
150
151 inline bool operator==( const IdString & lhs, const char * rhs )
152 { return lhs.compare( rhs ) == 0; }
153
154 inline bool operator==( const IdString & lhs, const std::string & rhs )
155 { return lhs.compare( rhs ) == 0; }
156
157 inline bool operator==( const char * lhs, const IdString & rhs )
158 { return rhs.compare( lhs ) == 0; }
159
160 inline bool operator==( const std::string & lhs, const IdString & rhs )
161 { return rhs.compare( lhs ) == 0; }
162
164 inline bool operator!=( const IdString & lhs, const IdString & rhs )
165 { return ! lhs.compareEQ( rhs ); }
166
167 inline bool operator!=( const IdString & lhs, const char * rhs )
168 { return lhs.compare( rhs ) != 0; }
169
170 inline bool operator!=( const IdString & lhs, const std::string & rhs )
171 { return lhs.compare( rhs ) != 0; }
172
173 inline bool operator!=( const char * lhs, const IdString & rhs )
174 { return rhs.compare( lhs ) != 0; }
175
176 inline bool operator!=( const std::string & lhs, const IdString & rhs )
177 { return rhs.compare( lhs ) != 0; }
178
180 inline bool operator<( const IdString & lhs, const IdString & rhs )
181 { return lhs.compare( rhs ) < 0; }
182
183 inline bool operator<( const IdString & lhs, const char * rhs )
184 { return lhs.compare( rhs ) < 0; }
185
186 inline bool operator<( const IdString & lhs, const std::string & rhs )
187 { return lhs.compare( rhs ) < 0; }
188
189 inline bool operator<( const char * lhs, const IdString & rhs )
190 { return rhs.compare( lhs ) >= 0; }
191
192 inline bool operator<( const std::string & lhs, const IdString & rhs )
193 { return rhs.compare( lhs ) >= 0; }
194
196 inline bool operator<=( const IdString & lhs, const IdString & rhs )
197 { return lhs.compare( rhs ) <= 0; }
198
199 inline bool operator<=( const IdString & lhs, const char * rhs )
200 { return lhs.compare( rhs ) <= 0; }
201
202 inline bool operator<=( const IdString & lhs, const std::string & rhs )
203 { return lhs.compare( rhs ) <= 0; }
204
205 inline bool operator<=( const char * lhs, const IdString & rhs )
206 { return rhs.compare( lhs ) > 0; }
207
208 inline bool operator<=( const std::string & lhs, const IdString & rhs )
209 { return rhs.compare( lhs ) > 0; }
210
212 inline bool operator>( const IdString & lhs, const IdString & rhs )
213 { return lhs.compare( rhs ) > 0; }
214
215 inline bool operator>( const IdString & lhs, const char * rhs )
216 { return lhs.compare( rhs ) > 0; }
217
218 inline bool operator>( const IdString & lhs, const std::string & rhs )
219 { return lhs.compare( rhs ) > 0; }
220
221 inline bool operator>( const char * lhs, const IdString & rhs )
222 { return rhs.compare( lhs ) <= 0; }
223
224 inline bool operator>( const std::string & lhs, const IdString & rhs )
225 { return rhs.compare( lhs ) <= 0; }
226
228 inline bool operator>=( const IdString & lhs, const IdString & rhs )
229 { return lhs.compare( rhs ) >= 0; }
230
231 inline bool operator>=( const IdString & lhs, const char * rhs )
232 { return lhs.compare( rhs ) >= 0; }
233
234 inline bool operator>=( const IdString & lhs, const std::string & rhs )
235 { return lhs.compare( rhs ) >= 0; }
236
237 inline bool operator>=( const char * lhs, const IdString & rhs )
238 { return rhs.compare( lhs ) < 0; }
239
240 inline bool operator>=( const std::string & lhs, const IdString & rhs )
241 { return rhs.compare( lhs ) < 0; }
242
244} // namespace zypp
246
247 ZYPP_DEFINE_ID_HASHABLE( ::zypp::IdString );
248
249#endif // ZYPP_SAT_IDSTR_H
PoolMember.h
bool
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:44
zypp::IdString::IdString
constexpr IdString(IdType id_r)
Ctor from id.
Definition IdString.h:53
zypp::IdString::operator>=
bool operator>=(const IdString &lhs, const IdString &rhs)
GreaterEqual.
Definition IdString.h:228
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *
Definition IdString.cc:50
zypp::IdString::compare
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition IdString.cc:53
zypp::IdString::operator!=
bool operator!=(const IdString &lhs, const IdString &rhs)
NotEqual.
Definition IdString.h:164
zypp::IdString::_id
IdType _id
Definition IdString.h:137
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:128
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::operator>
bool operator>(const IdString &lhs, const IdString &rhs)
Greater.
Definition IdString.h:212
zypp::IdString::operator==
bool operator==(const IdString &lhs, const IdString &rhs)
Equal.
Definition IdString.h:148
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:133
zypp::IdString::Null
static const IdString Null
No or Null string ( Id 0 ).
Definition IdString.h:75
zypp::IdString::Empty
static const IdString Empty
Empty string.
Definition IdString.h:78
zypp::IdString::asString
std::string asString() const
Conversion to std::string
Definition IdString.h:99
zypp::IdString::operator<=
bool operator<=(const IdString &lhs, const IdString &rhs)
LessEqual.
Definition IdString.h:196
zypp::IdString::compareEQ
bool compareEQ(const IdString &rhs) const
Fast compare equal.
Definition IdString.h:118
zypp::IdString::operator<
bool operator<(const IdString &lhs, const IdString &rhs)
Less.
Definition IdString.h:180
zypp::IdString::IdString
constexpr IdString()
Default ctor, empty string.
Definition IdString.h:50
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 PoolMember.h:104
zypp::sat
Definition Resolver.h:28
zypp::solver::detail
Definition PoolImpl.h:110
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::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition Capability.cc:580
zypp::IdStringSet
std::unordered_set< IdString > IdStringSet
Definition IdString.h:29
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
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::asString
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
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
Globals.h
Provides API related macros.
ZYPP_DEFINE_ID_HASHABLE
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition Hash.h:26