00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_PARSER_XML_XMLSTRING_H 00013 #define ZYPP_PARSER_XML_XMLSTRING_H 00014 00015 #include <iosfwd> 00016 #include <string> 00017 00018 #include "zypp/base/PtrTypes.h" 00019 00020 #include "zypp/parser/xml/libxmlfwd.h" 00021 00023 namespace zypp 00024 { 00025 00026 namespace xml 00027 { 00028 00030 // 00031 // CLASS NAME : XmlString 00032 // 00039 class XmlString 00040 { 00042 struct Deleter 00043 { 00044 void operator()( const xmlChar * xmlstr_r ) const 00045 { xmlFree( (void*)(xmlstr_r) ); } 00046 }; 00047 00048 public: 00049 00051 enum OnDelete { NOFREE, FREE }; 00052 00056 XmlString( const xmlChar *const xmlstr_r = NULL, 00057 OnDelete ondelete_r = NOFREE ); 00058 00060 const xmlChar *const get() const 00061 { 00062 if ( ! _xmlstr ) 00063 return NULL; 00064 return &(*_xmlstr); 00065 } 00066 00068 operator const xmlChar *const() const 00069 { return get(); } 00070 00072 const char *const c_str() const 00073 { return reinterpret_cast<const char *const>(get()); } 00074 00076 std::string asString() const 00077 { 00078 if ( ! _xmlstr ) 00079 return std::string(); 00080 return c_str(); 00081 } 00082 00083 bool operator==( const std::string & rhs ) const 00084 { return( rhs == c_str() ); } 00085 00086 bool operator!=( const std::string & rhs ) const 00087 { return( rhs != c_str() ); } 00088 00089 bool operator==( const char *const rhs ) const 00090 { return( asString() == rhs ); } 00091 00092 bool operator!=( const char *const rhs ) const 00093 { return( asString() != rhs ); } 00094 00095 bool operator==( const XmlString & rhs ) const 00096 { return( asString() == rhs.c_str() ); } 00097 00098 bool operator!=( const XmlString & rhs ) const 00099 { return( asString() != rhs.c_str() ); } 00100 00101 private: 00104 shared_ptr<const xmlChar> _xmlstr; 00105 }; 00107 00109 std::ostream & operator<<( std::ostream & str, const XmlString & obj ); 00110 00112 } // namespace xml 00115 } // namespace zypp 00117 #endif // ZYPP_PARSER_XML_XMLSTRING_H
1.5.3