libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_SAT_IDSTR_H 00013 #define ZYPP_SAT_IDSTR_H 00014 00015 #include <iosfwd> 00016 #include <string> 00017 00018 #include "zypp/base/SafeBool.h" 00019 00020 #include "zypp/sat/detail/PoolMember.h" 00021 00023 namespace zypp 00024 { 00025 00026 class IdString; 00027 typedef std::tr1::unordered_set<IdString> IdStringSet; 00028 00030 // 00031 // CLASS NAME : IdString 00032 // 00041 class IdString : protected sat::detail::PoolMember, 00042 private base::SafeBool<IdString> 00043 { 00044 public: 00045 typedef sat::detail::IdType IdType; 00046 00047 public: 00049 IdString() : _id( sat::detail::emptyId ) {} 00050 00052 explicit IdString( IdType id_r ) : _id( id_r ) {} 00053 00055 explicit IdString( const char * str_r ); 00056 00058 explicit IdString( const std::string & str_r ); 00059 00060 public: 00062 static const IdString Null; 00063 00065 static const IdString Empty; 00066 00067 public: 00068 #ifndef SWIG // Swig treats it as syntax error 00069 00070 using base::SafeBool<IdString>::operator bool_type; 00071 #endif 00072 00075 bool empty() const 00076 { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); } 00077 00079 unsigned size() const; 00080 00081 public: 00083 const char * c_str() const; 00084 00086 std::string asString() const 00087 { return c_str(); } 00088 00089 public: 00091 bool compareEQ( const IdString & rhs ) const 00092 { return( _id == rhs.id() ); } 00093 00095 int compare( const IdString & rhs ) const; 00096 00098 int compare( const char * rhs ) const; 00099 00101 int compare( const std::string & rhs ) const 00102 { return compare( rhs.c_str() ); } 00103 00104 public: 00106 IdType id() const 00107 { return _id; } 00108 private: 00109 #ifndef SWIG // Swig treats it as syntax error 00110 friend base::SafeBool<IdString>::operator bool_type() const; 00111 #endif 00112 bool boolTest() const { return _id; } 00113 private: 00114 IdType _id; 00115 }; 00117 00119 std::ostream & operator<<( std::ostream & str, const IdString & obj ); 00120 00122 std::ostream & dumpOn( std::ostream & str, const IdString & obj ); 00123 00125 inline bool operator==( const IdString & lhs, const IdString & rhs ) 00126 { return lhs.compareEQ( rhs ); } 00128 inline bool operator==( const IdString & lhs, const char * rhs ) 00129 { return lhs.compare( rhs ) == 0; } 00131 inline bool operator==( const IdString & lhs, const std::string & rhs ) 00132 { return lhs.compare( rhs ) == 0; } 00134 inline bool operator==( const char * lhs, const IdString & rhs ) 00135 { return rhs.compare( lhs ) == 0; } 00137 inline bool operator==( const std::string & lhs, const IdString & rhs ) 00138 { return rhs.compare( lhs ) == 0; } 00139 00141 inline bool operator!=( const IdString & lhs, const IdString & rhs ) 00142 { return ! lhs.compareEQ( rhs ); } 00144 inline bool operator!=( const IdString & lhs, const char * rhs ) 00145 { return lhs.compare( rhs ) != 0; } 00147 inline bool operator!=( const IdString & lhs, const std::string & rhs ) 00148 { return lhs.compare( rhs ) != 0; } 00150 inline bool operator!=( const char * lhs, const IdString & rhs ) 00151 { return rhs.compare( lhs ) != 0; } 00153 inline bool operator!=( const std::string & lhs, const IdString & rhs ) 00154 { return rhs.compare( lhs ) != 0; } 00155 00157 inline bool operator<( const IdString & lhs, const IdString & rhs ) 00158 { return lhs.compare( rhs ) < 0; } 00160 inline bool operator<( const IdString & lhs, const char * rhs ) 00161 { return lhs.compare( rhs ) < 0; } 00163 inline bool operator<( const IdString & lhs, const std::string & rhs ) 00164 { return lhs.compare( rhs ) < 0; } 00166 inline bool operator<( const char * lhs, const IdString & rhs ) 00167 { return rhs.compare( lhs ) >= 0; } 00169 inline bool operator<( const std::string & lhs, const IdString & rhs ) 00170 { return rhs.compare( lhs ) >= 0; } 00171 00173 inline bool operator<=( const IdString & lhs, const IdString & rhs ) 00174 { return lhs.compare( rhs ) <= 0; } 00176 inline bool operator<=( const IdString & lhs, const char * rhs ) 00177 { return lhs.compare( rhs ) <= 0; } 00179 inline bool operator<=( const IdString & lhs, const std::string & rhs ) 00180 { return lhs.compare( rhs ) <= 0; } 00182 inline bool operator<=( const char * lhs, const IdString & rhs ) 00183 { return rhs.compare( lhs ) > 0; } 00185 inline bool operator<=( const std::string & lhs, const IdString & rhs ) 00186 { return rhs.compare( lhs ) > 0; } 00187 00189 inline bool operator>( const IdString & lhs, const IdString & rhs ) 00190 { return lhs.compare( rhs ) > 0; } 00192 inline bool operator>( const IdString & lhs, const char * rhs ) 00193 { return lhs.compare( rhs ) > 0; } 00195 inline bool operator>( const IdString & lhs, const std::string & rhs ) 00196 { return lhs.compare( rhs ) > 0; } 00198 inline bool operator>( const char * lhs, const IdString & rhs ) 00199 { return rhs.compare( lhs ) <= 0; } 00201 inline bool operator>( const std::string & lhs, const IdString & rhs ) 00202 { return rhs.compare( lhs ) <= 0; } 00203 00205 inline bool operator>=( const IdString & lhs, const IdString & rhs ) 00206 { return lhs.compare( rhs ) >= 0; } 00208 inline bool operator>=( const IdString & lhs, const char * rhs ) 00209 { return lhs.compare( rhs ) >= 0; } 00211 inline bool operator>=( const IdString & lhs, const std::string & rhs ) 00212 { return lhs.compare( rhs ) >= 0; } 00214 inline bool operator>=( const char * lhs, const IdString & rhs ) 00215 { return rhs.compare( lhs ) < 0; } 00217 inline bool operator>=( const std::string & lhs, const IdString & rhs ) 00218 { return rhs.compare( lhs ) < 0; } 00219 00221 } // namespace zypp 00223 00224 ZYPP_DEFINE_ID_HASHABLE( ::zypp::IdString ); 00225 00226 #endif // ZYPP_SAT_IDSTR_H