1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
/*
This file is part of KDE Schema Parser
Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
based on wsdlpull parser by Vivek Krishna
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "element.h"
#include <QDebug>
namespace XSD {
class Element::Private
{
public:
Private()
: mGroupId(0),
mMinOccurs(1),
mMaxOccurs(1),
mQualified(false),
mNillable(false),
mHasSubstitutions(false),
mOccurrence(0)
{
}
QName mType;
QString mDocumentation;
int mGroupId;
int mMinOccurs;
int mMaxOccurs;
bool mQualified;
bool mNillable;
bool mHasSubstitutions;
QString mDefaultValue;
QString mFixedValue;
int mOccurrence;
QName mReference;
Compositor mCompositor;
bool operator==(const Element::Private &other) const
{
return mType == other.mType && mGroupId == other.mGroupId && mMinOccurs == other.mMinOccurs
&& mMaxOccurs == other.mMaxOccurs && mQualified == other.mQualified
&& mNillable == other.mNillable && mHasSubstitutions == other.mHasSubstitutions
&& mDefaultValue == other.mDefaultValue && mFixedValue == other.mFixedValue
&& mOccurrence == other.mOccurrence && mReference == other.mReference
&& mCompositor.type() == other.mCompositor.type();
}
inline bool operator!=(const Element::Private &other) const { return !(*this == other); }
};
Element::Element() : XmlElement(), d(new Private) {}
Element::Element(const QString &nameSpace) : XmlElement(nameSpace), d(new Private) {}
Element::Element(const Element &other) : XmlElement(other), d(new Private)
{
*d = *other.d;
}
Element::Element(Element &&other) : XmlElement(other), d(std::move(other.d)) {}
Element::~Element() = default;
Element &Element::operator=(const Element &other)
{
if (this == &other) {
return *this;
}
*d = *other.d;
XmlElement::operator=(other);
return *this;
}
Element &Element::operator=(Element &&other) noexcept = default;
void Element::setType(const QName &type)
{
Q_ASSERT(!type.isEmpty());
d->mType = type;
}
QName Element::type() const
{
return d->mType;
}
void Element::setDocumentation(const QString &documentation)
{
d->mDocumentation = documentation;
}
QString Element::documentation() const
{
return d->mDocumentation;
}
// unused
void Element::setGroupId(int group)
{
d->mGroupId = group;
}
// unused
int Element::groupId() const
{
return d->mGroupId;
}
void Element::setMinOccurs(int minOccurs)
{
d->mMinOccurs = minOccurs;
}
int Element::minOccurs() const
{
return d->mMinOccurs;
}
void Element::setMaxOccurs(int maxOccurs)
{
d->mMaxOccurs = maxOccurs;
}
int Element::maxOccurs() const
{
return d->mMaxOccurs;
}
void Element::setDefaultValue(const QString &defaultValue)
{
d->mDefaultValue = defaultValue;
}
QString Element::defaultValue() const
{
return d->mDefaultValue;
}
void Element::setFixedValue(const QString &fixedValue)
{
d->mFixedValue = fixedValue;
}
QString Element::fixedValue() const
{
return d->mFixedValue;
}
void Element::setIsQualified(bool isQualified)
{
d->mQualified = isQualified;
}
bool Element::isQualified() const
{
return d->mQualified;
}
void Element::setNillable(bool nillable)
{
d->mNillable = nillable;
}
bool Element::nillable() const
{
return d->mNillable;
}
void Element::setOccurrence(int occurrence)
{
d->mOccurrence = occurrence;
}
int Element::occurrence() const
{
return d->mOccurrence;
}
void Element::setReference(const QName &reference)
{
Q_ASSERT(!reference.isEmpty());
d->mReference = reference;
}
QName Element::reference() const
{
return d->mReference;
}
bool Element::isResolved() const
{
return !d->mType.isEmpty() || d->mReference.isEmpty();
}
void Element::setCompositor(const Compositor &c)
{
d->mCompositor = c;
}
Compositor Element::compositor() const
{
return d->mCompositor;
}
void Element::setHasSubstitutions(bool hasSub)
{
d->mHasSubstitutions = hasSub;
}
bool Element::hasSubstitutions() const
{
return d->mHasSubstitutions;
}
bool Element::operator==(const Element &other) const
{
return XmlElement::operator==(other) && *d == *other.d;
}
Element ElementList::element(const QName &qualifiedName) const
{
const_iterator it = constBegin();
for (; it != constEnd(); ++it)
if ((*it).qualifiedName() == qualifiedName) {
return *it;
}
// qDebug() << "Simple type" << qualifiedName << "not found";
return Element();
}
ElementList::iterator ElementList::findElement(const QName &qualifiedName)
{
for (iterator it = begin(); it != end(); ++it)
if ((*it).qualifiedName() == qualifiedName) {
return it;
}
return end();
}
void ElementList::dump()
{
Q_FOREACH (const Element &element, *this) {
qDebug() << element.nameSpace() << element.name();
}
}
bool ElementList::operator==(const ElementList &other) const
{
if (count() != other.count())
return false;
// Ordered vs. unordered composition should be specified for a whole composition, but
// as the Compositor::Type is determined during parsing (per element)
// comparing per element should be semantically identic:
for (int i = 0; i < count(); i++) {
const Element &e = at(i);
// ordered
if (e.compositor().type() == Compositor::Sequence && other.at(i) != e)
return false;
// unordered
else if (e.compositor().type() != Compositor::Sequence && !other.contains(e))
return false;
}
return true;
}
} // namespace XSD
QDebug operator<<(QDebug dbg, const XSD::Element &element)
{
dbg << element.name();
return dbg;
}
|