akregator/src/librss
category.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "category.h"
00026 #include "tools_p.h"
00027
00028 #include <qdom.h>
00029 #include <qstring.h>
00030
00031 class QString;
00032
00033 namespace RSS
00034 {
00035
00036 class Category::CategoryPrivate : public Shared
00037 {
00038 public:
00039 bool isNull;
00040 QString category;
00041 QString domain;
00042
00043 bool operator==(const CategoryPrivate &other) const
00044 {
00045 return (isNull && other.isNull) || (category == other.category && domain == other.domain);
00046 }
00047
00048 static CategoryPrivate* copyOnWrite(CategoryPrivate* ep)
00049 {
00050 if (ep->count > 1)
00051 {
00052 ep->deref();
00053 ep = new CategoryPrivate(*ep);
00054 }
00055 return ep;
00056 }
00057 };
00058
00059 bool Category::isNull() const
00060 {
00061 return d == 0;
00062 }
00063
00064 Category Category::fromXML(const QDomElement& e)
00065 {
00066 Category obj;
00067 if (e.hasAttribute(QString::fromLatin1("domain")))
00068 obj.d->domain = e.attribute(QString::fromLatin1("domain"));
00069 obj.d->category = e.text();
00070 obj.d->isNull = false;
00071 return obj;
00072 }
00073
00074 Category::Category() : d(new CategoryPrivate)
00075 {
00076 d->isNull = true;
00077 }
00078
00079 Category::Category(const Category& other) : d(0)
00080 {
00081 *this = other;
00082 }
00083
00084 Category::Category(const QString& category, const QString& domain) : d(new CategoryPrivate)
00085 {
00086 d->isNull = false;
00087 d->category = category;
00088 d->domain = domain;
00089 }
00090
00091 Category::~Category()
00092 {
00093 if (d->deref())
00094 {
00095 delete d;
00096 d = 0;
00097 }
00098 }
00099
00100 Category& Category::operator=(const Category& other)
00101 {
00102 if (d != other.d)
00103 {
00104 other.d->ref();
00105 if (d && d->deref())
00106 delete d;
00107 d = other.d;
00108 }
00109 return *this;
00110 }
00111
00112 bool Category::operator==(const Category &other) const
00113 {
00114 return *d == *other.d;
00115 }
00116
00117 QString Category::category() const
00118 {
00119 return !d->isNull ? d->category : QString::null;
00120 }
00121
00122 QString Category::domain() const
00123 {
00124 return !d->isNull ? d->domain : QString::null;
00125 }
00126
00127 }
00128
00129
|