KD SOAP
KDSoapValue.h
1 /****************************************************************************
2 ** Copyright (C) 2010-2016 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com.
3 ** All rights reserved.
4 **
5 ** This file is part of the KD Soap library.
6 **
7 ** Licensees holding valid commercial KD Soap licenses may use this file in
8 ** accordance with the KD Soap Commercial License Agreement provided with
9 ** the Software.
10 **
11 **
12 ** This file may be distributed and/or modified under the terms of the
13 ** GNU Lesser General Public License version 2.1 and version 3 as published by the
14 ** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
15 **
16 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 **
19 ** Contact info@kdab.com if any conditions of this licensing are not
20 ** clear to you.
21 **
22 **********************************************************************/
23 #ifndef KDSOAPVALUE_H
24 #define KDSOAPVALUE_H
25 
26 #include <QtCore/QString>
27 #include <QtCore/QVariant>
28 #include <QtCore/QList>
29 #include <QtCore/QPair>
30 #include <QtCore/QSet>
31 #include <QtCore/QVector>
32 #include <QtCore/QSharedDataPointer>
33 #include "KDSoapGlobal.h"
34 
35 #ifndef QT_NO_STL
36 # include <algorithm>
37 #endif
38 
39 // Qt-4.7 errors on QVariant::fromValue<signed char>(), but later versions support it.
40 #if QT_VERSION < 0x040800
41 Q_DECLARE_METATYPE(signed char)
42 #endif
43 
44 class KDSoapValueList;
45 class KDSoapNamespacePrefixes;
46 QT_BEGIN_NAMESPACE
47 class QXmlStreamWriter;
48 QT_END_NAMESPACE
49 
61 class KDSOAP_EXPORT KDSoapValue
62 {
63 public:
68  KDSoapValue();
72  ~KDSoapValue();
73 
82  KDSoapValue(const QString &name, const QVariant &valueVariant, const QString &typeNameSpace = QString(), const QString &typeName = QString());
91  KDSoapValue(const QString &name, const KDSoapValueList &childValues, const QString &typeNameSpace = QString(), const QString &typeName = QString());
92 
96  KDSoapValue(const KDSoapValue &other);
97 
102  {
103  if (this != &other) {
104  KDSoapValue copy(other);
105  swap(copy);
106  }
107  return *this;
108  }
109 
113  void swap(KDSoapValue &other)
114  {
115 #if QT_VERSION < 0x040600
116  qSwap(reinterpret_cast<Private *&>(d), reinterpret_cast<Private *&>(other.d));
117 #else
118  d.swap(other.d);
119 #endif
120  }
121 
126  bool isNull() const;
127 
133  bool isNil() const;
134 
139  void setNillable(bool nillable);
140 
144  QString name() const;
145 
149  QString namespaceUri() const;
150 
154  void setNamespaceUri(const QString &ns);
155 
159  QVariant value() const;
160 
164  void setValue(const QVariant &value);
165 
171  bool isQualified() const;
172 
185  void setQualified(bool qualified);
186 
191  KDSoapValueList &childValues() const;
192 
196  bool operator==(const KDSoapValue &other) const;
197 
201  bool operator!=(const KDSoapValue &other) const;
202 
217  void setType(const QString &nameSpace, const QString &type);
222  QString typeNs() const;
227  QString type() const;
228 
233  enum Use {
235  EncodedUse
236  };
237 
238  QByteArray toXml(Use use = LiteralUse, const QString &messageNamespace = QString()) const;
239 
240 private:
241  // To catch mistakes
242  KDSoapValue(QString, QString, QString);
243 
244  friend class KDSoapMessageWriter;
245  void writeElement(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, KDSoapValue::Use use, const QString &messageNamespace, bool forceQualified) const;
246  void writeElementContents(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, KDSoapValue::Use use, const QString &messageNamespace) const;
247  void writeChildren(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, KDSoapValue::Use use, const QString &messageNamespace, bool forceQualified) const;
248 
249  class Private;
250  QSharedDataPointer<Private> d;
251 };
252 
253 Q_DECLARE_TYPEINFO(KDSoapValue, Q_MOVABLE_TYPE);
254 
255 KDSOAP_EXPORT QDebug operator <<(QDebug dbg, const KDSoapValue &value);
256 
257 KDSOAP_EXPORT uint qHash(const KDSoapValue &value);
258 inline void qSwap(KDSoapValue &lhs, KDSoapValue &rhs)
259 {
260  lhs.swap(rhs);
261 }
262 
263 #ifndef QT_NO_STL
264 namespace std
265 {
266 template <> inline void swap<KDSoapValue>(KDSoapValue &lhs, KDSoapValue &rhs)
267 {
268  lhs.swap(rhs);
269 }
270 }
271 #endif
272 
279 class KDSOAP_EXPORT KDSoapValueList : public QList<KDSoapValue> //krazy:exclude=dpointer
280 {
281 public:
297  void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace = QString(), const QString &typeName = QString());
298 
306  KDSoapValue child(const QString &name) const;
307 
316  void setArrayType(const QString &nameSpace, const QString &type);
320  QString arrayTypeNs() const;
324  QString arrayType() const;
325 
333  QList<KDSoapValue> &attributes()
334  {
335  return m_attributes;
336  }
340  const QList<KDSoapValue> &attributes() const
341  {
342  return m_attributes;
343  }
344 
345 private:
346  QPair<QString, QString> m_arrayType;
347  QList<KDSoapValue> m_attributes;
348 
349  QVariant d; // for extensions
350 };
351 
352 typedef QListIterator<KDSoapValue> KDSoapValueListIterator;
353 
354 //Q_DECLARE_METATYPE(KDSoapValueList)
355 
356 #endif // KDSOAPVALUE_H
data is serialized according to a given schema, no xsi:type attributes are written out ...
Definition: KDSoapValue.h:234
KDSoapValue & operator=(const KDSoapValue &other)
Definition: KDSoapValue.h:101
Use
Definition: KDSoapValue.h:233
Definition: KDSoapValue.h:264
Definition: KDSoapValue.h:61
void swap(KDSoapValue &other)
Definition: KDSoapValue.h:113
Definition: KDSoapValue.h:279
const QList< KDSoapValue > & attributes() const
Definition: KDSoapValue.h:340
QList< KDSoapValue > & attributes()
Definition: KDSoapValue.h:333

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-soap/