IdString.h
Go to the documentation of this file.00001
00002
00003
00004
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
00027
00028
00029
00038 class IdString : protected sat::detail::PoolMember,
00039 private base::SafeBool<IdString>
00040 {
00041 public:
00042 typedef sat::detail::IdType IdType;
00043
00044 public:
00046 IdString() : _id( sat::detail::emptyId ) {}
00047
00049 explicit IdString( IdType id_r ) : _id( id_r ) {}
00050
00052 explicit IdString( const char * str_r );
00053
00055 explicit IdString( const std::string & str_r );
00056
00057 public:
00059 static const IdString Null;
00060
00062 static const IdString Empty;
00063
00064 public:
00065 #ifndef SWIG // Swig treats it as syntax error
00066
00067 using base::SafeBool<IdString>::operator bool_type;
00068 #endif
00069
00072 bool empty() const
00073 { return( _id == sat::detail::emptyId || _id == sat::detail::noId ); }
00074
00076 unsigned size() const;
00077
00078 public:
00080 const char * c_str() const;
00081
00083 std::string asString() const
00084 { return c_str(); }
00085
00086 public:
00088 bool compareEQ( const IdString & rhs ) const
00089 { return( _id == rhs.id() ); }
00090
00092 int compare( const IdString & rhs ) const;
00093
00095 int compare( const char * rhs ) const;
00096
00098 int compare( const std::string & rhs ) const
00099 { return compare( rhs.c_str() ); }
00100
00101 public:
00103 IdType id() const
00104 { return _id; }
00105 private:
00106 #ifndef SWIG // Swig treats it as syntax error
00107 friend base::SafeBool<IdString>::operator bool_type() const;
00108 #endif
00109 bool boolTest() const { return _id; }
00110 private:
00111 IdType _id;
00112 };
00114
00116 std::ostream & operator<<( std::ostream & str, const IdString & obj );
00117
00119 std::ostream & dumpOn( std::ostream & str, const IdString & obj );
00120
00122 inline bool operator==( const IdString & lhs, const IdString & rhs )
00123 { return lhs.compareEQ( rhs ); }
00125 inline bool operator==( const IdString & lhs, const char * rhs )
00126 { return lhs.compare( rhs ) == 0; }
00128 inline bool operator==( const IdString & lhs, const std::string & rhs )
00129 { return lhs.compare( rhs ) == 0; }
00131 inline bool operator==( const char * lhs, const IdString & rhs )
00132 { return rhs.compare( lhs ) == 0; }
00134 inline bool operator==( const std::string & lhs, const IdString & rhs )
00135 { return rhs.compare( lhs ) == 0; }
00136
00138 inline bool operator!=( const IdString & lhs, const IdString & rhs )
00139 { return ! lhs.compareEQ( rhs ); }
00141 inline bool operator!=( const IdString & lhs, const char * rhs )
00142 { return lhs.compare( rhs ) != 0; }
00144 inline bool operator!=( const IdString & lhs, const std::string & rhs )
00145 { return lhs.compare( rhs ) != 0; }
00147 inline bool operator!=( const char * lhs, const IdString & rhs )
00148 { return rhs.compare( lhs ) != 0; }
00150 inline bool operator!=( const std::string & lhs, const IdString & rhs )
00151 { return rhs.compare( lhs ) != 0; }
00152
00154 inline bool operator<( const IdString & lhs, const IdString & rhs )
00155 { return lhs.compare( rhs ) < 0; }
00157 inline bool operator<( const IdString & lhs, const char * rhs )
00158 { return lhs.compare( rhs ) < 0; }
00160 inline bool operator<( const IdString & lhs, const std::string & rhs )
00161 { return lhs.compare( rhs ) < 0; }
00163 inline bool operator<( const char * lhs, const IdString & rhs )
00164 { return rhs.compare( lhs ) >= 0; }
00166 inline bool operator<( const std::string & lhs, const IdString & rhs )
00167 { return rhs.compare( lhs ) >= 0; }
00168
00170 inline bool operator<=( const IdString & lhs, const IdString & rhs )
00171 { return lhs.compare( rhs ) <= 0; }
00173 inline bool operator<=( const IdString & lhs, const char * rhs )
00174 { return lhs.compare( rhs ) <= 0; }
00176 inline bool operator<=( const IdString & lhs, const std::string & rhs )
00177 { return lhs.compare( rhs ) <= 0; }
00179 inline bool operator<=( const char * lhs, const IdString & rhs )
00180 { return rhs.compare( lhs ) > 0; }
00182 inline bool operator<=( const std::string & lhs, const IdString & rhs )
00183 { return rhs.compare( lhs ) > 0; }
00184
00186 inline bool operator>( const IdString & lhs, const IdString & rhs )
00187 { return lhs.compare( rhs ) > 0; }
00189 inline bool operator>( const IdString & lhs, const char * rhs )
00190 { return lhs.compare( rhs ) > 0; }
00192 inline bool operator>( const IdString & lhs, const std::string & rhs )
00193 { return lhs.compare( rhs ) > 0; }
00195 inline bool operator>( const char * lhs, const IdString & rhs )
00196 { return rhs.compare( lhs ) <= 0; }
00198 inline bool operator>( const std::string & lhs, const IdString & rhs )
00199 { return rhs.compare( lhs ) <= 0; }
00200
00202 inline bool operator>=( const IdString & lhs, const IdString & rhs )
00203 { return lhs.compare( rhs ) >= 0; }
00205 inline bool operator>=( const IdString & lhs, const char * rhs )
00206 { return lhs.compare( rhs ) >= 0; }
00208 inline bool operator>=( const IdString & lhs, const std::string & rhs )
00209 { return lhs.compare( rhs ) >= 0; }
00211 inline bool operator>=( const char * lhs, const IdString & rhs )
00212 { return rhs.compare( lhs ) < 0; }
00214 inline bool operator>=( const std::string & lhs, const IdString & rhs )
00215 { return rhs.compare( lhs ) < 0; }
00216
00218 }
00220
00221 ZYPP_DEFINE_ID_HASHABLE( ::zypp::IdString );
00222
00223 #endif // ZYPP_SAT_IDSTR_H