From 917d17cf1fb92e3f0499362009908881b9723c5c Mon Sep 17 00:00:00 2001 From: micio Date: Wed, 28 Nov 2012 19:03:55 +0000 Subject: [PATCH] Bazaar/PolyXML : added support for load/save progress callback git-svn-id: svn://ultimatepp.org/upp/trunk@5587 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/PolyXML/PolyXML.h | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/bazaar/PolyXML/PolyXML.h b/bazaar/PolyXML/PolyXML.h index c49cceaa6..3cffcf481 100644 --- a/bazaar/PolyXML/PolyXML.h +++ b/bazaar/PolyXML/PolyXML.h @@ -53,14 +53,19 @@ template class PolyXMLArray : public Array T& Add(const T &data) { return Array::Add(data); } T& Add(T *data) { return Array::Add(data); } + + // progress callback + Callback2Progress; }; template void PolyXMLArray::Xmlize(XmlIO &xml) { if(xml.IsStoring()) { - for(int i = 0; i < PolyXMLArray::GetCount(); i++) + int count = PolyXMLArray::GetCount(); + for(int i = 0; i < count; i++) { + Progress(i, count); T &data = PolyXMLArray::operator[](i); if(!data.IsErased()) { @@ -73,8 +78,10 @@ template void PolyXMLArray::Xmlize(XmlIO &xml) else { PolyXMLArray::Clear(); - for(int i = 0; i < xml->GetCount(); i++) + int count = xml->GetCount(); + for(int i = 0; i < count; i++) { + Progress(i, count); if(xml->Node(i).IsTag()) { String tag = xml->Node(i).GetTag(); @@ -111,14 +118,20 @@ template class PolyXMLArrayMap : public ArrayMap T& Add(const K &key, const T &data) { return ArrayMap::Add(key, data); } T& Add(const K &key, T *data) { return ArrayMap::Add(key, data); } + + // progress callback + Callback2Progress; }; template void PolyXMLArrayMap::Xmlize(XmlIO &xml) { if(xml.IsStoring()) { - for(int i = 0; i < PolyXMLArrayMap::GetCount(); i++) + int count = PolyXMLArrayMap::GetCount(); + for(int i = 0; i < count; i++) { + Progress(i, count); + // skip unlinked elements if(ArrayMap::IsUnlinked(i)) continue; @@ -138,8 +151,11 @@ template void PolyXMLArrayMap::Xmlize(XmlIO &xml) else { PolyXMLArrayMap::Clear(); - for(int i = 0; i < xml->GetCount() - 1 && xml->Node(i).IsTag("key");) + int count = xml->GetCount() - 1; + for(int i = 0; i < count && xml->Node(i).IsTag("key");) { + Progress(i, count); + if(xml->Node(i).IsTag()) { K key; @@ -176,14 +192,20 @@ template class PolyXMLArrayMapOne : public ArrayMap void Xmlize(XmlIO &xml); One& Add(const K &key, pick_ One &data) { return ArrayMap >::AddPick(key, data); } + + // progress callback + Callback2Progress; }; template void PolyXMLArrayMapOne::Xmlize(XmlIO &xml) { if(xml.IsStoring()) { - for(int i = 0; i < PolyXMLArrayMapOne::GetCount(); i++) + int count = PolyXMLArrayMapOne::GetCount(); + for(int i = 0; i < count; i++) { + Progress(i, count); + // skip unlinked elements if(ArrayMap >::IsUnlinked(i)) continue; @@ -203,8 +225,11 @@ template void PolyXMLArrayMapOne::Xmlize(XmlIO &xml) else { PolyXMLArrayMapOne::Clear(); - for(int i = 0; i < xml->GetCount() - 1 && xml->Node(i).IsTag("key");) + int count = xml->GetCount() - 1; + for(int i = 0; i < count && xml->Node(i).IsTag("key");) { + Progress(i, count); + if(xml->Node(i).IsTag()) { K key;