libzypp 17.31.23
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
22
24namespace zypp
25{
26
27 class IdString;
28 typedef std::unordered_set<IdString> IdStringSet;
29
31 //
32 // CLASS NAME : IdString
33 //
43 {
44 public:
46
47 public:
49 constexpr IdString() : _id( sat::detail::emptyId ) {}
50
52 constexpr explicit IdString( IdType id_r ) : _id( id_r ) {}
53
55 explicit IdString( const char * str_r );
56
58 IdString( const char * str_r, unsigned len_r );
59
61 explicit IdString( const std::string & str_r );
62
64 explicit IdString( boost::string_ref str_r );
65
66#ifdef __cpp_lib_string_view
67 explicit IdString( std::string_view str_r )
68 : IdString( str_r.data(), str_r.size() )
69 {}
70#endif
71
72 public:
74 static const IdString Null;
75
77 static const IdString Empty;
78
79 public:
81 constexpr explicit operator bool() const
82 { return _id; }
83
87 constexpr bool empty() const
88 { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
89
91 unsigned size() const;
92
93 public:
95 const char * c_str() const;
96
98 std::string asString() const
99 { return c_str(); }
100
102 explicit operator std::string() const
103 { return asString(); }
104
105 public:
107 bool compareEQ( const IdString & rhs ) const
108 { return( _id == rhs.id() ); }
109
111 int compare( const IdString & rhs ) const;
112
114 int compare( const char * rhs ) const;
115
117 int compare( const std::string & rhs ) const
118 { return compare( rhs.c_str() ); }
119
120 public:
122 IdType id() const
123 { return _id; }
124
125 private:
127 };
129
131 std::ostream & operator<<( std::ostream & str, const IdString & obj );
132
134 std::ostream & dumpOn( std::ostream & str, const IdString & obj );
135
137 inline bool operator==( const IdString & lhs, const IdString & rhs )
138 { return lhs.compareEQ( rhs ); }
140 inline bool operator==( const IdString & lhs, const char * rhs )
141 { return lhs.compare( rhs ) == 0; }
143 inline bool operator==( const IdString & lhs, const std::string & rhs )
144 { return lhs.compare( rhs ) == 0; }
146 inline bool operator==( const char * lhs, const IdString & rhs )
147 { return rhs.compare( lhs ) == 0; }
149 inline bool operator==( const std::string & lhs, const IdString & rhs )
150 { return rhs.compare( lhs ) == 0; }
151
153 inline bool operator!=( const IdString & lhs, const IdString & rhs )
154 { return ! lhs.compareEQ( rhs ); }
156 inline bool operator!=( const IdString & lhs, const char * rhs )
157 { return lhs.compare( rhs ) != 0; }
159 inline bool operator!=( const IdString & lhs, const std::string & rhs )
160 { return lhs.compare( rhs ) != 0; }
162 inline bool operator!=( const char * lhs, const IdString & rhs )
163 { return rhs.compare( lhs ) != 0; }
165 inline bool operator!=( const std::string & lhs, const IdString & rhs )
166 { return rhs.compare( lhs ) != 0; }
167
169 inline bool operator<( const IdString & lhs, const IdString & rhs )
170 { return lhs.compare( rhs ) < 0; }
172 inline bool operator<( const IdString & lhs, const char * rhs )
173 { return lhs.compare( rhs ) < 0; }
175 inline bool operator<( const IdString & lhs, const std::string & rhs )
176 { return lhs.compare( rhs ) < 0; }
178 inline bool operator<( const char * lhs, const IdString & rhs )
179 { return rhs.compare( lhs ) >= 0; }
181 inline bool operator<( const std::string & lhs, const IdString & rhs )
182 { return rhs.compare( lhs ) >= 0; }
183
185 inline bool operator<=( const IdString & lhs, const IdString & rhs )
186 { return lhs.compare( rhs ) <= 0; }
188 inline bool operator<=( const IdString & lhs, const char * rhs )
189 { return lhs.compare( rhs ) <= 0; }
191 inline bool operator<=( const IdString & lhs, const std::string & rhs )
192 { return lhs.compare( rhs ) <= 0; }
194 inline bool operator<=( const char * lhs, const IdString & rhs )
195 { return rhs.compare( lhs ) > 0; }
197 inline bool operator<=( const std::string & lhs, const IdString & rhs )
198 { return rhs.compare( lhs ) > 0; }
199
201 inline bool operator>( const IdString & lhs, const IdString & rhs )
202 { return lhs.compare( rhs ) > 0; }
204 inline bool operator>( const IdString & lhs, const char * rhs )
205 { return lhs.compare( rhs ) > 0; }
207 inline bool operator>( const IdString & lhs, const std::string & rhs )
208 { return lhs.compare( rhs ) > 0; }
210 inline bool operator>( const char * lhs, const IdString & rhs )
211 { return rhs.compare( lhs ) <= 0; }
213 inline bool operator>( const std::string & lhs, const IdString & rhs )
214 { return rhs.compare( lhs ) <= 0; }
215
217 inline bool operator>=( const IdString & lhs, const IdString & rhs )
218 { return lhs.compare( rhs ) >= 0; }
220 inline bool operator>=( const IdString & lhs, const char * rhs )
221 { return lhs.compare( rhs ) >= 0; }
223 inline bool operator>=( const IdString & lhs, const std::string & rhs )
224 { return lhs.compare( rhs ) >= 0; }
226 inline bool operator>=( const char * lhs, const IdString & rhs )
227 { return rhs.compare( lhs ) < 0; }
229 inline bool operator>=( const std::string & lhs, const IdString & rhs )
230 { return rhs.compare( lhs ) < 0; }
231
233} // namespace zypp
235
237
238#endif // ZYPP_SAT_IDSTR_H
Access to the sat-pools string space.
Definition: IdString.h:43
unsigned size() const
The strings size.
Definition: IdString.cc:47
constexpr IdString(IdType id_r)
Ctor from id.
Definition: IdString.h:52
bool operator>=(const IdString &lhs, const IdString &rhs)
GreaterEqual.
Definition: IdString.h:217
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition: IdString.cc:53
sat::detail::IdType IdType
Definition: IdString.h:45
bool operator!=(const IdString &lhs, const IdString &rhs)
NotEqual.
Definition: IdString.h:153
IdType _id
Definition: IdString.h:126
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:117
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:87
bool operator>(const IdString &lhs, const IdString &rhs)
Greater.
Definition: IdString.h:201
bool operator==(const IdString &lhs, const IdString &rhs)
Equal.
Definition: IdString.h:137
IdType id() const
Expert backdoor.
Definition: IdString.h:122
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:74
static const IdString Empty
Empty string.
Definition: IdString.h:77
std::string asString() const
Conversion to std::string
Definition: IdString.h:98
bool operator<=(const IdString &lhs, const IdString &rhs)
LessEqual.
Definition: IdString.h:185
bool compareEQ(const IdString &rhs) const
Fast compare equal.
Definition: IdString.h:107
bool operator<(const IdString &lhs, const IdString &rhs)
Less.
Definition: IdString.h:169
constexpr IdString()
Default ctor, empty string.
Definition: IdString.h:49
String related utilities and Regular expression matching.
static const IdType emptyId(1)
static const IdType noId(0)
int IdType
Generic Id type.
Definition: PoolMember.h:104
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:335
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...
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:204
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:580
std::unordered_set< IdString > IdStringSet
Definition: IdString.h:28
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
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:220
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...
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:188
Backlink to the associated PoolImpl.
Definition: PoolMember.h:89
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition: Hash.h:26