libzypp  10.5.0
IdString.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include <boost/mpl/int.hpp>
00014 
00015 #include "zypp/IdString.h"
00016 
00017 #include "zypp/sat/detail/PoolImpl.h"
00018 #include "zypp/sat/Pool.h"
00019 
00020 using std::endl;
00021 
00023 namespace zypp
00024 { 
00025 
00026   const IdString IdString::Null ( sat::detail::noId );
00027   const IdString IdString::Empty( sat::detail::emptyId );
00028 
00030 
00031   IdString::IdString( const char * str_r )
00032   : _id( ::pool_str2id( myPool().getPool(), str_r, /*create*/true ) )
00033   {}
00034 
00035   IdString::IdString( const std::string & str_r )
00036   : _id( ::pool_str2id( myPool().getPool(), str_r.c_str(), /*create*/true ) )
00037   {}
00038 
00039   unsigned IdString::size() const
00040   { return ::strlen( c_str() ); }
00041 
00042   const char * IdString::c_str() const
00043   { return _id ? ::pool_id2str( myPool().getPool(), _id ) : ""; }
00044 
00045   int IdString::compare( const IdString & rhs ) const
00046   {
00047     if ( _id == rhs._id )
00048       return 0;
00049     // Explicitly handle IdString::Null < ""
00050     if ( ! _id )
00051       return -1;
00052     if ( ! rhs._id )
00053       return 1;
00054     return ::strcmp( c_str(), rhs.c_str() );
00055   }
00056 
00057   int IdString::compare( const char * rhs ) const
00058   {
00059     // Explicitly handle IdString::Null == (const char *)0
00060     if ( ! _id )
00061       return rhs ? -1 : 0;
00062     if ( ! rhs )
00063       return _id ? 1 : 0;
00064     return ::strcmp( c_str(), rhs );
00065   }
00066 
00067   /******************************************************************
00068   **
00069   **    FUNCTION NAME : operator<<
00070   **    FUNCTION TYPE : std::ostream &
00071   */
00072   std::ostream & operator<<( std::ostream & str, const IdString & obj )
00073   {
00074     return str << obj.c_str();
00075   }
00076 
00077   std::ostream & dumpOn( std::ostream & str, const IdString & obj )
00078   {
00079     return str << '(' << obj.id() << ')' << obj.c_str();
00080   }
00081 
00083 } // namespace zypp