KDSOAP 1.2
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2010-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Soap library. 00005 ** 00006 ** Licensees holding valid commercial KD Soap licenses may use this file in 00007 ** accordance with the KD Soap Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 #ifndef KDSOAPVALUE_H 00023 #define KDSOAPVALUE_H 00024 00025 #include <QtCore/QString> 00026 #include <QtCore/QVariant> 00027 #include <QtCore/QList> 00028 #include <QtCore/QPair> 00029 #include <QtCore/QSet> 00030 #include <QtCore/QVector> 00031 #include <QtCore/QSharedDataPointer> 00032 #include "KDSoapGlobal.h" 00033 00034 #ifndef QT_NO_STL 00035 # include <algorithm> 00036 #endif 00037 00038 class KDSoapValueList; 00039 class KDSoapNamespacePrefixes; 00040 class QXmlStreamWriter; 00041 00053 class KDSOAP_EXPORT KDSoapValue 00054 { 00055 public: 00060 KDSoapValue(); 00064 ~KDSoapValue(); 00065 00075 KDSoapValue(const QString& name, const QVariant& valueVariant, const QString& typeNameSpace = QString(), const QString& typeName = QString()); 00084 KDSoapValue(const QString& name, const KDSoapValueList& childValues, const QString& typeNameSpace = QString(), const QString& typeName = QString()); 00085 00089 KDSoapValue(const KDSoapValue& other); 00090 00094 KDSoapValue& operator=(const KDSoapValue& other) { 00095 if ( this != &other ) { 00096 KDSoapValue copy( other ); 00097 swap( copy ); 00098 } 00099 return *this; 00100 } 00101 00105 void swap( KDSoapValue& other ) { 00106 #if QT_VERSION < 0x040600 00107 qSwap( reinterpret_cast<Private*&>(d), reinterpret_cast<Private*&>(other.d) ); 00108 #else 00109 d.swap( other.d ); 00110 #endif 00111 } 00112 00116 bool isNull() const; 00117 00121 QString name() const; 00122 00126 QString namespaceUri() const; 00127 00131 void setNamespaceUri(const QString& ns); 00132 00136 QVariant value() const; 00137 00141 void setValue(const QVariant& value); 00142 00148 bool isQualified() const; 00149 00162 void setQualified(bool qualified); 00163 00168 KDSoapValueList& childValues() const; 00169 00173 bool operator==(const KDSoapValue& other) const; 00174 00178 bool operator!=(const KDSoapValue& other) const; 00179 00194 void setType(const QString& nameSpace, const QString& type); 00199 QString typeNs() const; 00204 QString type() const; 00205 00210 enum Use 00211 { 00212 LiteralUse, 00213 EncodedUse 00214 }; 00215 00216 QByteArray toXml(Use use = LiteralUse, const QString& messageNamespace = QString()) const; 00217 00218 private: 00219 // To catch mistakes 00220 KDSoapValue(QString, QString, QString); 00221 00222 friend class KDSoapMessageWriter; 00223 void writeElement(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace, bool forceQualified) const; 00224 void writeElementContents(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace) const; 00225 void writeChildren(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace, bool forceQualified) const; 00226 00227 class Private; 00228 QSharedDataPointer<Private> d; 00229 }; 00230 00231 Q_DECLARE_TYPEINFO( KDSoapValue, Q_MOVABLE_TYPE ); 00232 00233 KDSOAP_EXPORT QDebug operator <<(QDebug dbg, const KDSoapValue &value); 00234 00235 KDSOAP_EXPORT uint qHash( const KDSoapValue& value ); 00236 inline void qSwap( KDSoapValue & lhs, KDSoapValue & rhs ) { lhs.swap( rhs ); } 00237 00238 #ifndef QT_NO_STL 00239 namespace std { 00240 template <> inline void swap<KDSoapValue>( KDSoapValue & lhs, KDSoapValue & rhs ) { 00241 lhs.swap( rhs ); 00242 } 00243 } 00244 #endif 00245 00252 class KDSOAP_EXPORT KDSoapValueList : public QList<KDSoapValue> 00253 { 00254 public: 00271 void addArgument(const QString& argumentName, const QVariant& argumentValue, const QString& typeNameSpace = QString(), const QString& typeName = QString()); 00272 00280 KDSoapValue child(const QString& name) const; 00281 00290 void setArrayType(const QString& nameSpace, const QString& type); 00294 QString arrayTypeNs() const; 00298 QString arrayType() const; 00299 00307 QList<KDSoapValue>& attributes() { return m_attributes; } 00311 const QList<KDSoapValue>& attributes() const { return m_attributes; } 00312 00313 private: 00314 QPair<QString, QString> m_arrayType; 00315 QList<KDSoapValue> m_attributes; 00316 00317 QVariant d; // for extensions 00318 }; 00319 00320 typedef QListIterator<KDSoapValue> KDSoapValueListIterator; 00321 00322 //Q_DECLARE_METATYPE(KDSoapValueList) 00323 00324 #endif // KDSOAPVALUE_H