tag.h

00001 /*
00002   Copyright (c) 2005 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_EXPORT 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 addAttrib( const std::string& name, const std::string& value );
00079 
00084       virtual void addChild( Tag *child );
00085 
00090       virtual void setCData( const std::string& cdata );
00091 
00096       virtual void addCData( const std::string& cdata );
00097 
00102       virtual std::string name() const { return m_name; };
00103 
00108       virtual std::string cdata() const;
00109 
00114       virtual StringMap& attributes();
00115 
00120       virtual TagList& children();
00121 
00127       virtual const std::string findAttribute( const std::string& name ) const;
00128 
00135       virtual bool hasAttribute( const std::string& name, const std::string& value = "" ) const;
00136 
00142       virtual Tag* findChild( const std::string& name );
00143 
00152       virtual bool hasChild( const std::string& name,
00153                              const std::string& attr = "", const std::string& value = "" ) const;
00154 
00162       virtual Tag* findChildWithAttrib( const std::string& attr, const std::string& value = "" );
00163 
00171       virtual bool hasChildWithAttrib( const std::string& attr, const std::string& value = "" ) const;
00172 
00177       virtual bool empty() const { return m_name.empty(); };
00178 
00186       bool hasChildWithCData( const std::string& name, const std::string& cdata ) const;
00187 
00192       Tag* parent() { return m_parent; };
00193 
00198       virtual StanzaType type() const { return m_type; };
00199 
00205       virtual Tag* clone();
00206 
00207     protected:
00208       std::string m_name;
00209       StringMap m_attribs;
00210       std::string m_cdata;
00211       TagList m_children;
00212       Tag *m_parent;
00213       StanzaType m_type;
00214 
00215     private:
00216       struct duo
00217       {
00218         duo( std::string f, std::string s ) : first( f), second( s ) {};
00219         std::string first;
00220         std::string second;
00221       };
00222       typedef std::list<duo> Duo;
00223 
00224       const std::string escape( const std::string& what ) const;
00225       const std::string relax( const std::string& what ) const;
00226       const std::string replace( const std::string& what, const Duo& duo ) const;
00227 
00228   };
00229 
00230 }
00231 
00232 #endif // TAG_H__

Generated on Mon Jan 16 16:19:54 2006 for gloox by  doxygen 1.4.6