libzypp  13.10.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 
19 
21 namespace zypp
22 {
23 
24  class IdString;
25  typedef std::tr1::unordered_set<IdString> IdStringSet;
26 
28  //
29  // CLASS NAME : IdString
30  //
40  {
41  public:
43 
44  public:
46  IdString() : _id( sat::detail::emptyId ) {}
47 
49  explicit IdString( IdType id_r ) : _id( id_r ) {}
50 
52  explicit IdString( const char * str_r );
53 
55  explicit IdString( const std::string & str_r );
56 
57  public:
59  static const IdString Null;
60 
62  static const IdString Empty;
63 
64  public:
66  explicit operator bool() const
67  { return _id; }
68 
72  bool empty() const
73  { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
74 
76  unsigned size() const;
77 
78  public:
80  const char * c_str() const;
81 
83  std::string asString() const
84  { return c_str(); }
85 
86  public:
88  bool compareEQ( const IdString & rhs ) const
89  { return( _id == rhs.id() ); }
90 
92  int compare( const IdString & rhs ) const;
93 
95  int compare( const char * rhs ) const;
96 
98  int compare( const std::string & rhs ) const
99  { return compare( rhs.c_str() ); }
100 
101  public:
103  IdType id() const
104  { return _id; }
105 
106  private:
108  };
110 
112  std::ostream & operator<<( std::ostream & str, const IdString & obj );
113 
115  std::ostream & dumpOn( std::ostream & str, const IdString & obj );
116 
118  inline bool operator==( const IdString & lhs, const IdString & rhs )
119  { return lhs.compareEQ( rhs ); }
121  inline bool operator==( const IdString & lhs, const char * rhs )
122  { return lhs.compare( rhs ) == 0; }
124  inline bool operator==( const IdString & lhs, const std::string & rhs )
125  { return lhs.compare( rhs ) == 0; }
127  inline bool operator==( const char * lhs, const IdString & rhs )
128  { return rhs.compare( lhs ) == 0; }
130  inline bool operator==( const std::string & lhs, const IdString & rhs )
131  { return rhs.compare( lhs ) == 0; }
132 
134  inline bool operator!=( const IdString & lhs, const IdString & rhs )
135  { return ! lhs.compareEQ( rhs ); }
137  inline bool operator!=( const IdString & lhs, const char * rhs )
138  { return lhs.compare( rhs ) != 0; }
140  inline bool operator!=( const IdString & lhs, const std::string & rhs )
141  { return lhs.compare( rhs ) != 0; }
143  inline bool operator!=( const char * lhs, const IdString & rhs )
144  { return rhs.compare( lhs ) != 0; }
146  inline bool operator!=( const std::string & lhs, const IdString & rhs )
147  { return rhs.compare( lhs ) != 0; }
148 
150  inline bool operator<( const IdString & lhs, const IdString & rhs )
151  { return lhs.compare( rhs ) < 0; }
153  inline bool operator<( const IdString & lhs, const char * rhs )
154  { return lhs.compare( rhs ) < 0; }
156  inline bool operator<( const IdString & lhs, const std::string & rhs )
157  { return lhs.compare( rhs ) < 0; }
159  inline bool operator<( const char * lhs, const IdString & rhs )
160  { return rhs.compare( lhs ) >= 0; }
162  inline bool operator<( const std::string & lhs, const IdString & rhs )
163  { return rhs.compare( lhs ) >= 0; }
164 
166  inline bool operator<=( const IdString & lhs, const IdString & rhs )
167  { return lhs.compare( rhs ) <= 0; }
169  inline bool operator<=( const IdString & lhs, const char * rhs )
170  { return lhs.compare( rhs ) <= 0; }
172  inline bool operator<=( const IdString & lhs, const std::string & rhs )
173  { return lhs.compare( rhs ) <= 0; }
175  inline bool operator<=( const char * lhs, const IdString & rhs )
176  { return rhs.compare( lhs ) > 0; }
178  inline bool operator<=( const std::string & lhs, const IdString & rhs )
179  { return rhs.compare( lhs ) > 0; }
180 
182  inline bool operator>( const IdString & lhs, const IdString & rhs )
183  { return lhs.compare( rhs ) > 0; }
185  inline bool operator>( const IdString & lhs, const char * rhs )
186  { return lhs.compare( rhs ) > 0; }
188  inline bool operator>( const IdString & lhs, const std::string & rhs )
189  { return lhs.compare( rhs ) > 0; }
191  inline bool operator>( const char * lhs, const IdString & rhs )
192  { return rhs.compare( lhs ) <= 0; }
194  inline bool operator>( const std::string & lhs, const IdString & rhs )
195  { return rhs.compare( lhs ) <= 0; }
196 
198  inline bool operator>=( const IdString & lhs, const IdString & rhs )
199  { return lhs.compare( rhs ) >= 0; }
201  inline bool operator>=( const IdString & lhs, const char * rhs )
202  { return lhs.compare( rhs ) >= 0; }
204  inline bool operator>=( const IdString & lhs, const std::string & rhs )
205  { return lhs.compare( rhs ) >= 0; }
207  inline bool operator>=( const char * lhs, const IdString & rhs )
208  { return rhs.compare( lhs ) < 0; }
210  inline bool operator>=( const std::string & lhs, const IdString & rhs )
211  { return rhs.compare( lhs ) < 0; }
212 
214 } // namespace zypp
216 
218 
219 #endif // ZYPP_SAT_IDSTR_H
int IdType
Generic Id type.
Definition: PoolMember.h:82
bool operator!=(const CountryCode &lhs, const CountryCode &rhs)
IdType id() const
Expert backdoor.
Definition: IdString.h:103
IdType _id
Definition: IdString.h:107
Access to the sat-pools string space.
Definition: IdString.h:39
std::string asString() const
Conversion to std::string
Definition: IdString.h:83
static const IdString Empty
Empty string.
Definition: IdString.h:62
Backlink to the associated PoolImpl.
Definition: PoolMember.h:66
static const IdType emptyId(1)
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
sat::detail::IdType IdType
Definition: IdString.h:42
bool operator==(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:118
int compare(const std::string &rhs) const
Definition: IdString.h:98
bool operator>=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:198
#define ZYPP_DEFINE_ID_HASHABLE(C)
Define hash function for id based classes.
Definition: Tr1hash.h:26
bool compareEQ(const IdString &rhs) const
Fast compare equal.
Definition: IdString.h:88
bool operator>(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:182
bool operator<(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:150
bool operator>=(const IdString &lhs, const char *rhs)
Definition: IdString.h:201
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:435
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:42
bool operator>(const IdString &lhs, const char *rhs)
Definition: IdString.h:185
bool operator!=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:134
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:309
IdString(IdType id_r)
Ctor from id.
Definition: IdString.h:49
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition: IdString.cc:45
IdString()
Default ctor, empty string.
Definition: IdString.h:46
static const IdString Null
No or Null string ( Id 0 ).
Definition: IdString.h:59
static const IdType noId(0)
bool empty() const
Whether the string is empty.
Definition: IdString.h:72
unsigned size() const
The strings size.
Definition: IdString.cc:39
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:315
bool operator<=(const IdString &lhs, const IdString &rhs)
Definition: IdString.h:166
std::tr1::unordered_set< IdString > IdStringSet
Definition: IdString.h:24
bool operator<=(const IdString &lhs, const char *rhs)
Definition: IdString.h:169