KD SOAP  1.10.0
KDSoapValue.h
1 /****************************************************************************
2 **
3 ** This file is part of the KD Soap library.
4 **
5 ** SPDX-FileCopyrightText: 2010-2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDAB-KDSoap OR LicenseRef-KDAB-KDSoap-US
8 **
9 ** Licensees holding valid commercial KD Soap licenses may use this file in
10 ** accordance with the KD Soap Commercial License Agreement provided with
11 ** the Software.
12 **
13 ** Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 **
15 ****************************************************************************/
16 #ifndef KDSOAPVALUE_H
17 #define KDSOAPVALUE_H
18 
19 #include <QtCore/QString>
20 #include <QtCore/QVariant>
21 #include <QtCore/QList>
22 #include <QtCore/QPair>
23 #include <QtCore/QSet>
24 #include <QtCore/QVector>
25 #include <QtCore/QSharedDataPointer>
26 #include <QtCore/QXmlStreamNamespaceDeclarations>
27 #include "KDSoapGlobal.h"
28 
29 #ifndef QT_NO_STL
30 # include <algorithm>
31 #endif
32 
33 // Qt-4.7 errors on QVariant::fromValue<signed char>(), but later versions support it.
34 #if QT_VERSION < 0x040800
35 Q_DECLARE_METATYPE(signed char)
36 #endif
37 
38 class KDSoapValueList;
39 class KDSoapNamespacePrefixes;
40 QT_BEGIN_NAMESPACE
41 class QXmlStreamWriter;
42 QT_END_NAMESPACE
43 
44 namespace KDSoap {
50 enum SoapVersion {
52  SOAP1_1 = 1,
54  SOAP1_2 = 2
55 };
56 }
57 
69 class KDSOAP_EXPORT KDSoapValue
70 {
71 public:
76  KDSoapValue();
80  ~KDSoapValue();
81 
90  KDSoapValue(const QString &name, const QVariant &valueVariant, const QString &typeNameSpace = QString(), const QString &typeName = QString());
99  KDSoapValue(const QString &name, const KDSoapValueList &childValues, const QString &typeNameSpace = QString(), const QString &typeName = QString());
100 
104  KDSoapValue(const KDSoapValue &other);
105 
110  {
111  if (this != &other) {
112  KDSoapValue copy(other);
113  swap(copy);
114  }
115  return *this;
116  }
117 
121  void swap(KDSoapValue &other)
122  {
123 #if QT_VERSION < 0x040600
124  qSwap(reinterpret_cast<Private *&>(d), reinterpret_cast<Private *&>(other.d));
125 #else
126  d.swap(other.d);
127 #endif
128  }
129 
134  bool isNull() const;
135 
141  bool isNil() const;
142 
147  void setNillable(bool nillable);
148 
152  QString name() const;
153 
157  QString namespaceUri() const;
158 
162  void setNamespaceUri(const QString &ns);
163 
167  QVariant value() const;
168 
172  void setValue(const QVariant &value);
173 
179  bool isQualified() const;
180 
193  void setQualified(bool qualified);
194 
199  KDSoapValueList &childValues() const;
200 
204  bool operator==(const KDSoapValue &other) const;
205 
209  bool operator!=(const KDSoapValue &other) const;
210 
225  void setType(const QString &nameSpace, const QString &type);
230  QString typeNs() const;
235  QString type() const;
236 
241  void setNamespaceDeclarations(const QXmlStreamNamespaceDeclarations& namespaceDeclarations);
242 
247  void addNamespaceDeclaration(const QXmlStreamNamespaceDeclaration& namespaceDeclaration);
248 
253  QXmlStreamNamespaceDeclarations namespaceDeclarations() const;
254 
259  void setEnvironmentNamespaceDeclarations(const QXmlStreamNamespaceDeclarations& environmentNamespaceDeclarations);
260 
265  QXmlStreamNamespaceDeclarations environmentNamespaceDeclarations() const;
266 
272  KDSoapValueList split() const;
273 
278  enum Use {
280  EncodedUse
281  };
282 
283  QByteArray toXml(Use use = LiteralUse, const QString &messageNamespace = QString()) const;
284 
285 protected: // for KDSoapMessage
286 
287  void setName(const QString &name);
288 
289 private:
290  // To catch mistakes
291  KDSoapValue(QString, QString, QString);
292 
293  friend class KDSoapMessageWriter;
294  void writeElement(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, KDSoapValue::Use use, const QString &messageNamespace, bool forceQualified) const;
295  void writeElementContents(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, KDSoapValue::Use use, const QString &messageNamespace) const;
296  void writeChildren(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, KDSoapValue::Use use, const QString &messageNamespace, bool forceQualified) const;
297 
298  class Private;
299  QSharedDataPointer<Private> d;
300 };
301 
302 QT_BEGIN_NAMESPACE
303 Q_DECLARE_TYPEINFO(KDSoapValue, Q_MOVABLE_TYPE);
304 QT_END_NAMESPACE
305 
306 KDSOAP_EXPORT QDebug operator <<(QDebug dbg, const KDSoapValue &value);
307 
308 KDSOAP_EXPORT uint qHash(const KDSoapValue &value);
309 inline void qSwap(KDSoapValue &lhs, KDSoapValue &rhs)
310 {
311  lhs.swap(rhs);
312 }
313 
314 #ifndef QT_NO_STL
315 namespace std
316 {
317 template <> inline void swap<KDSoapValue>(KDSoapValue &lhs, KDSoapValue &rhs)
318 {
319  lhs.swap(rhs);
320 }
321 }
322 #endif
323 
330 class KDSOAP_EXPORT KDSoapValueList : public QList<KDSoapValue> //krazy:exclude=dpointer
331 {
332 public:
348  void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace = QString(), const QString &typeName = QString());
349 
357  KDSoapValue child(const QString &name) const;
358 
367  void setArrayType(const QString &nameSpace, const QString &type);
371  QString arrayTypeNs() const;
375  QString arrayType() const;
376 
384  QList<KDSoapValue> &attributes()
385  {
386  return m_attributes;
387  }
391  const QList<KDSoapValue> &attributes() const
392  {
393  return m_attributes;
394  }
395 
396 private:
397  QPair<QString, QString> m_arrayType;
398  QList<KDSoapValue> m_attributes;
399 
400  QVariant d; // for extensions
401 };
402 
403 typedef QListIterator<KDSoapValue> KDSoapValueListIterator;
404 
405 //Q_DECLARE_METATYPE(KDSoapValueList)
406 
407 #endif // KDSOAPVALUE_H
data is serialized according to a given schema, no xsi:type attributes are written out ...
Definition: KDSoapValue.h:279
KDSoapValue & operator=(const KDSoapValue &other)
Definition: KDSoapValue.h:109
Use
Definition: KDSoapValue.h:278
Definition: KDSoapValue.h:315
Definition: KDSoapValue.h:69
void swap(KDSoapValue &other)
Definition: KDSoapValue.h:121
Definition: KDSoapValue.h:44
Definition: KDSoapValue.h:330
const QList< KDSoapValue > & attributes() const
Definition: KDSoapValue.h:391
QList< KDSoapValue > & attributes()
Definition: KDSoapValue.h:384

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-soap/