SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
xmlser.h
Go to the documentation of this file.
1 #ifndef _xmlser_h
2 #define _xmlser_h
3 
4 // !bn: pobrisan 'explicit' - je pa se v bd.h - a je prov tko?
5 template <class TRec>
7  Addr(NULL){TBool IsNull(SIn);
8  if (!IsNull){TPt Pt=TRec::Load(SIn); Addr=Pt.Addr; MkRef();}}
9 
10 template <class TRec>
11 TPt<TRec>::TPt(TSIn& SIn, void* ThisPt):
12  Addr(NULL){TBool IsNull(SIn);
13  if (!IsNull){TPt Pt=TRec::Load(SIn, ThisPt); Addr=Pt.Addr; MkRef();}}
14 
15 template <class TRec>
16 void TPt<TRec>::Save(TSOut& SOut) const {
17  if (Addr==NULL){TBool(true).Save(SOut);}
18  else {TBool(false).Save(SOut); Addr->Save(SOut);}}
19 
20 template <class TRec>
21 void TPt<TRec>::LoadXml(const TPt<TXmlTok>& XmlTok, const TStr& Nm){
22  XLoadHd(Nm);
23  bool NullP=TXmlObjSer::GetBoolArg(XmlTok, "Null");
24  if (NullP){
25  Addr=NULL;
26  } else {
27  Addr=new TRec(); MkRef();
28  Addr->LoadXml(XmlTok, "-");
29  }
30 }
31 
32 template <class TRec>
33 void TPt<TRec>::SaveXml(TSOut& SOut, const TStr& Nm) const {
34  if (Addr==NULL){
35  XSaveBETagArg(Nm, "Null", TBool::GetStr(true));
36  } else {
37  XSaveHdArg(Nm, "Null", TBool::GetStr(false));
38  Addr->SaveXml(SOut, "-");
39  }
40 }
41 
43 // Xml-Object-Serialization
44 template <class TRec>
45 bool IsXLoadFromFileOk(const TStr& FNm, const TStr& Nm, TRec& Rec, TStr& MsgStr){
46  bool Ok=true;
47  try {
48  PXmlDoc XmlDoc=TXmlDoc::LoadTxt(FNm);
49  if (XmlDoc->IsOk()){
50  PXmlTok XmlTok=XmlDoc->GetTok();
51  Rec.LoadXml(XmlTok, Nm);
52  } else {
53  Ok=false; MsgStr=XmlDoc->GetMsgStr();
54  }
55  }
56  catch (PExcept Except){
57  Ok=false; MsgStr=Except->GetMsgStr();
58  }
59  return Ok;
60 }
61 
62 template <class TRec>
63 void XLoadFromFile(const TStr& FNm, const TStr& Nm, TRec& Rec){
64  TStr MsgStr;
65  if (!IsXLoadFromFileOk(FNm, Nm, Rec, MsgStr)){
66  TExcept::Throw(MsgStr);
67  }
68 }
69 
70 template <class TVal1, class TVal2>
71 void TPair<TVal1, TVal2>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
72  XLoadHd(Nm); XLoad(Val1); XLoad(Val2);}
73 
74 template <class TVal1, class TVal2>
75 void TPair<TVal1, TVal2>::SaveXml(TSOut& SOut, const TStr& Nm) const {
76  XSaveHd(Nm); XSave(Val1); XSave(Val2);}
77 
78 template <class TVal1, class TVal2, class TVal3>
79 void TTriple<TVal1, TVal2, TVal3>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
80  XLoadHd(Nm); XLoad(Val1); XLoad(Val2); XLoad(Val3);}
81 
82 template <class TVal1, class TVal2, class TVal3>
83 void TTriple<TVal1, TVal2, TVal3>::SaveXml(TSOut& SOut, const TStr& Nm) const {
84  XSaveHd(Nm); XSave(Val1); XSave(Val2); XSave(Val3);}
85 
86 template <class TVal1, class TVal2, class TVal3, class TVal4>
88  XLoadHd(Nm); XLoad(Val1); XLoad(Val2); XLoad(Val3); XLoad(Val4);}
89 
90 template <class TVal1, class TVal2, class TVal3, class TVal4>
92  XSaveHd(Nm); XSave(Val1); XSave(Val2); XSave(Val3); XSave(Val4);}
93 
94 template <class TKey, class TDat>
95 void TKeyDat< TKey, TDat>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
96  XLoadHd(Nm); XLoad(Key); XLoad(Dat);}
97 
98 template <class TKey, class TDat>
99 void TKeyDat< TKey, TDat>::SaveXml(TSOut& SOut, const TStr& Nm) const {
100  XSaveHd(Nm); XSave(Key); XSave(Dat);}
101 
102 template <class TVal, class TSizeTy>
103 void TVec<TVal, TSizeTy>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
104  XLoadHd(Nm);
105  TSizeTy SubToks=XmlTok->GetSubToks(); Gen(SubToks, 0);
106  for (TSizeTy SubTokN=0; SubTokN<SubToks; SubTokN++){
107  PXmlTok SubTok=XmlTok->GetSubTok(SubTokN);
108  TVal Val; Val.LoadXml(SubTok, TStr()); Add(Val);
109  }
110 }
111 
112 template <class TVal, class TSizeTy>
113 void TVec<TVal, TSizeTy>::SaveXml(TSOut& SOut, const TStr& Nm) const {
114  XSaveHdArg(Nm, "Vals", TInt::GetStr(Vals));
115  for (TSizeTy ValN=0; ValN<Vals; ValN++){ValT[ValN].SaveXml(SOut, TStr());}
116 }
117 
118 template <class TKey, class TDat>
119 void THashKeyDat< TKey, TDat>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
120  XLoadHd(Nm); XLoad(Key); XLoad(Dat);}
121 
122 template <class TKey, class TDat>
123 void THashKeyDat< TKey, TDat>::SaveXml(TSOut& SOut, const TStr& Nm) const {
124  XSaveHd(Nm); XSave(Key); XSave(Dat);}
125 
126 template<class TKey, class TDat, class THashFunc>
127 void THash< TKey, TDat, THashFunc>::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
128  XLoadHd(Nm); TVec<THashKeyDat<TKey, TDat> > KeyDatV; XLoad(KeyDatV); XLoad(AutoSizeP);
129  for (int KeyDatN=0; KeyDatN<KeyDatV.Len(); KeyDatN++){
130  AddDat(KeyDatV[KeyDatN].Key, KeyDatV[KeyDatN].Dat);}}
131 
132 template<class TKey, class TDat, class THashFunc>
134  Defrag(); XSaveHd(Nm); XSave(KeyDatV); XSave(AutoSizeP);}
135 
136 #endif
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:113
TStr GetStr() const
Definition: dt.h:1197
#define XSaveBETagArg(Nm, ArgNm, ArgVal)
Definition: bd.h:327
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:99
#define XLoadHd(Nm)
Definition: bd.h:312
void XLoadFromFile(const TStr &FNm, const TStr &Nm, TRec &Rec)
Definition: xmlser.h:63
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:95
#define XSaveHdArg(Nm, ArgNm, ArgVal)
Definition: bd.h:321
#define XSaveHd(Nm)
Definition: bd.h:318
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:33
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
#define XLoad(Nm)
Definition: bd.h:315
PXmlTok GetSubTok(const int &SubTokN) const
Definition: xml.h:294
void Save(TSOut &SOut) const
Definition: dt.h:992
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:127
TPt()
Definition: bd.h:476
#define XSave(Nm)
Definition: bd.h:333
Definition: fl.h:58
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:87
static bool GetBoolArg(const PXmlTok &XmlTok, const TStr &Nm)
Definition: xml.cpp:59
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:83
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:119
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:91
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:71
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:103
Definition: fl.h:128
void MkRef() const
Definition: bd.h:464
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:75
TRec * Addr
Definition: bd.h:463
void Save(TSOut &SOut) const
Definition: xmlser.h:16
Definition: dt.h:412
void SaveXml(TSOut &SOut, const TStr &Nm)
Definition: xmlser.h:133
static PXmlDoc LoadTxt(TXmlLx &Lx)
Definition: xml.cpp:1401
static TStr GetStr(const bool &Val)
Definition: dt.h:1008
Definition: bd.h:196
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
Definition: xmlser.h:79
Definition: dt.h:971
void LoadXml(const TPt< TXmlTok > &XmlTok, const TStr &Nm)
Definition: xmlser.h:21
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430
int GetSubToks() const
Definition: xml.h:293
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: xmlser.h:123
bool IsXLoadFromFileOk(const TStr &FNm, const TStr &Nm, TRec &Rec, TStr &MsgStr)
Definition: xmlser.h:45