KD SOAP
 All Classes Functions Enumerations Enumerator Pages
KDSoapValue.h
1 /****************************************************************************
2 ** Copyright (C) 2010-2014 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  if ( this != &other ) {
103  KDSoapValue copy( other );
104  swap( copy );
105  }
106  return *this;
107  }
108 
112  void swap( KDSoapValue& other ) {
113 #if QT_VERSION < 0x040600
114  qSwap( reinterpret_cast<Private*&>(d), reinterpret_cast<Private*&>(other.d) );
115 #else
116  d.swap( other.d );
117 #endif
118  }
119 
124  bool isNull() const;
125 
131  bool isNil() const;
132 
137  void setNillable(bool nillable);
138 
142  QString name() const;
143 
147  QString namespaceUri() const;
148 
152  void setNamespaceUri(const QString& ns);
153 
157  QVariant value() const;
158 
162  void setValue(const QVariant& value);
163 
169  bool isQualified() const;
170 
183  void setQualified(bool qualified);
184 
189  KDSoapValueList& childValues() const;
190 
194  bool operator==(const KDSoapValue& other) const;
195 
199  bool operator!=(const KDSoapValue& other) const;
200 
215  void setType(const QString& nameSpace, const QString& type);
220  QString typeNs() const;
225  QString type() const;
226 
231  enum Use
232  {
234  EncodedUse
235  };
236 
237  QByteArray toXml(Use use = LiteralUse, const QString& messageNamespace = QString()) const;
238 
239 private:
240  // To catch mistakes
241  KDSoapValue(QString, QString, QString);
242 
243  friend class KDSoapMessageWriter;
244  void writeElement(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace, bool forceQualified) const;
245  void writeElementContents(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace) const;
246  void writeChildren(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace, bool forceQualified) const;
247 
248  class Private;
249  QSharedDataPointer<Private> d;
250 };
251 
252 Q_DECLARE_TYPEINFO( KDSoapValue, Q_MOVABLE_TYPE );
253 
254 KDSOAP_EXPORT QDebug operator <<(QDebug dbg, const KDSoapValue &value);
255 
256 KDSOAP_EXPORT uint qHash( const KDSoapValue& value );
257 inline void qSwap( KDSoapValue & lhs, KDSoapValue & rhs ) { lhs.swap( rhs ); }
258 
259 #ifndef QT_NO_STL
260 namespace std {
261  template <> inline void swap<KDSoapValue>( KDSoapValue & lhs, KDSoapValue & rhs ) {
262  lhs.swap( rhs );
263  }
264 }
265 #endif
266 
273 class KDSOAP_EXPORT KDSoapValueList : public QList<KDSoapValue> //krazy:exclude=dpointer
274 {
275 public:
291  void addArgument(const QString& argumentName, const QVariant& argumentValue, const QString& typeNameSpace = QString(), const QString& typeName = QString());
292 
300  KDSoapValue child(const QString& name) const;
301 
310  void setArrayType(const QString& nameSpace, const QString& type);
314  QString arrayTypeNs() const;
318  QString arrayType() const;
319 
327  QList<KDSoapValue>& attributes() { return m_attributes; }
331  const QList<KDSoapValue>& attributes() const { return m_attributes; }
332 
333 private:
334  QPair<QString, QString> m_arrayType;
335  QList<KDSoapValue> m_attributes;
336 
337  QVariant d; // for extensions
338 };
339 
340 typedef QListIterator<KDSoapValue> KDSoapValueListIterator;
341 
342 //Q_DECLARE_METATYPE(KDSoapValueList)
343 
344 #endif // KDSOAPVALUE_H

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