SNAP Library 2.0, User Reference
2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <lx.h>
Public Member Functions | |
TILx (const PSIn &_SIn, const TFSet &OptSet=TFSet(), const TLxChDefTy &ChDefTy=lcdtUsAscii) | |
TILx & | operator= (const TILx &) |
void | SetOpt (const int &Opt, const bool &Val) |
TLxSym | AddRw (const TStr &Str) |
TLxSym | GetRw (const TStr &Str) |
PSIn | GetSIn (const char &SepCh) |
int | GetLnN () const |
bool | IsBof () const |
bool | IsEof () const |
TLxSym | GetSym (const TFSet &Expect) |
TLxSym | GetSym () |
TLxSym | GetSym (const TLxSym &Sym) |
TLxSym | GetSym (const TLxSym &Sym1, const TLxSym &Sym2) |
TLxSym | GetSym (const TLxSym &Sym1, const TLxSym &Sym2, const TLxSym &Sym3) |
TLxSym | GetSym (const TLxSym &Sym1, const TLxSym &Sym2, const TLxSym &Sym3, const TLxSym &Sym4) |
bool | GetBool () |
int | GetInt () |
double | GetFlt () |
TStr | GetStr (const TStr &_Str=TStr()) |
TStr | GetIdStr (const TStr &IdStr=TStr()) |
TStr | GetQStr (const TStr &QStr=TStr()) |
void | GetEoln () |
TStr | GetStrToCh (const char &ToCh) |
TStr | GetStrToEolnOrCh (const char &ToCh) |
TStr | GetStrToEoln (const bool &DoTrunc=false) |
TStr | GetStrToEolnAndCh (const char &ToCh) |
void | SkipToEoln () |
void | SkipToSym (const TLxSym &SkipToSym) |
void | PutSym (const TILxSymSt &SymSt) |
void | PutSym () |
TLxSym | PeekSym () |
TLxSym | PeekSym (const int &Syms) |
TStr | GetSymStr () const |
TStr | GetFPosStr () const |
bool | IsVar (const TStr &VarNm) |
void | GetVar (const TStr &VarNm, const bool &LBracket=false, const bool &NewLn=false) |
void | GetVarEnd (const bool &RBracket=false, const bool &NewLn=false) |
bool | PeekVarEnd (const bool &RBracket=false, const bool &NewLn=false) |
bool | GetVarBool (const TStr &VarNm, const bool &NewLn=true) |
int | GetVarInt (const TStr &VarNm, const bool &NewLn=true) |
double | GetVarFlt (const TStr &VarNm, const bool &NewLn=true) |
TStr | GetVarStr (const TStr &VarNm, const bool &NewLn=true) |
TSecTm | GetVarSecTm (const TStr &VarNm, const bool &NewLn=true) |
void | GetVarBoolV (const TStr &VarNm, TBoolV &BoolV, const bool &NewLn=true) |
void | GetVarIntV (const TStr &VarNm, TIntV &IntV, const bool &NewLn=true) |
void | GetVarFltV (const TStr &VarNm, TFltV &FltV, const bool &NewLn=true) |
void | GetVarStrV (const TStr &VarNm, TStrV &StrV, const bool &NewLn=true) |
void | GetVarStrPrV (const TStr &VarNm, TStrPrV &StrPrV, const bool &NewLn=true) |
void | GetVarStrVV (const TStr &VarNm, TVec< TStrV > &StrVV, const bool &NewLn=true) |
Static Public Member Functions | |
static TStr | GetQStr (const TStr &Str, const bool &QuoteP, const char &QuoteCh) |
static void | GetLnV (const TStr &FNm, TStrV &LnV) |
Public Attributes | |
TLxSym | Sym |
TChA | Str |
TChA | UcStr |
TChA | CmtStr |
bool | Bool |
int | Int |
double | Flt |
int | SymLnN |
int | SymLnChN |
int | SymChN |
bool | QuoteP |
char | QuoteCh |
Private Member Functions | |
char | GetCh () |
char | GetChX () |
Private Attributes | |
PLxChDef | ChDef |
PSIn | SIn |
TSIn & | RSIn |
char | PrevCh |
char | Ch |
int | LnN |
int | LnChN |
int | ChN |
TSStack< TILxSymSt > | PrevSymStStack |
TStrIntH | RwStrH |
bool | IsCmtAlw |
bool | IsRetEoln |
bool | IsSigNum |
bool | IsUniStr |
bool | IsCsSens |
bool | IsExcept |
bool | IsTabSep |
bool | IsList |
TILx::TILx | ( | const PSIn & | _SIn, |
const TFSet & | OptSet = TFSet() , |
||
const TLxChDefTy & | ChDefTy = lcdtUsAscii |
||
) |
Definition at line 270 of file lx.cpp.
: ChDef(TLxChDef::GetChDef(ChDefTy)), SIn(_SIn), RSIn(*SIn), PrevCh(' '), Ch(' '), LnN(0), LnChN(0-1), ChN(0-1), PrevSymStStack(), RwStrH(50), IsCmtAlw(false), IsRetEoln(false), IsSigNum(false), IsUniStr(false), IsCsSens(false), IsExcept(false), IsTabSep(false), IsList(false), Sym(syUndef), Str(), UcStr(), CmtStr(), Bool(false), Int(0), Flt(0), SymLnN(-1), SymLnChN(-1), SymChN(-1){ for (int Opt=0; Opt<iloMx; Opt++){ if (OptSet.In(Opt)){SetOpt(Opt, true);}} }
TLxSym TILx::AddRw | ( | const TStr & | Str | ) |
bool TILx::GetBool | ( | ) | [inline] |
char TILx::GetCh | ( | ) | [inline, private] |
char TILx::GetChX | ( | ) | [inline, private] |
double TILx::GetFlt | ( | ) | [inline] |
TStr TILx::GetFPosStr | ( | ) | const |
Definition at line 607 of file lx.cpp.
{ TChA ChA; ChA+="File:"; ChA+=SIn->GetSNm(); ChA+=" Line:"; ChA+=TInt::GetStr(LnN+1); ChA+=" Char:"; ChA+=TInt::GetStr(LnChN); return ChA; }
TStr TILx::GetIdStr | ( | const TStr & | IdStr = TStr() | ) | [inline] |
int TILx::GetInt | ( | ) | [inline] |
int TILx::GetLnN | ( | ) | const [inline] |
void TILx::GetLnV | ( | const TStr & | FNm, |
TStrV & | LnV | ||
) | [static] |
Definition at line 687 of file lx.cpp.
{ TFIn SIn(FNm); LnV.Clr(); TChA Ln; if (!SIn.Eof()){ char Ch=SIn.GetCh(); while (!SIn.Eof()){ if ((Ch==TCh::CrCh)||(Ch==TCh::LfCh)){ if (!SIn.Eof()){ char PrevCh=Ch; Ch=SIn.GetCh(); if (!SIn.Eof()){ if (PrevCh==TCh::CrCh){if (Ch==TCh::LfCh){Ch=SIn.GetCh();}} else if (PrevCh==TCh::LfCh){if (Ch==TCh::CrCh){Ch=SIn.GetCh();}} } } LnV.Add(Ln); Ln.Clr(); } else { Ln+=Ch; Ch=SIn.GetCh(); } } if (!Ln.Empty()){ LnV.Add(Ln);} } }
TStr TILx::GetQStr | ( | const TStr & | QStr = TStr() | ) | [inline] |
TStr TILx::GetQStr | ( | const TStr & | Str, |
const bool & | QuoteP, | ||
const char & | QuoteCh | ||
) | [static] |
TLxSym TILx::GetRw | ( | const TStr & | Str | ) | [inline] |
PSIn TILx::GetSIn | ( | const char & | SepCh | ) |
Definition at line 309 of file lx.cpp.
{ IAssert(PrevSymStStack.Empty()); while ((Ch!=TCh::EofCh)&&(Ch!=SepCh)){GetCh();} return SIn; }
TStr TILx::GetStr | ( | const TStr & | _Str = TStr() | ) | [inline] |
TStr TILx::GetStrToCh | ( | const char & | ToCh | ) |
TStr TILx::GetStrToEoln | ( | const bool & | DoTrunc = false | ) |
TStr TILx::GetStrToEolnAndCh | ( | const char & | ToCh | ) |
TStr TILx::GetStrToEolnOrCh | ( | const char & | ToCh | ) |
TLxSym TILx::GetSym | ( | const TFSet & | Expect | ) |
Definition at line 315 of file lx.cpp.
{ CmtStr.Clr(); if (!PrevSymStStack.Empty()){ // symbols already on the stack PrevSymStStack.Top().Restore(*this); PrevSymStStack.Pop(); } else if (Expect.In(syLn)){ // symbol is the whole line string if (Ch==TCh::EofCh){ Sym=syEof; } else { Str.Clr(); if (IsBof()){GetCh();} while (!ChDef->IsTerm(Ch)){Str.AddCh(Ch); GetCh();} bool _IsRetEoln=IsRetEoln; IsRetEoln=true; GetSym(TFSet()|syEoln|syEof); Sym=syLn; IsRetEoln=_IsRetEoln; } } else if (IsTabSep){ // symbol is between tab characters if (IsBof()){GetCh();} if (Ch==TCh::TabCh){ // tab character Sym=syTab; GetCh(); } else if (ChDef->IsTerm(Ch)){ // eoln & eof characters bool _IsRetEoln=IsRetEoln; IsRetEoln=true; IsTabSep=false; GetSym(TFSet()|syEoln|syEof); IsRetEoln=_IsRetEoln; IsTabSep=true; } else { Str.Clr(); while ((!ChDef->IsTerm(Ch))&&(Ch!=TCh::TabCh)){ Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh();} Sym=syStr; QuoteP=false; } } else { // usual symbol while (ChDef->IsSpace(Ch)){GetCh();} SymLnN=LnN; SymLnChN=LnChN; SymChN=ChN; if (ChDef->IsAlpha(Ch)){ if (IsUniStr){Sym=syStr;} else {Sym=syIdStr;} Str.Clr(); UcStr.Clr(); QuoteP=false; do {Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch));} while (ChDef->IsAlNum(GetCh())); if (!RwStrH.Empty()){ TStr RwStr=Str; if (!IsCsSens){RwStr=UcStr;} int SymKeyId=RwStrH.GetKeyId(RwStr); if (SymKeyId!=-1){Sym=TLxSym(int(RwStrH[SymKeyId]));} } if (Expect.In(syBool)){ Sym=syBool; IAssert(TBool::IsValStr(Str)); Bool=TBool::GetValFromStr(Str); } } else if ((Ch=='"')||(Ch=='\'')){ if (IsUniStr){Sym=syStr;} else {Sym=syQStr;} Str.Clr(); UcStr.Clr(); QuoteP=true; QuoteCh=Ch; GetCh(); forever{ while ((Ch!=QuoteCh)&&(Ch!='\\')&&(Ch!=TCh::EofCh)){ Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh();} if (Ch==TCh::EofCh){ Sym=syUndef; break; } else if (Ch==QuoteCh){ GetCh(); break; } else { GetCh(); switch (Ch){ case '"': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case '\\': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case '\'': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case '/': Str.AddCh(Ch); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case 'b': Str.AddCh('\b'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case 'f': Str.AddCh('\f'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case 'n': Str.AddCh('\n'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case 'r': Str.AddCh('\r'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case 't': Str.AddCh('\t'); UcStr.AddCh(ChDef->GetUc(Ch)); GetCh(); break; case 'u': { // unicode character, represented using 4 hexadecimal digits GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape"); int UChCd = TCh::GetHex(Ch); GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape"); UChCd = 16 * UChCd + TCh::GetHex(Ch); GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape"); UChCd = 16 * UChCd + TCh::GetHex(Ch); GetCh(); EAssertR(TCh::IsHex(Ch), "Invalid hexadecimal digit in unicode escape"); UChCd = 16 * UChCd + TCh::GetHex(Ch); // get as UTF8 encoded characters TUnicode::EncodeUtf8(UChCd, Str); TUnicode::EncodeUtf8(UChCd, UcStr); } GetCh(); break; default: Sym=syUndef; break; } if (Sym==syUndef){ throw PExcept(new TExcept("Invalid Escape Sequence in Quoted String"));} } } } else if ((ChDef->IsNum(Ch))||(IsSigNum&&((Ch=='+')||(Ch=='-')))){ Str.Clr(); bool IntP=true; do {Str.AddCh(Ch);} while (ChDef->IsNum(GetCh())); if (Expect.In(syFlt)){ if (Ch=='.'){ Str.AddCh(Ch); IntP=false; while (ChDef->IsNum(GetCh())){Str.AddCh(Ch);} } if ((Ch=='e')||(Ch=='E')){ Str.AddCh(Ch); GetCh(); IntP=false; if ((Ch=='+')||(Ch=='-')){Str.AddCh(Ch); GetCh();} while (ChDef->IsNum(Ch)){Str.AddCh(Ch); GetCh();} } } UcStr=Str; if (IntP&&(Expect.In(syInt))){ Sym=syInt; Int=atoi(Str.CStr()); } else { Sym=syFlt; Flt=atof(Str.CStr()); } } else if ((Ch==TCh::CrCh)||(Ch==TCh::LfCh)){ Sym=syEoln; if (Ch==TCh::CrCh){if (GetCh()==TCh::LfCh){GetCh();}} else if (Ch==TCh::LfCh){if (GetCh()==TCh::CrCh){GetCh();}} LnN++; LnChN=0; if (!IsRetEoln){GetSym(Expect);} } else if (Ch=='/'){ GetCh(); if ((IsCmtAlw)&&(Ch=='/')){ TChA _CmtStr; do {_CmtStr+=GetCh();} while (!ChDef->IsTerm(Ch)); _CmtStr.Pop(); _CmtStr.Trunc(); if (Ch==TCh::CrCh){ if (GetCh()==TCh::LfCh){GetCh();} } else if (Ch==TCh::LfCh){ if (GetCh()==TCh::CrCh){GetCh();} } if (IsRetEoln){Sym=syEoln;} else {GetSym(Expect);} CmtStr=_CmtStr; } else if (Ch=='*'){ TChA _CmtStr; do { while (GetCh()!='*'){_CmtStr+=Ch;} _CmtStr+=GetCh(); } while (Ch!='/'); _CmtStr.Pop(); _CmtStr.Pop(); _CmtStr.Trunc(); GetCh(); GetSym(Expect); CmtStr=_CmtStr; } else { Sym=sySlash; } } else if (Ch==TCh::EofCh){ Sym=syEof; } else { switch (Ch){ case '.': if (GetCh()=='.'){Sym=syDPeriod; GetCh();} else {Sym=syPeriod;} break; case ',': Sym=syComma; GetCh(); break; case ':': if (GetCh()==':'){Sym=syDColon; GetCh();} else {Sym=syColon;} break; case ';': Sym=sySemicolon; GetCh(); break; case '+': Sym=syPlus; GetCh(); break; case '-': Sym=syMinus; GetCh(); break; case '*': Sym=syAsterisk; GetCh(); break; case '/': Sym=sySlash; GetCh(); break; case '%': Sym=syPercent; GetCh(); break; case '!': Sym=syExclamation; GetCh(); break; case '|': Sym=syVBar; GetCh(); break; case '&': Sym=syAmpersand; GetCh(); break; case '=': Sym=syEq; GetCh(); break; case '<': GetCh(); if (Ch=='='){Sym=syLEq; GetCh();} else if (Ch=='>'){Sym=syNEq; GetCh();} else {Sym=syLss;} break; case '>': if (GetCh()=='='){Sym=syGEq; GetCh();} else {Sym=syGtr;} break; case '?': Sym=syQuestion; GetCh(); break; case '#': if (IsCmtAlw){ TChA _CmtStr; do {_CmtStr+=GetCh();} while (!ChDef->IsTerm(Ch)); _CmtStr.Pop(); _CmtStr.Trunc(); if (Ch==TCh::CrCh){ if (GetCh()==TCh::LfCh){GetCh();} } else if (Ch==TCh::LfCh){ if (GetCh()==TCh::CrCh){GetCh();} } if (IsRetEoln){Sym=syEoln;} else {GetSym(Expect);} CmtStr=_CmtStr; } else { Sym=syHash; GetCh(); } break; case '(': Sym=syLParen; GetCh(); break; case ')': Sym=syRParen; GetCh(); break; case '[': Sym=syLBracket; GetCh(); break; case ']': Sym=syRBracket; GetCh(); break; case '{': Sym=syLBrace; GetCh(); break; case '}': Sym=syRBrace; GetCh(); break; default: Sym=syUndef; GetCh(); break; } } } if ((!Expect.In(Sym))&&(!Expect.Empty())){ if (IsExcept){ TStr MsgStr= TStr("Unexpected symbol (")+GetSymStr()+") ["+GetFPosStr()+"]"; throw PExcept(new TExcept(MsgStr)); } else { Fail; } } return Sym; }
TLxSym TILx::GetSym | ( | const TLxSym & | Sym | ) | [inline] |
TLxSym TILx::GetSym | ( | const TLxSym & | Sym1, |
const TLxSym & | Sym2 | ||
) | [inline] |
TLxSym TILx::GetSym | ( | const TLxSym & | Sym1, |
const TLxSym & | Sym2, | ||
const TLxSym & | Sym3 | ||
) | [inline] |
TStr TILx::GetSymStr | ( | ) | const |
void TILx::GetVar | ( | const TStr & | VarNm, |
const bool & | LBracket = false , |
||
const bool & | NewLn = false |
||
) | [inline] |
bool TILx::GetVarBool | ( | const TStr & | VarNm, |
const bool & | NewLn = true |
||
) | [inline] |
void TILx::GetVarBoolV | ( | const TStr & | VarNm, |
TBoolV & | BoolV, | ||
const bool & | NewLn = true |
||
) |
void TILx::GetVarEnd | ( | const bool & | RBracket = false , |
const bool & | NewLn = false |
||
) | [inline] |
Definition at line 213 of file lx.h.
{ if (RBracket){GetSym(syRBracket);} if (NewLn){GetEoln();}}
double TILx::GetVarFlt | ( | const TStr & | VarNm, |
const bool & | NewLn = true |
||
) | [inline] |
void TILx::GetVarFltV | ( | const TStr & | VarNm, |
TFltV & | FltV, | ||
const bool & | NewLn = true |
||
) |
int TILx::GetVarInt | ( | const TStr & | VarNm, |
const bool & | NewLn = true |
||
) | [inline] |
void TILx::GetVarIntV | ( | const TStr & | VarNm, |
TIntV & | IntV, | ||
const bool & | NewLn = true |
||
) |
TSecTm TILx::GetVarSecTm | ( | const TStr & | VarNm, |
const bool & | NewLn = true |
||
) | [inline] |
TStr TILx::GetVarStr | ( | const TStr & | VarNm, |
const bool & | NewLn = true |
||
) | [inline] |
void TILx::GetVarStrPrV | ( | const TStr & | VarNm, |
TStrPrV & | StrPrV, | ||
const bool & | NewLn = true |
||
) |
Definition at line 664 of file lx.cpp.
{ StrPrV.Clr(); GetVar(VarNm, true, NewLn); while (GetSym(syRBracket, syLBracket)==syLBracket){ TStr Str1=GetQStr(); TStr Str2=GetQStr(); GetSym(syRBracket); StrPrV.Add(TStrPr(Str1, Str2)); if (NewLn){GetEoln();} } if (NewLn){GetEoln();} }
void TILx::GetVarStrV | ( | const TStr & | VarNm, |
TStrV & | StrV, | ||
const bool & | NewLn = true |
||
) |
void TILx::GetVarStrVV | ( | const TStr & | VarNm, |
TVec< TStrV > & | StrVV, | ||
const bool & | NewLn = true |
||
) |
Definition at line 675 of file lx.cpp.
{ StrVV.Clr(); GetVar(VarNm, true, NewLn); while (GetSym(syRBracket, syLBracket)==syLBracket){ StrVV.Add(); while (GetSym(syQStr, syRBracket)==syQStr){ StrVV.Last().Add(Str);} if (NewLn){GetEoln();} } if (NewLn){GetEoln();} }
bool TILx::IsBof | ( | ) | const [inline] |
bool TILx::IsEof | ( | ) | const [inline] |
Definition at line 168 of file lx.h.
{return Ch==TCh::EofCh;}
bool TILx::IsVar | ( | const TStr & | VarNm | ) | [inline] |
TLxSym TILx::PeekSym | ( | ) | [inline] |
TLxSym TILx::PeekSym | ( | const int & | Syms | ) |
Definition at line 580 of file lx.cpp.
{ TILxSymSt CurSymSt(*this); TSStack<TILxSymSt> SymStStack; for (int SymN=0; SymN<Syms; SymN++){ GetSym(); SymStStack.Push(TILxSymSt(*this));} TLxSym PeekedSym=Sym; while (!SymStStack.Empty()){ SymStStack.Top().Restore(*this); SymStStack.Pop(); PutSym(); } CurSymSt.Restore(*this); return PeekedSym; }
bool TILx::PeekVarEnd | ( | const bool & | RBracket = false , |
const bool & | NewLn = false |
||
) | [inline] |
void TILx::PutSym | ( | const TILxSymSt & | SymSt | ) | [inline] |
Definition at line 198 of file lx.h.
{PrevSymStStack.Push(TILxSymSt(SymSt));}
void TILx::PutSym | ( | ) | [inline] |
Definition at line 199 of file lx.h.
{PrevSymStStack.Push(TILxSymSt(*this));}
void TILx::SetOpt | ( | const int & | Opt, |
const bool & | Val | ||
) |
Definition at line 286 of file lx.cpp.
{ switch (Opt){ case iloCmtAlw: IsCmtAlw=Val; break; case iloRetEoln: IsRetEoln=Val; break; case iloSigNum: IsSigNum=Val; break; case iloUniStr: IsUniStr=Val; break; case iloCsSens: IsCsSens=Val; break; case iloExcept: IsExcept=Val; break; case iloTabSep: IsTabSep=Val; break; case iloList: IsList=Val; break; default: Fail; } }
void TILx::SkipToEoln | ( | ) |
void TILx::SkipToSym | ( | const TLxSym & | SkipToSym | ) | [inline] |
bool TILx::Bool |
PLxChDef TILx::ChDef [private] |
bool TILx::IsCmtAlw [private] |
bool TILx::IsCsSens [private] |
bool TILx::IsExcept [private] |
bool TILx::IsList [private] |
bool TILx::IsRetEoln [private] |
bool TILx::IsSigNum [private] |
bool TILx::IsTabSep [private] |
bool TILx::IsUniStr [private] |
int TILx::LnChN [private] |
char TILx::PrevCh [private] |
TSStack<TILxSymSt> TILx::PrevSymStStack [private] |
char TILx::QuoteCh |
bool TILx::QuoteP |
TSIn& TILx::RSIn [private] |
TStrIntH TILx::RwStrH [private] |
int TILx::SymChN |
int TILx::SymLnChN |
int TILx::SymLnN |