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

#include <fl.h>

Inherits TSOut.

List of all members.

Public Member Functions

 TMOut (const int &_MxBfL=1024)
 TMOut (char *_Bf, const int &_MxBfL)
 ~TMOut ()
int PutCh (const char &Ch)
int PutBf (const void *LBf, const TSize &LBfL)
void AppendBf (const void *LBf, const TSize &LBfL)
void Flush ()
int Len () const
void Clr ()
char GetCh (const int &ChN) const
TStr GetAsStr () const
void CutBf (const int &CutBfL)
PSIn GetSIn (const bool &IsCut=true, const int &CutBfL=-1)
char * GetBfAddr () const
bool IsCrLfLn () const
TStr GetCrLfLn ()
bool IsEolnLn () const
TStr GetEolnLn (const bool &DoAddEoln, const bool &DoCutBf)
void MkEolnLn ()

Static Public Member Functions

static PSOut New (const int &MxBfL=1024)

Private Member Functions

void Resize (const int &ReqLen=-1)
 TMOut (const TMOut &)
TMOutoperator= (const TMOut &)

Private Attributes

char * Bf
int BfL
int MxBfL
bool OwnBf

Detailed Description

Definition at line 417 of file fl.h.


Constructor & Destructor Documentation

TMOut::TMOut ( const TMOut ) [private]
TMOut::TMOut ( const int &  _MxBfL = 1024)

Definition at line 618 of file fl.cpp.

                             :
  TSBase("Output-Memory"), TSOut("Output-Memory"),
  Bf(NULL), BfL(0), MxBfL(0), OwnBf(true){
  MxBfL=_MxBfL>0?_MxBfL:1024;
  Bf=new char[MxBfL];
}
TMOut::TMOut ( char *  _Bf,
const int &  _MxBfL 
)

Definition at line 625 of file fl.cpp.

                                        :
  TSBase("Output-Memory"), TSOut("Output-Memory"),
  Bf(_Bf), BfL(0), MxBfL(_MxBfL), OwnBf(false){}
TMOut::~TMOut ( ) [inline]

Definition at line 431 of file fl.h.

{if (OwnBf&&(Bf!=NULL)){delete[] Bf;}}

Member Function Documentation

void TMOut::AppendBf ( const void *  LBf,
const TSize LBfL 
)

Definition at line 629 of file fl.cpp.

                                                       {
  Resize(Len() + (int)LBfL);
  memcpy(Bf + BfL, LBf, LBfL);
  BfL += (int)LBfL;
}
void TMOut::Clr ( ) [inline]

Definition at line 440 of file fl.h.

{BfL=0;}
void TMOut::CutBf ( const int &  CutBfL)

Definition at line 653 of file fl.cpp.

                                  {
  IAssert((0<=CutBfL)&&(CutBfL<=BfL));
  if (CutBfL==BfL){BfL=0;}
  else {memmove(Bf, Bf+CutBfL, BfL-CutBfL); BfL=BfL-CutBfL;}
}
void TMOut::Flush ( ) [inline, virtual]

Implements TSOut.

Definition at line 437 of file fl.h.

{}
TStr TMOut::GetAsStr ( ) const

Definition at line 647 of file fl.cpp.

                           {
  TChA ChA(BfL);
  for (int BfC=0; BfC<BfL; BfC++){ChA+=Bf[BfC];}
  return ChA;
}
char* TMOut::GetBfAddr ( ) const [inline]

Definition at line 446 of file fl.h.

{return Bf;}
char TMOut::GetCh ( const int &  ChN) const [inline]

Definition at line 441 of file fl.h.

                                   {
    IAssert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}

Definition at line 679 of file fl.cpp.

                     {
  IAssert(IsCrLfLn());
  TChA Ln;
  for (int BfC=0; BfC<BfL; BfC++){
    char Ch=Bf[BfC];
    if ((Ch==TCh::CrCh)&&((BfC+1<BfL)&&(Bf[BfC+1]==TCh::LfCh))){
      Ln+=TCh::CrCh; Ln+=TCh::LfCh; CutBf(BfC+1+1); break;
    } else {
      Ln+=Ch;
    }
  }
  return Ln;
}
TStr TMOut::GetEolnLn ( const bool &  DoAddEoln,
const bool &  DoCutBf 
)

Definition at line 700 of file fl.cpp.

                                                               {
  IAssert(IsEolnLn());
  int LnChs=0; TChA Ln;
  for (int BfC=0; BfC<BfL; BfC++){
    char Ch=Bf[BfC];
    if ((Ch==TCh::CrCh)||(Ch==TCh::LfCh)){
      LnChs++; if (DoAddEoln){Ln+=Ch;}
      if (BfC+1<BfL){
        char NextCh=Bf[BfC+1];
        if (((Ch==TCh::CrCh)&&(NextCh==TCh::LfCh))||
         ((Ch==TCh::LfCh)&&(NextCh==TCh::CrCh))){
          LnChs++; if (DoAddEoln){Ln+=NextCh;}
        }
      }
      break;
    } else {
      LnChs++; Ln+=Ch;
    }
  }
  if (DoCutBf){
    CutBf(LnChs);
  }
  return Ln;
}
PSIn TMOut::GetSIn ( const bool &  IsCut = true,
const int &  CutBfL = -1 
)

Definition at line 659 of file fl.cpp.

                                                      {
  IAssert((CutBfL==-1)||((0<=CutBfL)));
  int SInBfL= (CutBfL==-1) ? BfL : TInt::GetMn(BfL, CutBfL);
  PSIn SIn;
  if (OwnBf&&IsCut&&(SInBfL==BfL)){
    SIn=PSIn(new TMIn(Bf, SInBfL, true));
    Bf=NULL; BfL=MxBfL=0; OwnBf=true;
  } else {
    SIn=PSIn(new TMIn(Bf, SInBfL, false));
    if (IsCut){CutBf(SInBfL);}
  }
  return SIn;
}
bool TMOut::IsCrLfLn ( ) const

Definition at line 673 of file fl.cpp.

                           {
  for (int BfC=0; BfC<BfL; BfC++){
    if ((Bf[BfC]==TCh::CrCh)&&((BfC+1<BfL)&&(Bf[BfC+1]==TCh::LfCh))){return true;}}
  return false;
}
bool TMOut::IsEolnLn ( ) const

Definition at line 693 of file fl.cpp.

                           {
  for (int BfC=0; BfC<BfL; BfC++){
    if ((Bf[BfC]==TCh::CrCh)||(Bf[BfC]==TCh::LfCh)){return true;}
  }
  return false;
}
int TMOut::Len ( ) const [inline]

Definition at line 439 of file fl.h.

{return BfL;}
void TMOut::MkEolnLn ( )

Definition at line 725 of file fl.cpp.

                    {
  if (!IsEolnLn()){
    PutCh(TCh::CrCh); PutCh(TCh::LfCh);}
}
static PSOut TMOut::New ( const int &  MxBfL = 1024) [inline, static]

Definition at line 428 of file fl.h.

                                         {
    return PSOut(new TMOut(MxBfL));}
TMOut& TMOut::operator= ( const TMOut ) [private]
int TMOut::PutBf ( const void *  LBf,
const TSize LBfL 
) [virtual]

Implements TSOut.

Definition at line 635 of file fl.cpp.

                                                  {
  int LBfS=0;
  if (TSize(BfL+LBfL)>TSize(MxBfL)){
    for (TSize LBfC=0; LBfC<LBfL; LBfC++){
      LBfS+=PutCh(((char*)LBf)[LBfC]);}
  } else {
    for (TSize LBfC=0; LBfC<LBfL; LBfC++){
      LBfS+=(Bf[BfL++]=((char*)LBf)[LBfC]);}
  }
  return LBfS;
}
int TMOut::PutCh ( const char &  Ch) [inline, virtual]

Implements TSOut.

Definition at line 433 of file fl.h.

                           {if (BfL==MxBfL){
    Resize();} return Bf[BfL++]=Ch;}
void TMOut::Resize ( const int &  ReqLen = -1) [private]

Definition at line 603 of file fl.cpp.

                                   {
  IAssert(OwnBf&&(BfL==MxBfL || ReqLen >= 0));
  if (Bf==NULL){
    IAssert(MxBfL==0); 
    if (ReqLen < 0) Bf=new char[MxBfL=1024];
    else Bf=new char[MxBfL=ReqLen];
  } else {
    if (ReqLen < 0){ MxBfL*=2; }
    else if (ReqLen < MxBfL){ return; } // nothing to do 
    else { MxBfL=(2*MxBfL < ReqLen ? ReqLen : 2*MxBfL); }
    char* NewBf=new char[MxBfL];
    memmove(NewBf, Bf, BfL); delete[] Bf; Bf=NewBf;
  }
}

Member Data Documentation

char* TMOut::Bf [private]

Definition at line 419 of file fl.h.

int TMOut::BfL [private]

Definition at line 420 of file fl.h.

int TMOut::MxBfL [private]

Definition at line 420 of file fl.h.

bool TMOut::OwnBf [private]

Definition at line 421 of file fl.h.


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