tag.h

00001 /*
00002   Copyright (c) 2005-2006 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 #ifndef TAG_H__
00015 #define TAG_H__
00016 
00017 #include "gloox.h"
00018 
00019 #include <string>
00020 #include <list>
00021 #include <map>
00022 
00023 namespace gloox
00024 {
00025 
00032   class GLOOX_API Tag
00033   {
00034     public:
00038       typedef std::list<Tag*> TagList;
00039 
00043       Tag();
00044 
00052       Tag( const std::string& name, const std::string& cdata = "", bool incoming = false );
00053 
00063       Tag( Tag *parent, const std::string& name, const std::string& cdata = "", bool incoming = false );
00064 
00068       virtual ~Tag();
00069 
00075       virtual const std::string xml() const;
00076 
00082       virtual void addAttribute( const std::string& name, const std::string& value );
00083 
00090       virtual void addAttribute( const std::string& name, int value );
00091 
00096       virtual void addChild( Tag *child );
00097 
00102       virtual void setCData( const std::string& cdata );
00103 
00108       virtual void addCData( const std::string& cdata );
00109 
00114       virtual const std::string& name() const { return m_name; };
00115 
00120       virtual const std::string cdata() const;
00121 
00126       virtual StringMap& attributes();
00127 
00132       virtual TagList& children();
00133 
00139       virtual const std::string findAttribute( const std::string& name ) const;
00140 
00147       virtual bool hasAttribute( const std::string& name, const std::string& value = "" ) const;
00148 
00155       virtual Tag* findChild( const std::string& name );
00156 
00165       virtual Tag* findChild( const std::string& name, const std::string& attr,
00166                                const std::string& value = "" );
00167 
00176       virtual bool hasChild( const std::string& name, const std::string& attr = "",
00177                              const std::string& value = "" ) const;
00178 
00186       virtual Tag* findChildWithAttrib( const std::string& attr, const std::string& value = "" );
00187 
00195       virtual bool hasChildWithAttrib( const std::string& attr, const std::string& value = "" ) const;
00196 
00201       virtual bool empty() const { return m_name.empty(); };
00202 
00210       bool hasChildWithCData( const std::string& name, const std::string& cdata ) const;
00211 
00216       Tag* parent() { return m_parent; };
00217 
00222       virtual StanzaType type() const { return m_type; };
00223 
00229       virtual Tag* clone() const;
00230 
00231     protected:
00232       std::string m_name;
00233       StringMap m_attribs;
00234       std::string m_cdata;
00235       TagList m_children;
00236       Tag *m_parent;
00237       StanzaType m_type;
00238       bool m_incoming;
00239 
00240     private:
00241       struct duo
00242       {
00243         duo( std::string f, std::string s ) : first( f), second( s ) {};
00244         std::string first;
00245         std::string second;
00246       };
00247       typedef std::list<duo> Duo;
00248 
00249       const std::string escape( const std::string& what ) const;
00250       const std::string relax( const std::string& what ) const;
00251       const std::string replace( const std::string& what, const Duo& duo ) const;
00252 
00253   };
00254 
00255 }
00256 
00257 #endif // TAG_H__

Generated on Wed Dec 20 18:25:29 2006 for gloox by  doxygen 1.5.1