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 const StringMap& attributes() const { return m_attribs; }
00133 
00138       virtual TagList& children();
00139 
00144       virtual const TagList& children() const { return m_children; }
00145 
00151       virtual const std::string findAttribute( const std::string& name ) const;
00152 
00159       virtual bool hasAttribute( const std::string& name, const std::string& value = "" ) const;
00160 
00167       virtual Tag* findChild( const std::string& name );
00168 
00177       virtual Tag* findChild( const std::string& name, const std::string& attr,
00178                                const std::string& value = "" );
00179 
00188       virtual bool hasChild( const std::string& name, const std::string& attr = "",
00189                              const std::string& value = "" ) const;
00190 
00198       virtual Tag* findChildWithAttrib( const std::string& attr, const std::string& value = "" );
00199 
00207       virtual bool hasChildWithAttrib( const std::string& attr, const std::string& value = "" ) const;
00208 
00213       virtual bool empty() const { return m_name.empty(); };
00214 
00222       bool hasChildWithCData( const std::string& name, const std::string& cdata ) const;
00223 
00228       Tag* parent() { return m_parent; };
00229 
00234       virtual StanzaType type() const { return m_type; };
00235 
00241       virtual Tag* clone() const;
00242 
00243     protected:
00244       std::string m_name;
00245       StringMap m_attribs;
00246       std::string m_cdata;
00247       TagList m_children;
00248       Tag *m_parent;
00249       StanzaType m_type;
00250       bool m_incoming;
00251 
00252     private:
00253       struct duo
00254       {
00255         duo( std::string f, std::string s ) : first( f), second( s ) {};
00256         std::string first;
00257         std::string second;
00258       };
00259       typedef std::list<duo> Duo;
00260 
00261       const std::string escape( const std::string& what ) const;
00262       const std::string relax( const std::string& what ) const;
00263       const std::string replace( const std::string& what, const Duo& duo ) const;
00264 
00265   };
00266 
00267 }
00268 
00269 #endif // TAG_H__

Generated on Tue May 1 14:20:20 2007 for gloox by  doxygen 1.5.1