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 
00050       Tag( const std::string& name, const std::string& cdata = "" );
00051 
00059       Tag( Tag *parent, const std::string& name, const std::string& cdata = "" );
00060 
00064       virtual ~Tag();
00065 
00071       virtual const std::string xml() const;
00072 
00078       virtual void addAttribute( const std::string& name, const std::string& value );
00079 
00086       virtual void addAttribute( const std::string& name, int value );
00087 
00092       virtual void addChild( Tag *child );
00093 
00098       virtual void setCData( const std::string& cdata );
00099 
00104       virtual void addCData( const std::string& cdata );
00105 
00110       virtual const std::string& name() const { return m_name; };
00111 
00116       virtual const std::string cdata() const;
00117 
00122       virtual StringMap& attributes();
00123 
00128       virtual TagList& children();
00129 
00135       virtual const std::string findAttribute( const std::string& name ) const;
00136 
00143       virtual bool hasAttribute( const std::string& name, const std::string& value = "" ) const;
00144 
00151       virtual Tag* findChild( const std::string& name );
00152 
00161       virtual Tag* findChild( const std::string& name, const std::string& attr,
00162                               const std::string& value = "" );
00163 
00172       virtual bool hasChild( const std::string& name, const std::string& attr = "",
00173                              const std::string& value = "" ) const;
00174 
00182       virtual Tag* findChildWithAttrib( const std::string& attr, const std::string& value = "" );
00183 
00191       virtual bool hasChildWithAttrib( const std::string& attr, const std::string& value = "" ) const;
00192 
00197       virtual bool empty() const { return m_name.empty(); };
00198 
00206       bool hasChildWithCData( const std::string& name, const std::string& cdata ) const;
00207 
00212       Tag* parent() { return m_parent; };
00213 
00218       virtual StanzaType type() const { return m_type; };
00219 
00225       virtual Tag* clone() const;
00226 
00227     protected:
00228       std::string m_name;
00229       StringMap m_attribs;
00230       std::string m_cdata;
00231       TagList m_children;
00232       Tag *m_parent;
00233       StanzaType m_type;
00234 
00235     private:
00236       struct duo
00237       {
00238         duo( std::string f, std::string s ) : first( f), second( s ) {};
00239         std::string first;
00240         std::string second;
00241       };
00242       typedef std::list<duo> Duo;
00243 
00244       const std::string escape( const std::string& what ) const;
00245       const std::string relax( const std::string& what ) const;
00246       const std::string replace( const std::string& what, const Duo& duo ) const;
00247 
00248   };
00249 
00250 }
00251 
00252 #endif // TAG_H__

Generated on Sun Sep 24 21:57:32 2006 for gloox by  doxygen 1.4.7