KD SOAP
 All Classes Functions Enumerations Enumerator Pages
KDSoapValue.h
1 /****************************************************************************
2 ** Copyright (C) 2010-2013 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Soap library.
5 **
6 ** Licensees holding valid commercial KD Soap licenses may use this file in
7 ** accordance with the KD Soap Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU Lesser General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 #ifndef KDSOAPVALUE_H
23 #define KDSOAPVALUE_H
24 
25 #include <QtCore/QString>
26 #include <QtCore/QVariant>
27 #include <QtCore/QList>
28 #include <QtCore/QPair>
29 #include <QtCore/QSet>
30 #include <QtCore/QVector>
31 #include <QtCore/QSharedDataPointer>
32 #include "KDSoapGlobal.h"
33 
34 #ifndef QT_NO_STL
35 # include <algorithm>
36 #endif
37 
38 // Qt-4.7 errors on QVariant::fromValue<signed char>(), but later versions support it.
39 #if QT_VERSION < 0x040800
40 Q_DECLARE_METATYPE(signed char)
41 #endif
42 
43 class KDSoapValueList;
44 class KDSoapNamespacePrefixes;
45 QT_BEGIN_NAMESPACE
46 class QXmlStreamWriter;
47 QT_END_NAMESPACE
48 
60 class KDSOAP_EXPORT KDSoapValue
61 {
62 public:
67  KDSoapValue();
71  ~KDSoapValue();
72 
81  KDSoapValue(const QString& name, const QVariant& valueVariant, const QString& typeNameSpace = QString(), const QString& typeName = QString());
90  KDSoapValue(const QString& name, const KDSoapValueList& childValues, const QString& typeNameSpace = QString(), const QString& typeName = QString());
91 
95  KDSoapValue(const KDSoapValue& other);
96 
101  if ( this != &other ) {
102  KDSoapValue copy( other );
103  swap( copy );
104  }
105  return *this;
106  }
107 
111  void swap( KDSoapValue& other ) {
112 #if QT_VERSION < 0x040600
113  qSwap( reinterpret_cast<Private*&>(d), reinterpret_cast<Private*&>(other.d) );
114 #else
115  d.swap( other.d );
116 #endif
117  }
118 
122  bool isNull() const;
123 
127  QString name() const;
128 
132  QString namespaceUri() const;
133 
137  void setNamespaceUri(const QString& ns);
138 
142  QVariant value() const;
143 
147  void setValue(const QVariant& value);
148 
154  bool isQualified() const;
155 
168  void setQualified(bool qualified);
169 
174  KDSoapValueList& childValues() const;
175 
179  bool operator==(const KDSoapValue& other) const;
180 
184  bool operator!=(const KDSoapValue& other) const;
185 
200  void setType(const QString& nameSpace, const QString& type);
205  QString typeNs() const;
210  QString type() const;
211 
216  enum Use
217  {
219  EncodedUse
220  };
221 
222  QByteArray toXml(Use use = LiteralUse, const QString& messageNamespace = QString()) const;
223 
224 private:
225  // To catch mistakes
226  KDSoapValue(QString, QString, QString);
227 
228  friend class KDSoapMessageWriter;
229  void writeElement(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace, bool forceQualified) const;
230  void writeElementContents(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace) const;
231  void writeChildren(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace, bool forceQualified) const;
232 
233  class Private;
234  QSharedDataPointer<Private> d;
235 };
236 
237 Q_DECLARE_TYPEINFO( KDSoapValue, Q_MOVABLE_TYPE );
238 
239 KDSOAP_EXPORT QDebug operator <<(QDebug dbg, const KDSoapValue &value);
240 
241 KDSOAP_EXPORT uint qHash( const KDSoapValue& value );
242 inline void qSwap( KDSoapValue & lhs, KDSoapValue & rhs ) { lhs.swap( rhs ); }
243 
244 #ifndef QT_NO_STL
245 namespace std {
246  template <> inline void swap<KDSoapValue>( KDSoapValue & lhs, KDSoapValue & rhs ) {
247  lhs.swap( rhs );
248  }
249 }
250 #endif
251 
258 class KDSOAP_EXPORT KDSoapValueList : public QList<KDSoapValue>
259 {
260 public:
276  void addArgument(const QString& argumentName, const QVariant& argumentValue, const QString& typeNameSpace = QString(), const QString& typeName = QString());
277 
285  KDSoapValue child(const QString& name) const;
286 
295  void setArrayType(const QString& nameSpace, const QString& type);
299  QString arrayTypeNs() const;
303  QString arrayType() const;
304 
312  QList<KDSoapValue>& attributes() { return m_attributes; }
316  const QList<KDSoapValue>& attributes() const { return m_attributes; }
317 
318 private:
319  QPair<QString, QString> m_arrayType;
320  QList<KDSoapValue> m_attributes;
321 
322  QVariant d; // for extensions
323 };
324 
325 typedef QListIterator<KDSoapValue> KDSoapValueListIterator;
326 
327 //Q_DECLARE_METATYPE(KDSoapValueList)
328 
329 #endif // KDSOAPVALUE_H

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