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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TMacro Class Reference

#include <macro.h>

List of all members.

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.

                                                                           :
  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]

Definition at line 19 of file macro.h.

{}
TMacro::TMacro ( TSIn ) [inline]

Definition at line 20 of file macro.h.

{Fail;}

Member Function Documentation

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;
}

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]

Definition at line 27 of file macro.h.

{return MsgStr;}
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]

Definition at line 29 of file macro.h.

{return TxtStr;}
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

Definition at line 96 of file macro.cpp.

                                          {
  VarNmV.Gen(GetVars(), 0);
  for (int VarN=0; VarN<GetVars(); VarN++){
    VarNmV.Add(GetVarNm(VarN));
  }
}
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]

Definition at line 26 of file macro.h.

{return Ok;}
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]

Definition at line 21 of file macro.h.

{Fail; return NULL;}
static PMacro TMacro::New ( const TStr TxtStr,
const char &  MacroCh = '$',
const char &  VarCh = '#' 
) [inline, static]

Definition at line 16 of file macro.h.

                                                                      {
    return PMacro(new TMacro(TxtStr, MacroCh, VarCh));}
TMacro& TMacro::operator= ( const TMacro ) [inline]

Definition at line 24 of file macro.h.

{Fail; return *this;}
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]

Definition at line 22 of file macro.h.

{Fail;}
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;
    }
  }
}

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.

Definition at line 9 of file macro.h.

Definition at line 8 of file macro.h.

bool TMacro::Ok

Definition at line 7 of file macro.h.

Definition at line 12 of file macro.h.

Definition at line 11 of file macro.h.

Definition at line 10 of file macro.h.

Definition at line 13 of file macro.h.


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