akregator/src/librss

category.cpp
1/*
2 This file is part of Akregator.
3
4 Copyright (C) 2005 Frank Osterfeld <frank.osterfeld at kdemail.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "category.h"
26#include "tools_p.h"
27
28#include <tqdom.h>
29#include <tqstring.h>
30
31class TQString;
32
33namespace RSS
34{
35
36class Category::CategoryPrivate : public Shared
37{
38 public:
39 bool isNull;
40 TQString category;
41 TQString domain;
42
43 bool operator==(const CategoryPrivate &other) const
44 {
45 return (isNull && other.isNull) || (category == other.category && domain == other.domain);
46 }
47
48 static CategoryPrivate* copyOnWrite(CategoryPrivate* ep)
49 {
50 if (ep->count > 1)
51 {
52 ep->deref();
53 ep = new CategoryPrivate(*ep);
54 }
55 return ep;
56 }
57};
58
59bool Category::isNull() const
60{
61 return d == 0;
62}
63
64Category Category::fromXML(const TQDomElement& e)
65{
66 Category obj;
67 if (e.hasAttribute(TQString::fromLatin1("domain")))
68 obj.d->domain = e.attribute(TQString::fromLatin1("domain"));
69 obj.d->category = e.text();
70 obj.d->isNull = false;
71 return obj;
72}
73
74Category::Category() : d(new CategoryPrivate)
75{
76 d->isNull = true;
77}
78
79Category::Category(const Category& other) : d(0)
80{
81 *this = other;
82}
83
84Category::Category(const TQString& category, const TQString& domain) : d(new CategoryPrivate)
85{
86 d->isNull = false;
87 d->category = category;
88 d->domain = domain;
89}
90
91Category::~Category()
92{
93 if (d->deref())
94 {
95 delete d;
96 d = 0;
97 }
98}
99
100Category& Category::operator=(const Category& other)
101{
102 if (d != other.d)
103 {
104 other.d->ref();
105 if (d && d->deref())
106 delete d;
107 d = other.d;
108 }
109 return *this;
110}
111
112bool Category::operator==(const Category &other) const
113{
114 return *d == *other.d;
115}
116
117TQString Category::category() const
118{
119 return !d->isNull ? d->category : TQString();
120}
121
122TQString Category::domain() const
123{
124 return !d->isNull ? d->domain : TQString();
125}
126
127} // namespace RSS
128
129