Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef XMLMAP_H
00029 #define XMLMAP_H
00030
00031 #include "XMLClass.h"
00032 #include "QGpCoreToolsDLLExport.h"
00033
00034 namespace QGpCoreTools {
00035
00036 template <class Key, class T>
00037 class QGPCORETOOLS_EXPORT XMLMap : public XMLClass
00038 {
00039 public:
00040 XMLMap(QString tag, QMap<Key,T> * map);
00041 XMLMap(QString tag, const QMap<Key,T> * map);
00042
00043 virtual const QString& xml_tagName() const {return _tag;}
00044 QMap<Key,T> * map() {return _map;}
00045 protected:
00046 virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00047 virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00048 virtual XMLMember xml_member(XML_MEMBER_ARGS);
00049 private:
00050 QString _tag;
00051 QMap<Key,T> * _map;
00052 };
00053
00054 template <class Key, class T>
00055 XMLMap<Key,T>::XMLMap(QString tag, QMap<Key,T> * map)
00056 {
00057 _tag=tag;
00058 _map=map;
00059 }
00060
00061 template <class Key, class T>
00062 XMLMap<Key,T>::XMLMap(QString tag, const QMap<Key,T> * map)
00063 {
00064 _tag=tag;
00065 _map=const_cast<QMap<Key,T> *>(map);
00066 }
00067
00068 template <class Key, class T>
00069 void XMLMap<Key,T>::xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const
00070 {
00071 TRACE;
00072 Q_UNUSED(context);
00073 static const QString tag="value";
00074 static const QString key("key");
00075 XMLSaveAttributes att;
00076 QString& value=att.add(key);
00077 QMapIterator<Key,T> it(*_map);
00078 while(it.hasNext()) {
00079 it.next();
00080 value=it.key();
00081 writeProperty(s, tag, att, it.value());
00082 }
00083 }
00084
00085 template <class Key, class T>
00086 XMLMember XMLMap<Key,T>::xml_member(XML_MEMBER_ARGS)
00087 {
00088 TRACE;
00089 Q_UNUSED(attributes);
00090 Q_UNUSED(context);
00091 if(tag=="value" ) return XMLMember(0);
00092 return XMLMember(XMLMember::Unknown);
00093 }
00094
00095 template <class Key, class T>
00096 bool XMLMap<Key,T>::xml_setProperty(XML_SETPROPERTY_ARGS)
00097 {
00098 TRACE;
00099 Q_UNUSED(context);
00100 static const QString att="key";
00101 if(memberID==0) {
00102 XMLRestoreAttributeIterator it=attributes.find(att);
00103 if(it!=attributes.end()) {
00104 Key tmpKey;
00105 T tmpT;
00106 _map->insert(it.value().to(tmpKey), content.to(tmpT));
00107 return true;
00108 }
00109 }
00110 return false;
00111 }
00112
00113 }
00114
00115 #endif // XMLMAP_H