SNAP Library 2.1, Developer Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
xmlser.h
Go to the documentation of this file.
00001 #ifndef _xmlser_h
00002 #define _xmlser_h
00003 
00004 // !bn: pobrisan 'explicit' - je pa se v bd.h - a je prov tko?
00005 template <class TRec>
00006 TPt<TRec>::TPt(TSIn& SIn):
00007     Addr(NULL){TBool IsNull(SIn);
00008     if (!IsNull){TPt Pt=TRec::Load(SIn); Addr=Pt.Addr; MkRef();}}
00009 
00010 template <class TRec>
00011 TPt<TRec>::TPt(TSIn& SIn, void* ThisPt):
00012     Addr(NULL){TBool IsNull(SIn);
00013     if (!IsNull){TPt Pt=TRec::Load(SIn, ThisPt); Addr=Pt.Addr; MkRef();}}
00014 
00015 template <class TRec>
00016 void TPt<TRec>::Save(TSOut& SOut) const {
00017     if (Addr==NULL){TBool(true).Save(SOut);}
00018     else {TBool(false).Save(SOut); Addr->Save(SOut);}}
00019 
00020 template <class TRec>
00021 void TPt<TRec>::LoadXml(const TPt<TXmlTok>& XmlTok, const TStr& Nm){
00022   XLoadHd(Nm);
00023   bool NullP=TXmlObjSer::GetBoolArg(XmlTok, "Null");
00024   if (NullP){
00025     Addr=NULL;
00026   } else {
00027     Addr=new TRec(); MkRef();
00028     Addr->LoadXml(XmlTok, "-");
00029   }
00030 }
00031 
00032 template <class TRec>
00033 void TPt<TRec>::SaveXml(TSOut& SOut, const TStr& Nm) const {
00034   if (Addr==NULL){
00035     XSaveBETagArg(Nm, "Null", TBool::GetStr(true));
00036   } else {
00037     XSaveHdArg(Nm, "Null", TBool::GetStr(false));
00038     Addr->SaveXml(SOut, "-");
00039   }
00040 }
00041 
00043 // Xml-Object-Serialization
00044 template <class TRec>
00045 bool IsXLoadFromFileOk(const TStr& FNm, const TStr& Nm, TRec& Rec, TStr& MsgStr){
00046   bool Ok=true;
00047   try {
00048     PXmlDoc XmlDoc=TXmlDoc::LoadTxt(FNm);
00049     if (XmlDoc->IsOk()){
00050       PXmlTok XmlTok=XmlDoc->GetTok();
00051       Rec.LoadXml(XmlTok, Nm);
00052     } else {
00053       Ok=false; MsgStr=XmlDoc->GetMsgStr();
00054     }
00055   }
00056   catch (PExcept Except){
00057     Ok=false; MsgStr=Except->GetMsgStr();
00058   }
00059   return Ok;
00060 }
00061 
00062 template <class TRec>
00063 void XLoadFromFile(const TStr& FNm, const TStr& Nm, TRec& Rec){
00064   TStr MsgStr;
00065   if (!IsXLoadFromFileOk(FNm, Nm, Rec, MsgStr)){
00066     TExcept::Throw(MsgStr);
00067   }
00068 }
00069 
00070 template <class TVal1, class TVal2>
00071 void TPair<TVal1, TVal2>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
00072         XLoadHd(Nm); XLoad(Val1); XLoad(Val2);}
00073 
00074 template <class TVal1, class TVal2>
00075 void TPair<TVal1, TVal2>::SaveXml(TSOut& SOut, const TStr& Nm) const {
00076         XSaveHd(Nm); XSave(Val1); XSave(Val2);}
00077 
00078 template <class TVal1, class TVal2, class TVal3>
00079 void TTriple<TVal1, TVal2, TVal3>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
00080         XLoadHd(Nm); XLoad(Val1); XLoad(Val2); XLoad(Val3);}
00081 
00082 template <class TVal1, class TVal2, class TVal3>
00083 void TTriple<TVal1, TVal2, TVal3>::SaveXml(TSOut& SOut, const TStr& Nm) const {
00084         XSaveHd(Nm); XSave(Val1); XSave(Val2); XSave(Val3);}
00085 
00086 template <class TVal1, class TVal2, class TVal3, class TVal4>
00087 void TQuad< TVal1, TVal2, TVal3, TVal4>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
00088         XLoadHd(Nm); XLoad(Val1); XLoad(Val2); XLoad(Val3); XLoad(Val4);}
00089 
00090 template <class TVal1, class TVal2, class TVal3, class TVal4>
00091 void TQuad< TVal1, TVal2, TVal3, TVal4>::SaveXml(TSOut& SOut, const TStr& Nm) const {
00092         XSaveHd(Nm); XSave(Val1); XSave(Val2); XSave(Val3); XSave(Val4);}
00093 
00094 template <class TKey, class TDat>
00095 void TKeyDat< TKey, TDat>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
00096         XLoadHd(Nm); XLoad(Key); XLoad(Dat);}
00097 
00098 template <class TKey, class TDat>
00099 void TKeyDat< TKey, TDat>::SaveXml(TSOut& SOut, const TStr& Nm) const {
00100         XSaveHd(Nm); XSave(Key); XSave(Dat);}
00101 
00102 template <class TVal, class TSizeTy>
00103 void TVec<TVal, TSizeTy>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
00104   XLoadHd(Nm);
00105   TSizeTy SubToks=XmlTok->GetSubToks(); Gen(SubToks, 0);
00106   for (TSizeTy SubTokN=0; SubTokN<SubToks; SubTokN++){
00107     PXmlTok SubTok=XmlTok->GetSubTok(SubTokN);
00108     TVal Val; Val.LoadXml(SubTok, TStr()); Add(Val);
00109   }
00110 }
00111 
00112 template <class TVal, class TSizeTy>
00113 void TVec<TVal, TSizeTy>::SaveXml(TSOut& SOut, const TStr& Nm) const {
00114   XSaveHdArg(Nm, "Vals", TInt::GetStr(Vals));
00115   for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN].SaveXml(SOut, TStr());}
00116 }
00117 
00118 template <class TKey, class TDat>
00119 void THashKeyDat< TKey, TDat>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
00120         XLoadHd(Nm); XLoad(Key); XLoad(Dat);}
00121 
00122 template <class TKey, class TDat>
00123 void THashKeyDat< TKey, TDat>::SaveXml(TSOut& SOut, const TStr& Nm) const {
00124         XSaveHd(Nm); XSave(Key); XSave(Dat);}
00125 
00126 template<class TKey, class TDat, class THashFunc>
00127 void THash< TKey, TDat, THashFunc>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
00128   XLoadHd(Nm); TVec<THashKeyDat<TKey, TDat> > KeyDatV; XLoad(KeyDatV); XLoad(AutoSizeP);
00129         for (int KeyDatN=0; KeyDatN<KeyDatV.Len(); KeyDatN++){
00130                 AddDat(KeyDatV[KeyDatN].Key, KeyDatV[KeyDatN].Dat);}}
00131 
00132 template<class TKey, class TDat, class THashFunc>
00133 void THash< TKey, TDat, THashFunc>::SaveXml(TSOut& SOut, const TStr& Nm){
00134   Defrag(); XSaveHd(Nm); XSave(KeyDatV); XSave(AutoSizeP);}
00135 
00136 #endif