SNAP Library 2.3, User Reference  2014-06-16 11:58:46
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
TMacro Class Reference

#include <macro.h>

Public Member Functions

 TMacro (const TStr &TxtStr, const char &_MacroCh='$', const char &_VarCh='#')
 
 ~TMacro ()
 
 TMacro (TSIn &)
 
void Save (TSOut &) const
 
TMacrooperator= (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 >
 

Detailed Description

Definition at line 5 of file macro.h.

Constructor & Destructor Documentation

TMacro::TMacro ( const TStr TxtStr,
const char &  _MacroCh = '$',
const char &  _VarCh = '#' 
)

Definition at line 3 of file macro.cpp.

3  :
4  Ok(true), MsgStr("Ok"), MacroCh(_MacroCh), VarCh(_VarCh),
5  TxtStr(_TxtStr), SubstToValStrH(10), VarNmToValStrH(10){
6  int TxtStrLen=TxtStr.Len(); int TxtStrChN=0;
7  while ((Ok)&&(TxtStrChN<TxtStrLen)){
8  if (TxtStr[TxtStrChN]==MacroCh){
9  // extract substitution from text
10  TChA SubstChA; TxtStrChN++;
11  while ((TxtStrChN<TxtStrLen)&&(TxtStr[TxtStrChN]!=MacroCh)){
12  SubstChA+=TxtStr[TxtStrChN]; TxtStrChN++;}
13  Ok=(TxtStrChN<TxtStrLen);
14  if (!Ok){MsgStr=SubstChA; break;}
15  TxtStrChN++;
16  SubstToValStrH.AddDat(SubstChA);
17  // extract variable name from substitution
18  int SubstChN=0;
19  while ((Ok)&&(SubstChN<SubstChA.Len())){
20  if (SubstChA[SubstChN]==VarCh){
21  TChA VarNmChA; SubstChN++;
22  while ((SubstChN<SubstChA.Len())&&(SubstChA[SubstChN]!=VarCh)){
23  VarNmChA+=SubstChA[SubstChN]; SubstChN++;}
24  Ok=(SubstChN<SubstChA.Len());
25  if (!Ok){MsgStr=VarNmChA; break;}
26  SubstChN++;
27  VarNmToValStrH.AddDat(VarNmChA);
28  } else {
29  SubstChN++;
30  }
31  }
32  } else {
33  TxtStrChN++;
34  }
35  }
36 }
int Len() const
Definition: dt.h:487
char VarCh
Definition: macro.h:10
int Len() const
Definition: dt.h:259
TStrStrH SubstToValStrH
Definition: macro.h:12
TStrStrH VarNmToValStrH
Definition: macro.h:13
bool Ok
Definition: macro.h:7
char MacroCh
Definition: macro.h:9
TStr MsgStr
Definition: macro.h:8
Definition: dt.h:201
TStr TxtStr
Definition: macro.h:11
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
TMacro::~TMacro ( )
inline

Definition at line 19 of file macro.h.

19 {}
TMacro::TMacro ( TSIn )
inline

Definition at line 20 of file macro.h.

20 {Fail;}
#define Fail
Definition: bd.h:238

Member Function Documentation

TStr TMacro::GetAllSubstValStr ( ) const

Definition at line 87 of file macro.cpp.

87  {
88  TChA AllSubstValChA;
89  for (int SubstStrN=0; SubstStrN<GetSubstStrs(); SubstStrN++){
90  if (SubstStrN>0){AllSubstValChA+=", ";}
91  AllSubstValChA+=GetSubstValStr(SubstStrN);
92  }
93  return AllSubstValChA;
94 }
Definition: dt.h:201
int GetSubstStrs() const
Definition: macro.h:32
TStr GetSubstValStr(const int &SubstStrN) const
Definition: macro.h:43
TStr TMacro::GetDstSubstStr ( const int &  SubstStrN = 0) const

Definition at line 67 of file macro.cpp.

67  {
68  TStr SrcSubstStr=SubstToValStrH.GetKey(SubstStrN);
69  int SrcSubstStrLen=SrcSubstStr.Len();
70  int SrcSubstChN=0;
71  TChA DstSubstChA;
72  while (SrcSubstChN<SrcSubstStrLen){
73  if (SrcSubstStr[SrcSubstChN]==VarCh){
74  TChA VarNmChA; SrcSubstChN++;
75  while ((SrcSubstChN<SrcSubstStrLen)&&(SrcSubstStr[SrcSubstChN]!=VarCh)){
76  VarNmChA+=SrcSubstStr[SrcSubstChN]; SrcSubstChN++;}
77  IAssert(SrcSubstChN<SrcSubstStrLen); SrcSubstChN++;
78  TStr VarVal=GetVarVal(VarNmChA);
79  DstSubstChA+=VarVal;
80  } else {
81  DstSubstChA+=SrcSubstStr[SrcSubstChN]; SrcSubstChN++;
82  }
83  }
84  return DstSubstChA;
85 }
#define IAssert(Cond)
Definition: bd.h:262
int Len() const
Definition: dt.h:487
char VarCh
Definition: macro.h:10
TStrStrH SubstToValStrH
Definition: macro.h:12
TStr GetVarVal(const TStr &VarNm) const
Definition: macro.h:52
Definition: dt.h:201
Definition: dt.h:412
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
TStr TMacro::GetDstTxtStr ( ) const

Definition at line 38 of file macro.cpp.

38  {
39  int TxtStrLen=TxtStr.Len(); int TxtStrChN=0;
40  TChA DstTxtChA;
41  while (TxtStrChN<TxtStrLen){
42  if (TxtStr[TxtStrChN]==MacroCh){
43  TChA SubstChA; TxtStrChN++;
44  while ((TxtStrChN<TxtStrLen)&&(TxtStr[TxtStrChN]!=MacroCh)){
45  SubstChA+=TxtStr[TxtStrChN]; TxtStrChN++;}
46  TxtStrChN++;
47  int SubstKeyId;
48  if (SubstToValStrH.IsKey(SubstChA, SubstKeyId)){
49  DstTxtChA+=SubstToValStrH[SubstKeyId];
50  } else {
51  DstTxtChA+=MacroCh; DstTxtChA+=SubstChA; DstTxtChA+=MacroCh;
52  }
53  } else {
54  DstTxtChA+=TxtStr[TxtStrChN]; TxtStrChN++;
55  }
56  }
57  return DstTxtChA;
58 }
int Len() const
Definition: dt.h:487
TStrStrH SubstToValStrH
Definition: macro.h:12
char MacroCh
Definition: macro.h:9
Definition: dt.h:201
TStr TxtStr
Definition: macro.h:11
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TStr TMacro::GetMsgStr ( ) const
inline

Definition at line 27 of file macro.h.

27 {return MsgStr;}
TStr MsgStr
Definition: macro.h:8
TStr TMacro::GetSrcSubstStr ( const int &  SubstStrN) const
inline

Definition at line 33 of file macro.h.

33  {
34  return SubstToValStrH.GetKey(SubstStrN);}
TStrStrH SubstToValStrH
Definition: macro.h:12
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
int TMacro::GetSrcSubstStrN ( const TStr SrcSubstStr) const
inline

Definition at line 37 of file macro.h.

37  {
38  return SubstToValStrH.GetKeyId(SrcSubstStr);}
TStrStrH SubstToValStrH
Definition: macro.h:12
int GetKeyId(const TKey &Key) const
Definition: hash.h:420
void TMacro::GetSrcSubstStrV ( TStrV SubstStrV) const

Definition at line 60 of file macro.cpp.

60  {
61  SubstStrV.Gen(GetSubstStrs(), 0);
62  for (int SubstStrN=0; SubstStrN<GetSubstStrs(); SubstStrN++){
63  SubstStrV.Add(GetSrcSubstStr(SubstStrN));
64  }
65 }
TStr GetSrcSubstStr(const int &SubstStrN) const
Definition: macro.h:33
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
int GetSubstStrs() const
Definition: macro.h:32
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TStr TMacro::GetSrcTxtStr ( ) const
inline

Definition at line 29 of file macro.h.

29 {return TxtStr;}
TStr TxtStr
Definition: macro.h:11
int TMacro::GetSubstStrs ( ) const
inline

Definition at line 32 of file macro.h.

32 {return SubstToValStrH.Len();}
TStrStrH SubstToValStrH
Definition: macro.h:12
int Len() const
Definition: hash.h:186
TStr TMacro::GetSubstValStr ( const int &  SubstStrN) const
inline

Definition at line 43 of file macro.h.

43  {
44  return SubstToValStrH[SubstStrN];}
TStrStrH SubstToValStrH
Definition: macro.h:12
TStr TMacro::GetVarNm ( const int &  VarN) const
inline

Definition at line 48 of file macro.h.

48 {return VarNmToValStrH.GetKey(VarN);}
TStrStrH VarNmToValStrH
Definition: macro.h:13
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
void TMacro::GetVarNmV ( TStrV VarNmV) const

Definition at line 96 of file macro.cpp.

96  {
97  VarNmV.Gen(GetVars(), 0);
98  for (int VarN=0; VarN<GetVars(); VarN++){
99  VarNmV.Add(GetVarNm(VarN));
100  }
101 }
TStr GetVarNm(const int &VarN) const
Definition: macro.h:48
int GetVars() const
Definition: macro.h:47
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int TMacro::GetVars ( ) const
inline

Definition at line 47 of file macro.h.

47 {return VarNmToValStrH.Len();}
TStrStrH VarNmToValStrH
Definition: macro.h:13
int Len() const
Definition: hash.h:186
TStr TMacro::GetVarVal ( const TStr VarNm) const
inline

Definition at line 52 of file macro.h.

52  {
53  return VarNmToValStrH.GetDat(VarNm);}
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TStrStrH VarNmToValStrH
Definition: macro.h:13
bool TMacro::IsOk ( ) const
inline

Definition at line 26 of file macro.h.

26 {return Ok;}
bool Ok
Definition: macro.h:7
bool TMacro::IsSrcSubstStr ( const TStr SrcSubstStr,
int &  SubstStrN 
) const
inline

Definition at line 35 of file macro.h.

35  {
36  return SubstToValStrH.IsKey(SrcSubstStr, SubstStrN);}
TStrStrH SubstToValStrH
Definition: macro.h:12
bool IsKey(const TKey &Key) const
Definition: hash.h:216
static PMacro TMacro::Load ( TSIn )
inlinestatic

Definition at line 21 of file macro.h.

21 {Fail; return NULL;}
#define Fail
Definition: bd.h:238
static PMacro TMacro::New ( const TStr TxtStr,
const char &  MacroCh = '$',
const char &  VarCh = '#' 
)
inlinestatic

Definition at line 16 of file macro.h.

17  {
18  return PMacro(new TMacro(TxtStr, MacroCh, VarCh));}
char VarCh
Definition: macro.h:10
char MacroCh
Definition: macro.h:9
TPt< TMacro > PMacro
Definition: macro.h:5
TMacro(const TStr &TxtStr, const char &_MacroCh='$', const char &_VarCh='#')
Definition: macro.cpp:3
TMacro& TMacro::operator= ( const TMacro )
inline

Definition at line 24 of file macro.h.

24 {Fail; return *this;}
#define Fail
Definition: bd.h:238
void TMacro::PutSubstValStr ( const int &  SubstStrN,
const TStr ValStr 
)
inline

Definition at line 41 of file macro.h.

41  {
42  SubstToValStrH[SubstStrN]=ValStr;}
TStrStrH SubstToValStrH
Definition: macro.h:12
void TMacro::PutVarVal ( const TStr VarNm,
const TStr ValStr 
)
inline

Definition at line 50 of file macro.h.

50  {
51  VarNmToValStrH.AddDat(VarNm, ValStr);}
TStrStrH VarNmToValStrH
Definition: macro.h:13
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
void TMacro::Save ( TSOut ) const
inline

Definition at line 22 of file macro.h.

22 {Fail;}
#define Fail
Definition: bd.h:238
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.

105  {
106  if (VarNm.SearchCh(':')==-1){
107  CapStr=VarNm; IsComboBox=false; TbNm=""; ListFldNm=""; DataFldNm="";
108  } else {
109  int FirstColonChN=VarNm.SearchCh(':');
110  int SecondColonChN=VarNm.SearchCh(':', FirstColonChN+1);
111  int ThirdColonChN=VarNm.SearchCh(':', SecondColonChN+1);
112  IAssert((FirstColonChN!=-1)&&(SecondColonChN!=-1));
113  if (ThirdColonChN==-1){ThirdColonChN=VarNm.Len();}
114  CapStr=VarNm.GetSubStr(0, FirstColonChN-1);
115  IsComboBox=true;
116  TbNm=VarNm.GetSubStr(FirstColonChN+1, SecondColonChN-1);
117  ListFldNm=VarNm.GetSubStr(SecondColonChN+1, ThirdColonChN-1);
118  if (ThirdColonChN!=VarNm.Len()){
119  DataFldNm=VarNm.GetSubStr(ThirdColonChN+1, VarNm.Len()-1);
120  } else {
121  DataFldNm=ListFldNm;
122  }
123  }
124 }
#define IAssert(Cond)
Definition: bd.h:262
int SearchCh(const char &Ch, const int &BChN=0) const
Definition: dt.cpp:1043
int Len() const
Definition: dt.h:487
TStr GetSubStr(const int &BChN, const int &EChN) const
Definition: dt.cpp:811

Friends And Related Function Documentation

friend class TPt< TMacro >
friend

Definition at line 5 of file macro.h.

Member Data Documentation

TCRef TMacro::CRef
private

Definition at line 5 of file macro.h.

char TMacro::MacroCh

Definition at line 9 of file macro.h.

TStr TMacro::MsgStr

Definition at line 8 of file macro.h.

bool TMacro::Ok

Definition at line 7 of file macro.h.

TStrStrH TMacro::SubstToValStrH

Definition at line 12 of file macro.h.

TStr TMacro::TxtStr

Definition at line 11 of file macro.h.

char TMacro::VarCh

Definition at line 10 of file macro.h.

TStrStrH TMacro::VarNmToValStrH

Definition at line 13 of file macro.h.


The documentation for this class was generated from the following files: