Deprecate MediaAccess::downloads (accidentally deleted)
[platform/upstream/libzypp.git] / zypp / IdString.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/IdString.h
10  *
11 */
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
20 #include "zypp/sat/detail/PoolMember.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   ///////////////////////////////////////////////////////////////////
27   //
28   //    CLASS NAME : IdString
29   //
30   /** Access to the sat-pools string space.
31    *
32    * Construction from string will place a copy of the string in the
33    * string space, if it is not already present.
34    *
35    * While comparison differs between \ref IdString::Null and \ref IdString::Empty
36    * ( \c NULL and \c "" ), both are represented by an empty string \c "".
37    */
38   class IdString : protected sat::detail::PoolMember,
39                    private base::SafeBool<IdString>
40   {
41     public:
42       typedef sat::detail::IdType IdType;
43
44     public:
45       /** Default ctor, empty string. */
46       IdString() : _id( sat::detail::emptyId ) {}
47
48       /** Ctor from id. */
49       explicit IdString( IdType id_r ) : _id( id_r ) {}
50
51       /** Ctor from string. */
52       explicit IdString( const char * str_r );
53
54       /** Ctor from string. */
55       explicit IdString( const std::string & str_r );
56
57     public:
58       /** No or Null string ( Id \c 0 ). */
59       static const IdString Null;
60
61       /** Empty string. */
62       static const IdString Empty;
63
64     public:
65 #ifndef SWIG // Swig treats it as syntax error
66       /** Evaluate in a boolean context <tt>( != \c Null )</tt>. */
67       using base::SafeBool<IdString>::operator bool_type;
68 #endif
69       /** Whether the string is empty.
70        * This is true for \ref Null and \ref Empty.
71        */
72       bool empty() const
73       { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
74
75       /** The strings size. */
76       unsigned size() const;
77
78     public:
79       /** Conversion to <tt>const char *</tt> */
80       const char * c_str() const;
81
82       /** Conversion to <tt>std::string</tt> */
83       std::string asString() const
84       { return c_str(); }
85
86     public:
87       /** Fast compare equal. */
88       bool compareEQ( const IdString & rhs ) const
89       { return( _id == rhs.id() ); }
90
91       /** Compare IdString returning <tt>-1,0,1</tt>. */
92       int compare( const IdString & rhs ) const;
93
94       /** \overload */
95       int compare( const char * rhs ) const;
96
97       /** \overload */
98       int compare( const std::string & rhs ) const
99       { return compare( rhs.c_str() ); }
100
101     public:
102       /** Expert backdoor. */
103       IdType id() const
104       { return _id; }
105     private:
106 #ifndef SWIG // Swig treats it as syntax error
107       friend base::SafeBool<IdString>::operator bool_type() const;
108 #endif
109       bool boolTest() const { return _id; }
110     private:
111       IdType _id;
112   };
113   ///////////////////////////////////////////////////////////////////
114
115   /** \relates IdString Stream output */
116   std::ostream & operator<<( std::ostream & str, const IdString & obj );
117
118   /** \relates IdString Stream output */
119   std::ostream & dumpOn( std::ostream & str, const IdString & obj );
120
121   /** \relates IdString Equal */
122   inline bool operator==( const IdString & lhs, const IdString & rhs )
123   { return lhs.compareEQ( rhs ); }
124   /** \overload */
125   inline bool operator==( const IdString & lhs, const char * rhs )
126   { return lhs.compare( rhs ) == 0; }
127   /** \overload */
128   inline bool operator==( const IdString & lhs, const std::string & rhs )
129   { return lhs.compare( rhs ) == 0; }
130   /** \overload */
131   inline bool operator==( const char * lhs, const IdString & rhs )
132   { return rhs.compare( lhs ) == 0; }
133   /** \overload */
134   inline bool operator==( const std::string & lhs, const IdString & rhs )
135   { return rhs.compare( lhs ) == 0; }
136
137   /** \relates IdString NotEqual */
138   inline bool operator!=( const IdString & lhs, const IdString & rhs )
139   { return ! lhs.compareEQ( rhs ); }
140   /** \overload */
141   inline bool operator!=( const IdString & lhs, const char * rhs )
142   { return lhs.compare( rhs ) != 0; }
143   /** \overload */
144   inline bool operator!=( const IdString & lhs, const std::string & rhs )
145   { return lhs.compare( rhs ) != 0; }
146   /** \overload */
147   inline bool operator!=( const char * lhs, const IdString & rhs )
148   { return rhs.compare( lhs ) != 0; }
149   /** \overload */
150   inline bool operator!=( const std::string & lhs, const IdString & rhs )
151   { return rhs.compare( lhs ) != 0; }
152
153   /** \relates IdString Less */
154   inline bool operator<( const IdString & lhs, const IdString & rhs )
155   { return lhs.compare( rhs ) < 0; }
156   /** \overload */
157   inline bool operator<( const IdString & lhs, const char * rhs )
158   { return lhs.compare( rhs ) < 0; }
159   /** \overload */
160   inline bool operator<( const IdString & lhs, const std::string & rhs )
161   { return lhs.compare( rhs ) < 0; }
162   /** \overload */
163   inline bool operator<( const char * lhs, const IdString & rhs )
164   { return rhs.compare( lhs ) >= 0; }
165   /** \overload */
166   inline bool operator<( const std::string & lhs, const IdString & rhs )
167   { return rhs.compare( lhs ) >= 0; }
168
169   /** \relates IdString LessEqual*/
170   inline bool operator<=( const IdString & lhs, const IdString & rhs )
171   { return lhs.compare( rhs ) <= 0; }
172   /** \overload */
173   inline bool operator<=( const IdString & lhs, const char * rhs )
174   { return lhs.compare( rhs ) <= 0; }
175   /** \overload */
176   inline bool operator<=( const IdString & lhs, const std::string & rhs )
177   { return lhs.compare( rhs ) <= 0; }
178   /** \overload */
179   inline bool operator<=( const char * lhs, const IdString & rhs )
180   { return rhs.compare( lhs ) > 0; }
181   /** \overload */
182   inline bool operator<=( const std::string & lhs, const IdString & rhs )
183   { return rhs.compare( lhs ) > 0; }
184
185   /** \relates IdString Greater */
186   inline bool operator>( const IdString & lhs, const IdString & rhs )
187   { return lhs.compare( rhs ) > 0; }
188   /** \overload */
189   inline bool operator>( const IdString & lhs, const char * rhs )
190   { return lhs.compare( rhs ) > 0; }
191   /** \overload */
192   inline bool operator>( const IdString & lhs, const std::string & rhs )
193   { return lhs.compare( rhs ) > 0; }
194   /** \overload */
195   inline bool operator>( const char * lhs, const IdString & rhs )
196   { return rhs.compare( lhs ) <= 0; }
197   /** \overload */
198   inline bool operator>( const std::string & lhs, const IdString & rhs )
199   { return rhs.compare( lhs ) <= 0; }
200
201   /** \relates IdString GreaterEqual */
202   inline bool operator>=( const IdString & lhs, const IdString & rhs )
203   { return lhs.compare( rhs ) >= 0; }
204   /** \overload */
205   inline bool operator>=( const IdString & lhs, const char * rhs )
206   { return lhs.compare( rhs ) >= 0; }
207   /** \overload */
208   inline bool operator>=( const IdString & lhs, const std::string & rhs )
209   { return lhs.compare( rhs ) >= 0; }
210   /** \overload */
211   inline bool operator>=( const char * lhs, const IdString & rhs )
212   { return rhs.compare( lhs ) < 0; }
213   /** \overload */
214   inline bool operator>=( const std::string & lhs, const IdString & rhs )
215   { return rhs.compare( lhs ) < 0; }
216
217   /////////////////////////////////////////////////////////////////
218 } // namespace zypp
219 ///////////////////////////////////////////////////////////////////
220
221 ZYPP_DEFINE_ID_HASHABLE( ::zypp::IdString );
222
223 #endif // ZYPP_SAT_IDSTR_H