gloox 1.0.28
pubsubitem.cpp
1/*
2 Copyright (c) 2005-2023 by Jakob Schröter <js@camaya.net>
3 This file is part of the gloox library. http://camaya.net/gloox
4
5 This software is distributed under a license. The full license
6 agreement can be found in the file LICENSE in this distribution.
7 This software may not be copied, modified, sold or distributed
8 other than expressed in the named license agreement.
9
10 This software is distributed without any warranty.
11*/
12
13
14#include "pubsubitem.h"
15#include "tag.h"
16
17namespace gloox
18{
19
20 namespace PubSub
21 {
22
24 : m_payload( 0 )
25 {
26 }
27
28 Item::Item( const Tag* tag )
29 : m_payload( 0 )
30 {
31 if( !tag || tag->name() != "item" )
32 return;
33
34 m_id = tag->findAttribute( "id" );
35
36 if( tag->children().size() )
37 m_payload = tag->children().front()->clone();
38 }
39
40 Item::Item( const Item& item )
41 : m_payload( item.m_payload ? item.m_payload->clone() : 0 )
42 {
43 m_id = item.m_id;
44 }
45
47 {
48 delete m_payload;
49 }
50
51 void Item::setPayload( Tag* tag )
52 {
53 delete m_payload;
54 m_payload = tag;
55 }
56
57 Tag* Item::tag() const
58 {
59 Tag* t = new Tag( "item" );
60 t->addAttribute( "id", m_id );
61 if( m_payload )
62 t->addChild( m_payload->clone() );
63
64 return t;
65 }
66
67 }
68
69}
Abstracts a PubSub Item (XEP-0060).
Definition pubsubitem.h:38
void setPayload(Tag *tag)
Tag * tag() const
This is an abstraction of an XML element.
Definition tag.h:47
const std::string & name() const
Definition tag.h:394
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
void addChild(Tag *child)
Definition tag.cpp:424
const std::string & findAttribute(const std::string &name) const
Definition tag.cpp:589
Tag * clone() const
Definition tag.cpp:670
const TagList & children() const
Definition tag.cpp:510
The namespace for the gloox library.
Definition adhoc.cpp:28