SNAP Library 2.1, User Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <macro.h>
Public Member Functions | |
TMacro (const TStr &TxtStr, const char &_MacroCh='$', const char &_VarCh='#') | |
~TMacro () | |
TMacro (TSIn &) | |
void | Save (TSOut &) const |
TMacro & | operator= (const TMacro &) |
bool | IsOk () const |
TStr | GetMsgStr () const |
TStr | GetSrcTxtStr () const |
TStr | GetDstTxtStr () const |
int | GetSubstStrs () const |
TStr | GetSrcSubstStr (const int &SubstStrN) const |
bool | IsSrcSubstStr (const TStr &SrcSubstStr, int &SubstStrN) const |
int | GetSrcSubstStrN (const TStr &SrcSubstStr) const |
void | GetSrcSubstStrV (TStrV &SubstStrV) const |
TStr | GetDstSubstStr (const int &SubstStrN=0) const |
void | PutSubstValStr (const int &SubstStrN, const TStr &ValStr) |
TStr | GetSubstValStr (const int &SubstStrN) const |
TStr | GetAllSubstValStr () const |
int | GetVars () const |
TStr | GetVarNm (const int &VarN) const |
void | GetVarNmV (TStrV &VarNmV) const |
void | PutVarVal (const TStr &VarNm, const TStr &ValStr) |
TStr | GetVarVal (const TStr &VarNm) const |
Static Public Member Functions | |
static PMacro | New (const TStr &TxtStr, const char &MacroCh='$', const char &VarCh='#') |
static PMacro | Load (TSIn &) |
static void | SplitVarNm (const TStr &VarNm, TStr &CapStr, bool &IsComboBox, TStr &TbNm, TStr &ListFldNm, TStr &DataFldNm) |
Public Attributes | |
bool | Ok |
TStr | MsgStr |
char | MacroCh |
char | VarCh |
TStr | TxtStr |
TStrStrH | SubstToValStrH |
TStrStrH | VarNmToValStrH |
Private Attributes | |
TCRef | CRef |
Friends | |
class | TPt< TMacro > |
TMacro::TMacro | ( | const TStr & | TxtStr, |
const char & | _MacroCh = '$' , |
||
const char & | _VarCh = '#' |
||
) |
Definition at line 3 of file macro.cpp.
: Ok(true), MsgStr("Ok"), MacroCh(_MacroCh), VarCh(_VarCh), TxtStr(_TxtStr), SubstToValStrH(10), VarNmToValStrH(10){ int TxtStrLen=TxtStr.Len(); int TxtStrChN=0; while ((Ok)&&(TxtStrChN<TxtStrLen)){ if (TxtStr[TxtStrChN]==MacroCh){ // extract substitution from text TChA SubstChA; TxtStrChN++; while ((TxtStrChN<TxtStrLen)&&(TxtStr[TxtStrChN]!=MacroCh)){ SubstChA+=TxtStr[TxtStrChN]; TxtStrChN++;} Ok=(TxtStrChN<TxtStrLen); if (!Ok){MsgStr=SubstChA; break;} TxtStrChN++; SubstToValStrH.AddDat(SubstChA); // extract variable name from substitution int SubstChN=0; while ((Ok)&&(SubstChN<SubstChA.Len())){ if (SubstChA[SubstChN]==VarCh){ TChA VarNmChA; SubstChN++; while ((SubstChN<SubstChA.Len())&&(SubstChA[SubstChN]!=VarCh)){ VarNmChA+=SubstChA[SubstChN]; SubstChN++;} Ok=(SubstChN<SubstChA.Len()); if (!Ok){MsgStr=VarNmChA; break;} SubstChN++; VarNmToValStrH.AddDat(VarNmChA); } else { SubstChN++; } } } else { TxtStrChN++; } } }
TMacro::~TMacro | ( | ) | [inline] |
TMacro::TMacro | ( | TSIn & | ) | [inline] |
TStr TMacro::GetAllSubstValStr | ( | ) | const |
Definition at line 87 of file macro.cpp.
{ TChA AllSubstValChA; for (int SubstStrN=0; SubstStrN<GetSubstStrs(); SubstStrN++){ if (SubstStrN>0){AllSubstValChA+=", ";} AllSubstValChA+=GetSubstValStr(SubstStrN); } return AllSubstValChA; }
TStr TMacro::GetDstSubstStr | ( | const int & | SubstStrN = 0 | ) | const |
Definition at line 67 of file macro.cpp.
{ TStr SrcSubstStr=SubstToValStrH.GetKey(SubstStrN); int SrcSubstStrLen=SrcSubstStr.Len(); int SrcSubstChN=0; TChA DstSubstChA; while (SrcSubstChN<SrcSubstStrLen){ if (SrcSubstStr[SrcSubstChN]==VarCh){ TChA VarNmChA; SrcSubstChN++; while ((SrcSubstChN<SrcSubstStrLen)&&(SrcSubstStr[SrcSubstChN]!=VarCh)){ VarNmChA+=SrcSubstStr[SrcSubstChN]; SrcSubstChN++;} IAssert(SrcSubstChN<SrcSubstStrLen); SrcSubstChN++; TStr VarVal=GetVarVal(VarNmChA); DstSubstChA+=VarVal; } else { DstSubstChA+=SrcSubstStr[SrcSubstChN]; SrcSubstChN++; } } return DstSubstChA; }
TStr TMacro::GetDstTxtStr | ( | ) | const |
Definition at line 38 of file macro.cpp.
{ int TxtStrLen=TxtStr.Len(); int TxtStrChN=0; TChA DstTxtChA; while (TxtStrChN<TxtStrLen){ if (TxtStr[TxtStrChN]==MacroCh){ TChA SubstChA; TxtStrChN++; while ((TxtStrChN<TxtStrLen)&&(TxtStr[TxtStrChN]!=MacroCh)){ SubstChA+=TxtStr[TxtStrChN]; TxtStrChN++;} TxtStrChN++; int SubstKeyId; if (SubstToValStrH.IsKey(SubstChA, SubstKeyId)){ DstTxtChA+=SubstToValStrH[SubstKeyId]; } else { DstTxtChA+=MacroCh; DstTxtChA+=SubstChA; DstTxtChA+=MacroCh; } } else { DstTxtChA+=TxtStr[TxtStrChN]; TxtStrChN++; } } return DstTxtChA; }
TStr TMacro::GetMsgStr | ( | ) | const [inline] |
TStr TMacro::GetSrcSubstStr | ( | const int & | SubstStrN | ) | const [inline] |
Definition at line 33 of file macro.h.
{ return SubstToValStrH.GetKey(SubstStrN);}
int TMacro::GetSrcSubstStrN | ( | const TStr & | SrcSubstStr | ) | const [inline] |
Definition at line 37 of file macro.h.
{ return SubstToValStrH.GetKeyId(SrcSubstStr);}
void TMacro::GetSrcSubstStrV | ( | TStrV & | SubstStrV | ) | const |
Definition at line 60 of file macro.cpp.
{ SubstStrV.Gen(GetSubstStrs(), 0); for (int SubstStrN=0; SubstStrN<GetSubstStrs(); SubstStrN++){ SubstStrV.Add(GetSrcSubstStr(SubstStrN)); } }
TStr TMacro::GetSrcTxtStr | ( | ) | const [inline] |
int TMacro::GetSubstStrs | ( | ) | const [inline] |
Definition at line 32 of file macro.h.
{return SubstToValStrH.Len();}
TStr TMacro::GetSubstValStr | ( | const int & | SubstStrN | ) | const [inline] |
Definition at line 43 of file macro.h.
{ return SubstToValStrH[SubstStrN];}
TStr TMacro::GetVarNm | ( | const int & | VarN | ) | const [inline] |
Definition at line 48 of file macro.h.
{return VarNmToValStrH.GetKey(VarN);}
void TMacro::GetVarNmV | ( | TStrV & | VarNmV | ) | const |
int TMacro::GetVars | ( | ) | const [inline] |
Definition at line 47 of file macro.h.
{return VarNmToValStrH.Len();}
TStr TMacro::GetVarVal | ( | const TStr & | VarNm | ) | const [inline] |
Definition at line 52 of file macro.h.
{ return VarNmToValStrH.GetDat(VarNm);}
bool TMacro::IsOk | ( | ) | const [inline] |
bool TMacro::IsSrcSubstStr | ( | const TStr & | SrcSubstStr, |
int & | SubstStrN | ||
) | const [inline] |
Definition at line 35 of file macro.h.
{ return SubstToValStrH.IsKey(SrcSubstStr, SubstStrN);}
static PMacro TMacro::Load | ( | TSIn & | ) | [inline, static] |
static PMacro TMacro::New | ( | const TStr & | TxtStr, |
const char & | MacroCh = '$' , |
||
const char & | VarCh = '#' |
||
) | [inline, static] |
void TMacro::PutSubstValStr | ( | const int & | SubstStrN, |
const TStr & | ValStr | ||
) | [inline] |
Definition at line 41 of file macro.h.
{ SubstToValStrH[SubstStrN]=ValStr;}
void TMacro::PutVarVal | ( | const TStr & | VarNm, |
const TStr & | ValStr | ||
) | [inline] |
Definition at line 50 of file macro.h.
{ VarNmToValStrH.AddDat(VarNm, ValStr);}
void TMacro::Save | ( | TSOut & | ) | const [inline] |
void TMacro::SplitVarNm | ( | const TStr & | VarNm, |
TStr & | CapStr, | ||
bool & | IsComboBox, | ||
TStr & | TbNm, | ||
TStr & | ListFldNm, | ||
TStr & | DataFldNm | ||
) | [static] |
Definition at line 103 of file macro.cpp.
{ if (VarNm.SearchCh(':')==-1){ CapStr=VarNm; IsComboBox=false; TbNm=""; ListFldNm=""; DataFldNm=""; } else { int FirstColonChN=VarNm.SearchCh(':'); int SecondColonChN=VarNm.SearchCh(':', FirstColonChN+1); int ThirdColonChN=VarNm.SearchCh(':', SecondColonChN+1); IAssert((FirstColonChN!=-1)&&(SecondColonChN!=-1)); if (ThirdColonChN==-1){ThirdColonChN=VarNm.Len();} CapStr=VarNm.GetSubStr(0, FirstColonChN-1); IsComboBox=true; TbNm=VarNm.GetSubStr(FirstColonChN+1, SecondColonChN-1); ListFldNm=VarNm.GetSubStr(SecondColonChN+1, ThirdColonChN-1); if (ThirdColonChN!=VarNm.Len()){ DataFldNm=VarNm.GetSubStr(ThirdColonChN+1, VarNm.Len()-1); } else { DataFldNm=ListFldNm; } } }
TCRef TMacro::CRef [private] |
char TMacro::MacroCh |
bool TMacro::Ok |
char TMacro::VarCh |