libzypp  17.8.1
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 
18 #include <boost/utility/string_ref_fwd.hpp>
19 
21 
23 namespace zypp
24 {
25 
26  class IdString;
27  typedef std::unordered_set<IdString> IdStringSet;
28 
30  //
31  // CLASS NAME : IdString
32  //
42  {
43  public:
45 
46  public:
48  constexpr IdString() : _id( sat::detail::emptyId ) {}
49 
51  constexpr explicit IdString( IdType id_r ) : _id( id_r ) {}
52 
54  explicit IdString( const char * str_r );
55 
57  IdString( const char * str_r, unsigned len_r );
58 
60  explicit IdString( const std::string & str_r );
61 
63  explicit IdString( boost::string_ref str_r );
64 
65  public:
67  static const IdString Null;
68 
70  static const IdString Empty;
71 
72  public:
74  constexpr explicit operator bool() const
75  { return _id; }
76 
80  constexpr bool empty() const
81  { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
82 
84  unsigned size() const;
85 
86  public:
88  const char * c_str() const;
89 
91  std::string asString() const
92  { return c_str(); }
93 
95  explicit operator std::string() const
96  { return asString(); }
97 
98  public:
100  bool compareEQ( const IdString & rhs ) const
101  { return( _id == rhs.id() ); }
102 
104  int compare( const IdString & rhs ) const;
105 
107  int compare( const char * rhs ) const;
108 
110  int compare( const std::string & rhs ) const
111  { return compare( rhs.c_str() ); }
112 
113  public:
115  IdType id() const
116  { return _id; }
117 
118  private:
120  };
122 
124  std::ostream & operator<<( std::ostream & str, const IdString & obj );
125 
127  std::ostream & dumpOn( std::ostream & str, const IdString & obj );
128 
130  inline bool operator==( const IdString & lhs, const IdString & rhs )
131  { return lhs.compareEQ( rhs ); }
133  inline bool operator==( const IdString & lhs, const char * rhs )
134  { return lhs.compare( rhs ) == 0; }
136  inline bool operator==( const IdString & lhs, const std::string & rhs )
137  { return lhs.compare( rhs ) == 0; }
139  inline bool operator==( const char * lhs, const IdString & rhs )
140  { return rhs.compare( lhs ) == 0; }
142  inline bool operator==( const std::string & lhs, const IdString & rhs )
143  { return rhs.compare( lhs ) == 0; }
144 
146  inline bool operator!=( const IdString & lhs, const IdString & rhs )
147  { return ! lhs.compareEQ( rhs ); }
149  inline bool operator!=( const IdString & lhs, const char * rhs )
150  { return lhs.compare( rhs ) != 0; }
152  inline bool operator!=( const IdString & lhs, const std::string & rhs )
153  { return lhs.compare( rhs ) != 0; }
155  inline bool operator!=( const char * lhs, const IdString & rhs )
156  { return rhs.compare( lhs ) != 0; }
158  inline bool operator!=( const std::string & lhs, const IdString & rhs )
159  { return rhs.compare( lhs ) != 0; }
160 
162  inline bool operator<( const IdString & lhs, const IdString & rhs )
163  { return lhs.compare( rhs ) < 0; }
165  inline bool operator<( const IdString & lhs, const char * rhs )
166  { return lhs.compare( rhs ) < 0; }
168  inline bool operator<( const IdString & lhs, const std::string & rhs )
169  { return lhs.compare( rhs ) < 0; }
171  inline bool operator<( const char * lhs, const IdString & rhs )
172  { return rhs.compare( lhs ) >= 0; }
174  inline bool operator<( const std::string & lhs, const IdString & rhs )
175  { return rhs.compare( lhs ) >= 0; }
176 
178  inline bool operator<=( const IdString & lhs, const IdString & rhs )
179  { return lhs.compare( rhs ) <= 0; }
181  inline bool operator<=( const IdString & lhs, const char * rhs )
182  { return lhs.compare( rhs ) <= 0; }
184  inline bool operator<=( const IdString & lhs, const std::string & rhs )
185  { return lhs.compare( rhs ) <= 0; }
187  inline bool operator<=( const char * lhs, const IdString & rhs )
188  { return rhs.compare( lhs ) > 0; }
190  inline bool operator<=( const std::string & lhs, const IdString & rhs )
191  { return rhs.compare( lhs ) > 0; }
192 
194  inline bool operator>( const IdString & lhs, const IdString & rhs )
195  { return lhs.compare( rhs ) > 0; }
197  inline bool operator>( const IdString & lhs, const char * rhs )
198  { return lhs.compare( rhs ) > 0; }
200  inline bool operator>( const IdString & lhs, const std::string & rhs )
201  { return lhs.compare( rhs ) > 0; }
203  inline bool operator>( const char * lhs, const IdString & rhs )
204  { return rhs.compare( lhs ) <= 0; }
206  inline bool operator>( const std::string & lhs, const IdString & rhs )
207  { return rhs.compare( lhs ) <= 0; }
208 
210  inline bool operator>=( const IdString & lhs, const IdString & rhs )
211  { return lhs.compare( rhs ) >= 0; }
213  inline bool operator>=( const IdString & lhs, const char * rhs )
214  { return lhs.compare( rhs ) >= 0; }
216  inline bool operator>=( const IdString & lhs, const std::string & rhs )
217  { return lhs.compare( rhs ) >= 0; }
219  inline bool operator>=( const char * lhs, const IdString & rhs )
220  { return rhs.compare( lhs ) < 0; }
222  inline bool operator>=( const std::string & lhs, const IdString & rhs )
223  { return rhs.compare( lhs ) < 0; }
224 
226 } // namespace zypp
228 
230 
231 #endif // ZYPP_SAT_IDSTR_H
int IdType
Generic Id type.
Definition: PoolMember.h:130
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:110
bool compareEQ(const IdString &rhs) const
Fast compare equal.
Definition: IdString.h:100
IdType id() const
Expert backdoor.
Definition: IdString.h:115
IdType _id
Definition: IdString.h:119
String related utilities and Regular expression matching.
Access to the sat-pools string space.
Definition: IdString.h:41
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
constexpr IdString()
Default ctor, empty string.
Definition: IdString.h:48
constexpr bool empty() const
Whether the string is empty.
Definition: IdString.h:80
static const IdString Empty
Empty string.
Definition: IdString.h:70
Backlink to the associated PoolImpl.
Definition: PoolMember.h:114
static const IdType emptyId(1)
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
std::unordered_set< IdString > IdStringSet
Definition: IdString.h:26
sat::detail::IdType IdType
Definition: IdString.h:44
bool operator==(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:130
bool operator>=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:210
ZYPP_DEFINE_ID_HASHABLE(::zypp::IdString)
bool operator>(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:194
bool operator<(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:162
bool operator>=(const IdString &lhs, const char *rhs)
Definition: IdString.h:213
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:444
unsigned size() const
The strings size.
Definition: IdString.cc:47
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
bool operator>(const IdString &lhs, const char *rhs)
Definition: IdString.h:197
bool operator!=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:146
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:67
static const IdType noId(0)
std::string asString() const
Conversion to std::string
Definition: IdString.h:91
constexpr IdString(IdType id_r)
Ctor from id.
Definition: IdString.h:51
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:335
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool operator<=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:178
bool operator<=(const IdString &lhs, const char *rhs)
Definition: IdString.h:181