KDSOAP

KDSoapValue.h

00001 /****************************************************************************
00002 ** Copyright (C) 2010-2011 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 
00147     KDSoapValueList& childValues() const;
00148 
00152     bool operator==(const KDSoapValue& other) const;
00153 
00168     void setType(const QString& nameSpace, const QString& type);
00173     QString typeNs() const;
00178     QString type() const;
00179 
00184     enum Use
00185     {
00186       LiteralUse, 
00187       EncodedUse  
00188     };
00189 
00190     QByteArray toXml(Use use = LiteralUse, const QString& messageNamespace = QString()) const;
00191 
00192 private:
00193     // To catch mistakes
00194     KDSoapValue(QString, QString, QString);
00195 
00196     friend class KDSoapMessageWriter;
00197     void writeElement(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace) const;
00198     void writeElementContents(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace) const;
00199     void writeChildren(KDSoapNamespacePrefixes& namespacePrefixes, QXmlStreamWriter& writer, KDSoapValue::Use use, const QString& messageNamespace) const;
00200 
00201     class Private;
00202     QSharedDataPointer<Private> d;
00203 };
00204 
00205 Q_DECLARE_TYPEINFO( KDSoapValue, Q_MOVABLE_TYPE );
00206 
00207 KDSOAP_EXPORT QDebug operator <<(QDebug dbg, const KDSoapValue &value);
00208 
00209 KDSOAP_EXPORT uint qHash( const KDSoapValue& value );
00210 inline void qSwap( KDSoapValue & lhs, KDSoapValue & rhs ) { lhs.swap( rhs ); }
00211 
00212 #ifndef QT_NO_STL
00213 namespace std {
00214     template <> inline void swap<KDSoapValue>( KDSoapValue & lhs, KDSoapValue & rhs ) {
00215         lhs.swap( rhs );
00216     }
00217 }
00218 #endif
00219 
00226 class KDSOAP_EXPORT KDSoapValueList : public QList<KDSoapValue>
00227 {
00228 public:
00243     void addArgument(const QString& argumentName, const QVariant& argumentValue, const QString& typeNameSpace = QString(), const QString& typeName = QString());
00244 
00252     KDSoapValue child(const QString& name) const;
00253 
00262     void setArrayType(const QString& nameSpace, const QString& type);
00266     QString arrayTypeNs() const;
00270     QString arrayType() const;
00271 
00279     QList<KDSoapValue>& attributes() { return m_attributes; }
00283     const QList<KDSoapValue>& attributes() const { return m_attributes; }
00284 
00285 private:
00286     QPair<QString, QString> m_arrayType;
00287     QList<KDSoapValue> m_attributes;
00288 
00289     QVariant d; // for extensions
00290 };
00291 
00292 typedef QListIterator<KDSoapValue> KDSoapValueListIterator;
00293 
00294 //Q_DECLARE_METATYPE(KDSoapValueList)
00295 
00296 #endif // KDSOAPVALUE_H
 All Classes Functions Enumerations Enumerator

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