libzypp  10.5.0
XmlString.h
Go to the documentation of this file.
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 #include "zypp/parser/xml/XmlEscape.h"
00022 
00024 namespace zypp
00025 { 
00026 
00027   namespace xml
00028   { 
00029 
00031     //
00032     //  CLASS NAME : XmlString
00033     //
00040     class XmlString
00041     {
00043       struct Deleter
00044       {
00045         void operator()( const xmlChar * xmlstr_r ) const
00046         { xmlFree( (void*)(xmlstr_r) ); }
00047       };
00048 
00049     public:
00050 
00052       enum OnDelete { NOFREE, FREE };
00053 
00057       XmlString( const xmlChar *const xmlstr_r = NULL,
00058                  OnDelete ondelete_r           = NOFREE );
00059 
00061       const xmlChar * get() const
00062       {
00063         if ( ! _xmlstr )
00064           return NULL;
00065         return &(*_xmlstr);
00066       }
00067 
00069       operator const xmlChar * () const
00070       { return get(); }
00071 
00073       const char * c_str() const
00074       { return reinterpret_cast<const char *const>(get()); }
00075 
00077       std::string asString() const
00078       {
00079         if ( ! _xmlstr )
00080           return std::string();
00081         return c_str();
00082       }
00083 
00084       bool operator==( const std::string & rhs ) const
00085       { return( rhs == c_str() ); }
00086 
00087       bool operator!=( const std::string & rhs ) const
00088       { return( rhs != c_str() ); }
00089 
00090       bool operator==( const char *const rhs ) const
00091       { return( asString() == rhs ); }
00092 
00093       bool operator!=( const char *const rhs ) const
00094       { return( asString() != rhs ); }
00095 
00096       bool operator==( const XmlString & rhs ) const
00097       { return( asString() == rhs.c_str() ); }
00098 
00099       bool operator!=( const XmlString & rhs ) const
00100       { return( asString() != rhs.c_str() ); }
00101 
00102     private:
00105       shared_ptr<const xmlChar> _xmlstr;
00106     };
00108 
00110     std::ostream & operator<<( std::ostream & str, const XmlString & obj );
00111 
00113   } // namespace xml
00116 } // namespace zypp
00118 #endif // ZYPP_PARSER_XML_XMLSTRING_H