|
From: Greg <evo...@us...> - 2005-12-16 16:43:32
|
Update of /cvsroot/evolutionlejeu/evolutionlejeu/ELib/Xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8372/ELib/Xml Modified Files: XmlNode.h Log Message: CHG : All list & vector are cleared before beiing loaded FIX : Misses in save/load of some classes Index: XmlNode.h =================================================================== RCS file: /cvsroot/evolutionlejeu/evolutionlejeu/ELib/Xml/XmlNode.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** XmlNode.h 18 Aug 2005 13:05:48 -0000 1.8 --- XmlNode.h 16 Dec 2005 16:43:22 -0000 1.9 *************** *** 50,103 **** template <class T> void GetListFromXml( EString esListName, std::vector<T> *pList ) { XmlNode xmlObj = GetChild( esListName ); - XmlNode xmlCursor = xmlObj.GetFirstChild(); ! while( xmlCursor.Valid() ) { ! T newT; ! newT.FromXml( xmlCursor ); ! pList->push_back( newT ); ! xmlCursor = xmlCursor.GetNextSibling(); } } template <class T> void GetListFromXml( EString esListName, std::list<T> *pList ) { ! XmlNode xmlObj = GetChild( esListName ); ! XmlNode xmlCursor = xmlObj.GetFirstChild(); ! while( xmlCursor.Valid() ) { ! T newT; ! newT.FromXml( xmlCursor ); ! pList->push_back( newT ); ! xmlCursor = xmlCursor.GetNextSibling(); } } template <class T> void GetIntVecFromXml( EString esVecName, std::vector<T> *pVec ) { ! XmlNode xmlObj = GetChild( esVecName ); ! XmlNode xmlCursor = xmlObj.GetFirstChild(); ! while( xmlCursor.Valid() ) { ! XmlNode xmlValue = xmlCursor.GetChild( "int" ); ! assert( xmlValue.Valid() ); ! pVec->push_back( (T)( xmlValue.GetValue().ToInt() ) ); ! ! xmlCursor = xmlCursor.GetNextSibling(); } } template <class T> void GetIntListFromXml( EString esListName, std::list<T> *pList ) { ! XmlNode xmlObj = GetChild( esListName ); ! XmlNode xmlCursor = xmlObj.GetFirstChild(); ! while( xmlCursor.Valid() ) { ! XmlNode xmlValue = xmlCursor.GetChild( "int" ); ! assert( xmlValue.Valid() ); ! pList->push_back( (T) xmlValue.GetValue().ToInt() ); ! ! xmlCursor = xmlCursor.GetNextSibling(); } } --- 50,124 ---- template <class T> void GetListFromXml( EString esListName, std::vector<T> *pList ) { + pList->clear(); + XmlNode xmlObj = GetChild( esListName ); ! if( xmlObj.Valid() ) { ! XmlNode xmlCursor = xmlObj.GetFirstChild(); ! ! while( xmlCursor.Valid() ) ! { ! T newT; ! newT.FromXml( xmlCursor ); ! pList->push_back( newT ); ! xmlCursor = xmlCursor.GetNextSibling(); ! } } } template <class T> void GetListFromXml( EString esListName, std::list<T> *pList ) { ! pList->clear(); ! XmlNode xmlObj = GetChild( esListName ); ! if( xmlObj.Valid() ) { ! XmlNode xmlCursor = xmlObj.GetFirstChild(); ! ! while( xmlCursor.Valid() ) ! { ! T newT; ! newT.FromXml( xmlCursor ); ! pList->push_back( newT ); ! xmlCursor = xmlCursor.GetNextSibling(); ! } } } template <class T> void GetIntVecFromXml( EString esVecName, std::vector<T> *pVec ) { ! pVec->clear(); ! XmlNode xmlObj = GetChild( esVecName ); ! if( xmlObj.Valid() ) { ! XmlNode xmlCursor = xmlObj.GetFirstChild(); ! ! while( xmlCursor.Valid() ) ! { ! XmlNode xmlValue = xmlCursor.GetChild( "int" ); ! assert( xmlValue.Valid() ); ! pVec->push_back( (T)( xmlValue.GetValue().ToInt() ) ); ! ! xmlCursor = xmlCursor.GetNextSibling(); ! } } } template <class T> void GetIntListFromXml( EString esListName, std::list<T> *pList ) { ! pList->clear(); ! XmlNode xmlObj = GetChild( esListName ); ! if( xmlObj.Valid() ) { ! XmlNode xmlCursor = xmlObj.GetFirstChild(); ! ! while( xmlCursor.Valid() ) ! { ! XmlNode xmlValue = xmlCursor.GetChild( "int" ); ! assert( xmlValue.Valid() ); ! pList->push_back( (T) xmlValue.GetValue().ToInt() ); ! ! xmlCursor = xmlCursor.GetNextSibling(); ! } } } *************** *** 121,131 **** // Add to Xml a vector of object with a ToXml method ! XmlNode xmlObj = AddChild( esListName ); ! std::vector<T>::iterator it; ! ! for( it = list.begin(); it != list.end(); ++ it ) { ! XmlNode xmlItem = xmlObj.AddChild( "item" ); ! it->ToXml( xmlItem ); } } --- 142,155 ---- // Add to Xml a vector of object with a ToXml method ! if( ! list.empty() ) { ! XmlNode xmlObj = AddChild( esListName ); ! std::vector<T>::iterator it; ! ! for( it = list.begin(); it != list.end(); ++ it ) ! { ! XmlNode xmlItem = xmlObj.AddChild( "item" ); ! it->ToXml( xmlItem ); ! } } } *************** *** 134,144 **** // Add to Xml a list of object with a ToXml method ! XmlNode xmlObj = AddChild( esListName ); ! std::list<T>::iterator it; ! ! for( it = list.begin(); it != list.end(); ++ it ) { ! XmlNode xmlItem = xmlObj.AddChild( "item" ); ! it->ToXml( xmlItem ); } } --- 158,171 ---- // Add to Xml a list of object with a ToXml method ! if( ! list.empty() ) { ! XmlNode xmlObj = AddChild( esListName ); ! std::list<T>::iterator it; ! ! for( it = list.begin(); it != list.end(); ++ it ) ! { ! XmlNode xmlItem = xmlObj.AddChild( "item" ); ! it->ToXml( xmlItem ); ! } } } *************** *** 147,158 **** // Add to Xml a map with a ToXml method ! XmlNode xmlObj = AddChild( esMapName, xmlNode ); ! std::map<K,T>::iterator it; ! ! for( it = map.begin(); it != map.end(); ++ it ) { ! XmlNode xmlItem = xmlObj.AddChild( "item" ); ! AddAttribute( "key", it->first, xmlItem ); ! it->second.ToXml( xmlItem ); } } --- 174,188 ---- // Add to Xml a map with a ToXml method ! if( ! map.empty() ) { ! XmlNode xmlObj = AddChild( esMapName, xmlNode ); ! std::map<K,T>::iterator it; ! ! for( it = map.begin(); it != map.end(); ++ it ) ! { ! XmlNode xmlItem = xmlObj.AddChild( "item" ); ! AddAttribute( "key", it->first, xmlItem ); ! it->second.ToXml( xmlItem ); ! } } } *************** *** 160,169 **** { // Add to Xml a vector of standard element like EString, int,... ! XmlNode xmlObj = AddChild( esListName ); ! std::vector<T>::iterator it; ! ! for( it = vector.begin(); it != vector.end(); ++ it ) { ! xmlObj.AddToXml( "item", (int)*it ); } } --- 190,203 ---- { // Add to Xml a vector of standard element like EString, int,... ! ! if( ! vector.empty() ) { ! XmlNode xmlObj = AddChild( esListName ); ! std::vector<T>::iterator it; ! ! for( it = vector.begin(); it != vector.end(); ++ it ) ! { ! xmlObj.AddToXml( "item", (int)*it ); ! } } } *************** *** 171,180 **** { // Add to Xml a list of standard element like EString, int,... - XmlNode xmlObj = AddChild( esListName ); - std::list<T>::iterator it; ! for( it = list.begin(); it != list.end(); ++ it ) { ! xmlObj.AddToXml( "item", *it ); } } --- 205,218 ---- { // Add to Xml a list of standard element like EString, int,... ! if( ! list.empty() ) { ! XmlNode xmlObj = AddChild( esListName ); ! std::list<T>::iterator it; ! ! for( it = list.begin(); it != list.end(); ++ it ) ! { ! xmlObj.AddToXml( "item", *it ); ! } } } |