00001 /*************************************************************************** 00002 ** 00003 ** This file is part of QGpCoreTools. 00004 ** 00005 ** This library is free software; you can redistribute it and/or 00006 ** modify it under the terms of the GNU Lesser General Public 00007 ** License as published by the Free Software Foundation; either 00008 ** version 2.1 of the License, or (at your option) any later version. 00009 ** 00010 ** This file is distributed in the hope that it will be useful, but WITHOUT 00011 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00013 ** License for more details. 00014 ** 00015 ** You should have received a copy of the GNU Lesser General Public 00016 ** License along with this library; if not, write to the Free Software 00017 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ** 00019 ** See http://www.geopsy.org for more information. 00020 ** 00021 ** Created : 2008-11-09 00022 ** Authors : 00023 ** Marc Wathelet 00024 ** Marc Wathelet (LGIT, Grenoble, France) 00025 ** 00026 ***************************************************************************/ 00027 00028 #ifndef XMLSAVEATTRIBUTES_H 00029 #define XMLSAVEATTRIBUTES_H 00030 00031 #include <QtCore> 00032 00033 #include "QGpCoreToolsDLLExport.h" 00034 00035 namespace QGpCoreTools { 00036 00037 class QGPCORETOOLS_EXPORT XMLSaveAttribute : private QPair<QString,QString> 00038 { 00039 public: 00040 XMLSaveAttribute() {} 00041 XMLSaveAttribute(const QString& key, const QString& value) {first=key; second=value;} 00042 00043 QString& key() {return first;} 00044 QString& value() {return second;} 00045 00046 const QString& key() const {return first;} 00047 const QString& value() const {return second;} 00048 00049 bool operator==(const XMLSaveAttribute& o) const {return first==o.first && second==o.second;} 00050 }; 00051 00052 class QGPCORETOOLS_EXPORT XMLSaveAttributes : private QList<XMLSaveAttribute> 00053 { 00054 public: 00055 XMLSaveAttributes() {} 00056 XMLSaveAttributes(const XMLSaveAttributes& o) : QList<XMLSaveAttribute>(o) {} 00057 00058 inline QString& add(QString key, QString value=QString::null); 00059 00060 const QString& key(int index) const {return (*this)[index].key();} 00061 const QString& value(int index) const {return (*this)[index].value();} 00062 QString& key(int index) {return (*this)[index].key();} 00063 QString& value(int index) {return (*this)[index].value();} 00064 QString value(const QString& key); 00065 00066 QString toString() const; 00067 inline QString toEncodedString() const; 00068 00069 void clear() {QList<XMLSaveAttribute>::clear();} 00070 bool isEmpty() const {return QList<XMLSaveAttribute>::isEmpty();} 00071 bool operator==(const XMLSaveAttributes& o) const {return QList<XMLSaveAttribute>::operator==(o);} 00072 bool isSimilar(const XMLSaveAttributes& o) const; 00073 }; 00074 00075 inline QString& XMLSaveAttributes::add(QString key, QString value) 00076 { 00077 append(XMLSaveAttribute(key, value)); 00078 return last().value(); 00079 } 00080 00081 } // namespace QGpCoreTools 00082 00083 #endif // XMLSAVEATTRIBUTES_H