libzypp 17.38.15

IdString.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <boost/mpl/int.hpp>
14#include <boost/utility/string_ref.hpp>
15
16#include <zypp/IdString.h>
17#include <zypp/ng/sat/stringpool.h>
18
19 using std::endl;
20
22 namespace zypp
23{
24
25 const IdString IdString::Null ( sat::detail::noId );
26 const IdString IdString::Empty( sat::detail::emptyId );
27
28 using zyppng::sat::StringPool;
29
31
32 IdString::IdString( const char * str_r )
33 : _id( ::pool_str2id( StringPool::instance().getPool() , str_r, /*create*/true ) )
34 {}
35
36 IdString::IdString( const char * str_r, unsigned len_r )
37 : _id( ::pool_strn2id( StringPool::instance().getPool(), str_r, len_r, /*create*/true ) )
38 {}
39
40 IdString::IdString( const std::string & str_r )
41 : IdString( str_r.c_str(), str_r.length() )
42 {}
43
44 IdString::IdString( boost::string_ref str_r )
45 : IdString( str_r.data(), str_r.length() )
46 {}
47
48 unsigned IdString::size() const
49 { return ::strlen( c_str() ); }
50
51 const char * IdString::c_str() const
52 { return _id ? ::pool_id2str( StringPool::instance().getPool(), _id ) : ""; }
53
54 int IdString::compare( const IdString & rhs ) const
55 {
56 if ( _id == rhs._id )
57 return 0;
58 // Explicitly handle IdString::Null < ""
59 if ( ! _id )
60 return -1;
61 if ( ! rhs._id )
62 return 1;
63 return ::strcmp( c_str(), rhs.c_str() );
64 }
65
66 int IdString::compare( const char * rhs ) const
67 {
68 // Explicitly handle IdString::Null == (const char *)0
69 if ( ! _id )
70 return rhs ? -1 : 0;
71 if ( ! rhs )
72 return _id ? 1 : 0;
73 return ::strcmp( c_str(), rhs );
74 }
75
76 /******************************************************************
77 **
78 ** FUNCTION NAME : operator<<
79 ** FUNCTION TYPE : std::ostream &
80 */
81 std::ostream & operator<<( std::ostream & str, const IdString & obj )
82 {
83 return str << obj.c_str();
84 }
85
86 std::ostream & dumpOn( std::ostream & str, const IdString & obj )
87 {
88 return str << '(' << obj.id() << ')' << obj.c_str();
89 }
90
92} // namespace zypp
IdString.h
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::size
unsigned size() const
The strings size.
Definition IdString.cc:48
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *.
Definition IdString.cc:51
zypp::IdString::compare
int compare(const IdString &rhs) const
Compare IdString returning -1,0,1.
Definition IdString.cc:54
zypp::IdString::_id
IdType _id
Definition IdString.h:148
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:144
zypp::IdString::Null
static const IdString Null
No or Null string ( Id 0 ).
Definition IdString.h:86
zypp::IdString::Empty
static const IdString Empty
Empty string.
Definition IdString.h:89
zypp::IdString::IdString
constexpr IdString()
Default ctor, empty string.
Definition IdString.h:61
zypp::StringPool::instance
static StringPool & instance()
Access the global StringPool instance.
Definition stringpool.cc:18
zyppng::sat::StringPool
Singleton manager for the underlying libsolv string pool.
Definition stringpool.h:46
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
Definition Capability.cc:589
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
stringpool.h