libzypp  17.35.15
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>
23 
25 namespace zypp
26 {
27 
28  class IdString;
29  using IdStringSet = std::unordered_set<IdString>;
30 
32  //
33  // CLASS NAME : IdString
34  //
44  {
45  public:
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
107 
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:
138  };
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 ); }
151  inline bool operator==( const IdString & lhs, const char * rhs )
152  { return lhs.compare( rhs ) == 0; }
154  inline bool operator==( const IdString & lhs, const std::string & rhs )
155  { return lhs.compare( rhs ) == 0; }
157  inline bool operator==( const char * lhs, const IdString & rhs )
158  { return rhs.compare( lhs ) == 0; }
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 ); }
167  inline bool operator!=( const IdString & lhs, const char * rhs )
168  { return lhs.compare( rhs ) != 0; }
170  inline bool operator!=( const IdString & lhs, const std::string & rhs )
171  { return lhs.compare( rhs ) != 0; }
173  inline bool operator!=( const char * lhs, const IdString & rhs )
174  { return rhs.compare( lhs ) != 0; }
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; }
183  inline bool operator<( const IdString & lhs, const char * rhs )
184  { return lhs.compare( rhs ) < 0; }
186  inline bool operator<( const IdString & lhs, const std::string & rhs )
187  { return lhs.compare( rhs ) < 0; }
189  inline bool operator<( const char * lhs, const IdString & rhs )
190  { return rhs.compare( lhs ) >= 0; }
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; }
199  inline bool operator<=( const IdString & lhs, const char * rhs )
200  { return lhs.compare( rhs ) <= 0; }
202  inline bool operator<=( const IdString & lhs, const std::string & rhs )
203  { return lhs.compare( rhs ) <= 0; }
205  inline bool operator<=( const char * lhs, const IdString & rhs )
206  { return rhs.compare( lhs ) > 0; }
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; }
215  inline bool operator>( const IdString & lhs, const char * rhs )
216  { return lhs.compare( rhs ) > 0; }
218  inline bool operator>( const IdString & lhs, const std::string & rhs )
219  { return lhs.compare( rhs ) > 0; }
221  inline bool operator>( const char * lhs, const IdString & rhs )
222  { return rhs.compare( lhs ) <= 0; }
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; }
231  inline bool operator>=( const IdString & lhs, const char * rhs )
232  { return lhs.compare( rhs ) >= 0; }
234  inline bool operator>=( const IdString & lhs, const std::string & rhs )
235  { return lhs.compare( rhs ) >= 0; }
237  inline bool operator>=( const char * lhs, const IdString & rhs )
238  { return rhs.compare( lhs ) < 0; }
240  inline bool operator>=( const std::string & lhs, const IdString & rhs )
241  { return rhs.compare( lhs ) < 0; }
242 
244 } // namespace zypp
246 
248 
249 #endif // ZYPP_SAT_IDSTR_H
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition: IdString.cc:53
int compare(const std::string &rhs) const
Definition: IdString.h:128
bool compareEQ(const IdString &rhs) const
Fast compare equal.
Definition: IdString.h:118
IdType id() const
Expert backdoor.
Definition: IdString.h:133
IdType _id
Definition: IdString.h:137
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
int IdType
Generic Id type.
Definition: PoolMember.h:104
Access to the sat-pools string space.
Definition: IdString.h:43
Provides API related macros.
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
sat::detail::IdType IdType
Definition: IdString.h:46
constexpr IdString()
Default ctor, empty string.
Definition: IdString.h:50
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:88
std::unordered_set< IdString > IdStringSet
Definition: IdString.h:29
static const IdString Empty
Empty string.
Definition: IdString.h:78
Backlink to the associated PoolImpl.
Definition: PoolMember.h:88
static const IdType emptyId(1)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
bool operator==(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:148
bool operator>=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:228
ZYPP_DEFINE_ID_HASHABLE(::zypp::IdString)
bool operator>(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:212
bool operator<(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:180
bool operator>=(const IdString &lhs, const char *rhs)
Definition: IdString.h:231
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:580
bool operator>(const IdString &lhs, const char *rhs)
Definition: IdString.h:215
bool operator!=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:164
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:75
static const IdType noId(0)
std::string asString() const
Conversion to std::string
Definition: IdString.h:99
constexpr IdString(IdType id_r)
Ctor from id.
Definition: IdString.h:53
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:340
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
bool operator<=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:196
zypp::IdString IdString
Definition: idstring.h:16
bool operator<=(const IdString &lhs, const char *rhs)
Definition: IdString.h:199