libzypp  11.13.5
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 "zypp/base/SafeBool.h"
19 
21 
23 namespace zypp
24 {
25 
26  class IdString;
27  typedef std::tr1::unordered_set<IdString> IdStringSet;
28 
30  //
31  // CLASS NAME : IdString
32  //
41  class IdString : protected sat::detail::PoolMember,
42  private base::SafeBool<IdString>
43  {
44  public:
46 
47  public:
49  IdString() : _id( sat::detail::emptyId ) {}
50 
52  explicit IdString( IdType id_r ) : _id( id_r ) {}
53 
55  explicit IdString( const char * str_r );
56 
58  explicit IdString( const std::string & str_r );
59 
60  public:
62  static const IdString Null;
63 
65  static const IdString Empty;
66 
67  public:
68 #ifndef SWIG // Swig treats it as syntax error
69 
71 #endif
72 
75  bool empty() const
76  { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
77 
79  unsigned size() const;
80 
81  public:
83  const char * c_str() const;
84 
86  std::string asString() const
87  { return c_str(); }
88 
89  public:
91  bool compareEQ( const IdString & rhs ) const
92  { return( _id == rhs.id() ); }
93 
95  int compare( const IdString & rhs ) const;
96 
98  int compare( const char * rhs ) const;
99 
101  int compare( const std::string & rhs ) const
102  { return compare( rhs.c_str() ); }
103 
104  public:
106  IdType id() const
107  { return _id; }
108  private:
109 #ifndef SWIG // Swig treats it as syntax error
111 #endif
112  bool boolTest() const { return _id; }
113  private:
115  };
117 
119  std::ostream & operator<<( std::ostream & str, const IdString & obj );
120 
122  std::ostream & dumpOn( std::ostream & str, const IdString & obj );
123 
125  inline bool operator==( const IdString & lhs, const IdString & rhs )
126  { return lhs.compareEQ( rhs ); }
128  inline bool operator==( const IdString & lhs, const char * rhs )
129  { return lhs.compare( rhs ) == 0; }
131  inline bool operator==( const IdString & lhs, const std::string & rhs )
132  { return lhs.compare( rhs ) == 0; }
134  inline bool operator==( const char * lhs, const IdString & rhs )
135  { return rhs.compare( lhs ) == 0; }
137  inline bool operator==( const std::string & lhs, const IdString & rhs )
138  { return rhs.compare( lhs ) == 0; }
139 
141  inline bool operator!=( const IdString & lhs, const IdString & rhs )
142  { return ! lhs.compareEQ( rhs ); }
144  inline bool operator!=( const IdString & lhs, const char * rhs )
145  { return lhs.compare( rhs ) != 0; }
147  inline bool operator!=( const IdString & lhs, const std::string & rhs )
148  { return lhs.compare( rhs ) != 0; }
150  inline bool operator!=( const char * lhs, const IdString & rhs )
151  { return rhs.compare( lhs ) != 0; }
153  inline bool operator!=( const std::string & lhs, const IdString & rhs )
154  { return rhs.compare( lhs ) != 0; }
155 
157  inline bool operator<( const IdString & lhs, const IdString & rhs )
158  { return lhs.compare( rhs ) < 0; }
160  inline bool operator<( const IdString & lhs, const char * rhs )
161  { return lhs.compare( rhs ) < 0; }
163  inline bool operator<( const IdString & lhs, const std::string & rhs )
164  { return lhs.compare( rhs ) < 0; }
166  inline bool operator<( const char * lhs, const IdString & rhs )
167  { return rhs.compare( lhs ) >= 0; }
169  inline bool operator<( const std::string & lhs, const IdString & rhs )
170  { return rhs.compare( lhs ) >= 0; }
171 
173  inline bool operator<=( const IdString & lhs, const IdString & rhs )
174  { return lhs.compare( rhs ) <= 0; }
176  inline bool operator<=( const IdString & lhs, const char * rhs )
177  { return lhs.compare( rhs ) <= 0; }
179  inline bool operator<=( const IdString & lhs, const std::string & rhs )
180  { return lhs.compare( rhs ) <= 0; }
182  inline bool operator<=( const char * lhs, const IdString & rhs )
183  { return rhs.compare( lhs ) > 0; }
185  inline bool operator<=( const std::string & lhs, const IdString & rhs )
186  { return rhs.compare( lhs ) > 0; }
187 
189  inline bool operator>( const IdString & lhs, const IdString & rhs )
190  { return lhs.compare( rhs ) > 0; }
192  inline bool operator>( const IdString & lhs, const char * rhs )
193  { return lhs.compare( rhs ) > 0; }
195  inline bool operator>( const IdString & lhs, const std::string & rhs )
196  { return lhs.compare( rhs ) > 0; }
198  inline bool operator>( const char * lhs, const IdString & rhs )
199  { return rhs.compare( lhs ) <= 0; }
201  inline bool operator>( const std::string & lhs, const IdString & rhs )
202  { return rhs.compare( lhs ) <= 0; }
203 
205  inline bool operator>=( const IdString & lhs, const IdString & rhs )
206  { return lhs.compare( rhs ) >= 0; }
208  inline bool operator>=( const IdString & lhs, const char * rhs )
209  { return lhs.compare( rhs ) >= 0; }
211  inline bool operator>=( const IdString & lhs, const std::string & rhs )
212  { return lhs.compare( rhs ) >= 0; }
214  inline bool operator>=( const char * lhs, const IdString & rhs )
215  { return rhs.compare( lhs ) < 0; }
217  inline bool operator>=( const std::string & lhs, const IdString & rhs )
218  { return rhs.compare( lhs ) < 0; }
219 
221 } // namespace zypp
223 
225 
226 #endif // ZYPP_SAT_IDSTR_H