SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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
TMIn Class Reference

#include <fl.h>

Inheritance diagram for TMIn:
Collaboration diagram for TMIn:

Public Member Functions

 TMIn (const void *_Bf, const uint64 &_BfL, const bool &TakeBf=false)
 
 TMIn (TSIn &SIn)
 
 TMIn (const char *CStr)
 
 TMIn (const TStr &Str, bool FromFile)
 first parameter is either used as character array or file name More...
 
 TMIn (const TChA &ChA)
 
 ~TMIn ()
 
bool Eof ()
 
int Len () const
 
char GetCh ()
 
char PeekCh ()
 
int GetBf (const void *LBf, const TSize &LBfL)
 
void Reset ()
 
bool GetNextLnBf (TChA &LnChA)
 
uint64 GetBfC ()
 
uint64 GetBfL ()
 
void SetBfC (uint64 Pos)
 
uint64 CountNewLinesInRange (uint64 Lb, uint64 Ub)
 Finds number of new line chars in interval [Lb, Ub) More...
 
uint64 GetLineStartPos (uint64 Ind)
 Finds beginning of line in which Ind is present. More...
 
uint64 GetLineEndPos (uint64 Ind)
 Finds end of line in which Ind is present. More...
 
char * GetLine (uint64 Ind)
 
void SkipCommentLines ()
 Move stream pointer along until a non commented line is found. More...
 
char * GetBfAddr ()
 
- Public Member Functions inherited from TSIn
 TSIn ()
 
 TSIn (const TStr &Str)
 
virtual ~TSIn ()
 
bool IsFastMode () const
 
void SetFastMode (const bool &_FastMode)
 
virtual void LoadCs ()
 
void LoadBf (const void *Bf, const TSize &BfL)
 
void * LoadNewBf (const int &BfL)
 
void Load (bool &Bool)
 
void Load (uchar &UCh)
 
void Load (char &Ch)
 
void Load (short &Short)
 
void Load (ushort &UShort)
 
void Load (int &Int)
 
void Load (uint &UInt)
 
void Load (int64 &Int)
 
void Load (uint64 &UInt)
 
void Load (double &Flt)
 
void Load (sdouble &SFlt)
 
void Load (ldouble &LFlt)
 
void Load (char *&CStr, const int &MxCStrLen, const int &CStrLen)
 
void Load (char *&CStr)
 
TSInoperator>> (bool &Bool)
 
TSInoperator>> (uchar &UCh)
 
TSInoperator>> (char &Ch)
 
TSInoperator>> (short &Sh)
 
TSInoperator>> (ushort &USh)
 
TSInoperator>> (int &Int)
 
TSInoperator>> (uint &UInt)
 
TSInoperator>> (int64 &Int)
 
TSInoperator>> (uint64 &UInt)
 
TSInoperator>> (float &Flt)
 
TSInoperator>> (double &Double)
 
TSInoperator>> (long double &LDouble)
 
bool GetNextLn (TStr &LnStr)
 
bool GetNextLn (TChA &LnChA)
 
- Public Member Functions inherited from TSBase
 TSBase (const TSStr &Nm)
 
virtual ~TSBase ()
 
virtual TStr GetSNm () const
 

Static Public Member Functions

static PSIn New (const void *_Bf, const uint64 &_BfL, const bool &TakeBf=false)
 
static PSIn New (const char *CStr)
 
static PSIn New (const TStr &Str)
 
static PSIn New (const TChA &ChA)
 
static TPt< TMInNew (const TStr &Str, bool FromFile)
 

Private Member Functions

 TMIn ()
 
 TMIn (const TMIn &)
 
TMInoperator= (const TMIn &)
 
int FindEol (uint64 &BfN, bool &CrEnd)
 

Private Attributes

char * Bf
 
uint64 BfC
 
uint64 BfL
 
bool IsMemoryMapped
 

Friends

class TPt< TMIn >
 

Additional Inherited Members

- Static Public Attributes inherited from TSIn
static const TPt< TSInStdIn =PSIn(new TStdIn())
 
- Protected Attributes inherited from TSBase
TCRef CRef
 
TSStr SNm
 
TCs Cs
 

Detailed Description

Definition at line 437 of file fl.h.

Constructor & Destructor Documentation

TMIn::TMIn ( )
private

Referenced by New().

Here is the caller graph for this function:

TMIn::TMIn ( const TMIn )
private
TMIn::TMIn ( const void *  _Bf,
const uint64 _BfL,
const bool &  TakeBf = false 
)

Definition at line 594 of file fl.cpp.

References Bf, and BfL.

594  :
595  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(_BfL), IsMemoryMapped(false){
596  if (TakeBf){
597  Bf=(char*)_Bf;
598  } else {
599  Bf=new char[static_cast<size_t>(BfL)]; memmove(Bf, _Bf, static_cast<size_t>(BfL));
600  }
601 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440
bool IsMemoryMapped
Definition: fl.h:441
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:440
TMIn::TMIn ( TSIn SIn)

Definition at line 603 of file fl.cpp.

References Bf, BfC, BfL, TSIn::GetCh(), and TSIn::Len().

603  :
604  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
605  BfL=SIn.Len(); Bf=new char[static_cast<size_t>(BfL)];
606  for (uint64 BfC=0; BfC<BfL; BfC++){Bf[BfC]=SIn.GetCh();}
607 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
char * Bf
Definition: fl.h:439
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:440
bool IsMemoryMapped
Definition: fl.h:441
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:440
virtual char GetCh()=0
virtual int Len() const =0

Here is the call graph for this function:

TMIn::TMIn ( const char *  CStr)

Definition at line 609 of file fl.cpp.

References Bf, and BfL.

609  :
610  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
611  BfL=uint64(strlen(CStr)); Bf=new char[static_cast<size_t>(BfL+1)]; strcpy(Bf, CStr);
612 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
char * Bf
Definition: fl.h:439
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:440
bool IsMemoryMapped
Definition: fl.h:441
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:440
TMIn::TMIn ( const TStr Str,
bool  FromFile 
)

first parameter is either used as character array or file name

Definition at line 615 of file fl.cpp.

References Bf, BfC, BfL, TStr::CStr(), EAssertR, TStr::Empty(), IsMemoryMapped, TStr::Len(), SEEK_END, SEEK_SET, and TExcept::Throw().

615  :
616  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0){
617  if (FromFile == false) {
618  BfL=Str.Len(); Bf=new char[static_cast<size_t>(BfL)]; strncpy(Bf, Str.CStr(), static_cast<size_t>(BfL));
619  IsMemoryMapped = false;
620  }
621  else {
622 #ifdef GLib_LINUX
623  TStr FNm = Str;
624  TFileId FileId;
625  int fd;
626  uint64 FLen;
627  EAssertR(!FNm.Empty(), "Empty file-name.");
628  FileId=fopen(FNm.CStr(), "rb");
629  fd = fileno(FileId);
630 
631  EAssertR(FileId!=NULL, "Can not open file '"+FNm+"'.");
632 
633  EAssertR(
634  fseek(FileId, 0, SEEK_END)==0,
635  "Error seeking into file '"+TStr(FNm)+"'.");
636  FLen=(uint64)ftell(FileId);
637  EAssertR(
638  fseek(FileId, 0, SEEK_SET)==0,
639  "Error seeking into file '"+TStr(FNm)+"'.");
640 
641  // memory map contents of file
642  char *mapped;
643  mapped = (char *) mmap (0, FLen, PROT_READ, MAP_PRIVATE, fd, 0);
644  IsMemoryMapped = true;
645 
646  if (mapped == MAP_FAILED) {
647  printf("mmap failed: %d %s\n", fd, strerror (errno));
648  Bf = NULL;
649  BfC = BfL = 0;
650  }
651  else {
652  Bf = mapped;
653  BfC = 0;
654  BfL = FLen;
655  }
656  IsMemoryMapped = true;
657 #else
658  TExcept::Throw("TMIn::TMIn(TStr, Bool): GLib_LINUX undefined.\n");
659 #endif
660  }
661 }
int Len() const
Definition: dt.h:487
TSBase(const TSStr &Nm)
Definition: fl.h:50
#define SEEK_END
Definition: fl.cpp:969
#define SEEK_SET
Definition: fl.cpp:970
char * Bf
Definition: fl.h:439
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:440
bool IsMemoryMapped
Definition: fl.h:441
TSIn()
Definition: fl.h:65
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
FILE * TFileId
Definition: bd.h:17
uint64 BfC
Definition: fl.h:440
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * CStr()
Definition: dt.h:476

Here is the call graph for this function:

TMIn::TMIn ( const TChA ChA)

Definition at line 663 of file fl.cpp.

References Bf, BfL, TChA::CStr(), and TChA::Len().

663  :
664  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
665  BfL=ChA.Len(); Bf=new char[static_cast<size_t>(BfL)]; strncpy(Bf, ChA.CStr(), static_cast<size_t>(BfL));
666 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
int Len() const
Definition: dt.h:259
char * Bf
Definition: fl.h:439
char * CStr()
Definition: dt.h:255
uint64 BfL
Definition: fl.h:440
bool IsMemoryMapped
Definition: fl.h:441
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:440

Here is the call graph for this function:

TMIn::~TMIn ( )

Definition at line 688 of file fl.cpp.

References Bf, BfL, and IsMemoryMapped.

688  {
689  if (Bf!=NULL){
690  if (IsMemoryMapped) {
691 #ifdef GLib_LINUX
692  munmap(Bf, BfL);
693 #endif
694  }
695  else {
696  delete[] Bf;
697  }
698  }
699 }
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440
bool IsMemoryMapped
Definition: fl.h:441

Member Function Documentation

uint64 TMIn::CountNewLinesInRange ( uint64  Lb,
uint64  Ub 
)

Finds number of new line chars in interval [Lb, Ub)

Definition at line 782 of file fl.cpp.

References Bf, and BfL.

Referenced by TSsParserMP::CountNewLinesInRange().

782  {
783  uint64 Cnt = 0;
784  if (Lb >= BfL) {
785  return 0;
786  }
787  for (uint64 i = Lb; i < Ub; i++) {
788  if (Bf[i] == '\n') {
789  Cnt += 1;
790  }
791  }
792  return Cnt;
793 }
char * Bf
Definition: fl.h:439
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:440

Here is the caller graph for this function:

bool TMIn::Eof ( )
inlinevirtual

Implements TSIn.

Definition at line 464 of file fl.h.

References BfC, and BfL.

Referenced by FindEol().

464 {return BfC==BfL;}
uint64 BfL
Definition: fl.h:440
uint64 BfC
Definition: fl.h:440

Here is the caller graph for this function:

int TMIn::FindEol ( uint64 BfN,
bool &  CrEnd 
)
private

Definition at line 725 of file fl.cpp.

References Bf, BfC, BfL, and Eof().

725  {
726  char Ch;
727  if (BfC >= BfL) {
728  // read more data, check for eof
729  if (Eof()) {
730  return -1;
731  }
732  if (CrEnd && Bf[BfC]=='\n') {
733  BfC++;
734  BfN = BfC-1;
735  return 1;
736  }
737  }
738 
739  CrEnd = false;
740  while (BfC < BfL) {
741  Ch = Bf[BfC++];
742  if (Ch=='\n') {
743  BfN = BfC-1;
744  return 1;
745  }
746  if (Ch=='\r') {
747  if (BfC == BfL) {
748  CrEnd = true;
749  BfN = BfC-1;
750  return 0;
751  } else if (Bf[BfC]=='\n') {
752  BfC++;
753  BfN = BfC-2;
754  return 1;
755  }
756  }
757  }
758  BfN = BfC;
759 
760  return 0;
761 }
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440
bool Eof()
Definition: fl.h:464
uint64 BfC
Definition: fl.h:440

Here is the call graph for this function:

int TMIn::GetBf ( const void *  LBf,
const TSize LBfL 
)
virtual

Implements TSIn.

Definition at line 711 of file fl.cpp.

References Bf, BfC, BfL, and EAssertR.

711  {
712  EAssertR(TSize(BfC+LBfL)<=TSize(BfL), "Reading beyond the end of stream.");
713  int LBfS=0;
714  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
715  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
716  return LBfS;
717 }
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440
size_t TSize
Definition: bd.h:58
uint64 BfC
Definition: fl.h:440
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char* TMIn::GetBfAddr ( )
inline

Definition at line 486 of file fl.h.

References Bf.

486 {return Bf;}
char * Bf
Definition: fl.h:439
uint64 TMIn::GetBfC ( )

Definition at line 769 of file fl.cpp.

References BfC.

769  {
770  return BfC;
771 }
uint64 BfC
Definition: fl.h:440
uint64 TMIn::GetBfL ( )

Definition at line 773 of file fl.cpp.

References BfL.

773  {
774  return BfL;
775 }
uint64 BfL
Definition: fl.h:440
char TMIn::GetCh ( )
virtual

Implements TSIn.

Definition at line 701 of file fl.cpp.

References Bf, BfC, BfL, and EAssertR.

701  {
702  EAssertR(BfC<BfL, "Reading beyond the end of stream.");
703  return Bf[BfC++];
704 }
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440
uint64 BfC
Definition: fl.h:440
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * TMIn::GetLine ( uint64  Ind)

Definition at line 810 of file fl.cpp.

References Bf.

Referenced by TSsParserMP::NextFromIndex().

810  {
811  return &Bf[Index];
812 }
char * Bf
Definition: fl.h:439

Here is the caller graph for this function:

uint64 TMIn::GetLineEndPos ( uint64  Ind)

Finds end of line in which Ind is present.

Definition at line 802 of file fl.cpp.

References Bf, and BfL.

Referenced by TSsParserMP::GetStartPosV().

802  {
803  while (Ind < BfL && Bf[Ind] != '\n') {
804  Ind++;
805  }
806  if (Ind == BfL) Ind--;
807  return Ind;
808 }
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440

Here is the caller graph for this function:

uint64 TMIn::GetLineStartPos ( uint64  Ind)

Finds beginning of line in which Ind is present.

Definition at line 795 of file fl.cpp.

References Bf.

Referenced by TSsParserMP::GetStartPosV().

795  {
796  while (Ind > 0 && Bf[Ind-1] != '\n') {
797  Ind--;
798  }
799  return Ind;
800 }
char * Bf
Definition: fl.h:439

Here is the caller graph for this function:

bool TMIn::GetNextLnBf ( TChA LnChA)
virtual

Implements TSIn.

Definition at line 763 of file fl.cpp.

References FailR, and TStr::Fmt().

Referenced by TSsParserMP::Next().

763  {
764  // not implemented
765  FailR(TStr::Fmt("TMIn::GetNextLnBf: not implemented").CStr());
766  return false;
767 }
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599

Here is the call graph for this function:

Here is the caller graph for this function:

int TMIn::Len ( ) const
inlinevirtual

Implements TSIn.

Definition at line 465 of file fl.h.

References BfC, and BfL.

465 {return static_cast<int>(BfL-BfC);}
uint64 BfL
Definition: fl.h:440
uint64 BfC
Definition: fl.h:440
PSIn TMIn::New ( const void *  _Bf,
const uint64 _BfL,
const bool &  TakeBf = false 
)
static

Definition at line 668 of file fl.cpp.

References TMIn().

Referenced by TSsParserMP::TSsParserMP().

668  {
669  return PSIn(new TMIn(_Bf, _BfL, TakeBf));
670 }
TPt< TSIn > PSIn
Definition: fl.h:119

Here is the call graph for this function:

Here is the caller graph for this function:

PSIn TMIn::New ( const char *  CStr)
static

Definition at line 672 of file fl.cpp.

References TMIn().

672  {
673  return PSIn(new TMIn(CStr));
674 }
TPt< TSIn > PSIn
Definition: fl.h:119

Here is the call graph for this function:

PSIn TMIn::New ( const TStr Str)
static

Definition at line 676 of file fl.cpp.

References TMIn().

676  {
677  return PSIn(new TMIn(Str));
678 }
TPt< TSIn > PSIn
Definition: fl.h:119

Here is the call graph for this function:

PSIn TMIn::New ( const TChA ChA)
static

Definition at line 684 of file fl.cpp.

References TMIn().

684  {
685  return PSIn(new TMIn(ChA));
686 }
TPt< TSIn > PSIn
Definition: fl.h:119

Here is the call graph for this function:

PMIn TMIn::New ( const TStr Str,
bool  FromFile 
)
static

Definition at line 680 of file fl.cpp.

References TMIn().

680  {
681  return new TMIn(Str, FromFile);
682 }

Here is the call graph for this function:

TMIn& TMIn::operator= ( const TMIn )
private
char TMIn::PeekCh ( )
virtual

Implements TSIn.

Definition at line 706 of file fl.cpp.

References Bf, BfC, BfL, and EAssertR.

706  {
707  EAssertR(BfC<BfL, "Reading beyond the end of stream.");
708  return Bf[BfC];
709 }
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440
uint64 BfC
Definition: fl.h:440
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
void TMIn::Reset ( )
inlinevirtual

Reimplemented from TSIn.

Definition at line 469 of file fl.h.

References BfC, and TSBase::Cs.

469 {Cs=TCs(); BfC=0;}
uint64 BfC
Definition: fl.h:440
Definition: fl.h:11
TCs Cs
Definition: fl.h:44
void TMIn::SetBfC ( uint64  Pos)

Definition at line 777 of file fl.cpp.

References BfC.

777  {
778  BfC = Pos;
779 }
uint64 BfC
Definition: fl.h:440
void TMIn::SkipCommentLines ( )

Move stream pointer along until a non commented line is found.

Definition at line 814 of file fl.cpp.

References Bf, BfC, BfL, and TCh::IsHashCh().

Referenced by TSsParserMP::SkipCommentLines().

814  {
815  while (BfC < BfL && TCh::IsHashCh(Bf[BfC])) {
816  while (BfC < BfL && Bf[BfC] != '\n') {
817  BfC++;
818  }
819  BfC++;
820  }
821 }
static bool IsHashCh(const char &Ch)
Definition: dt.h:1058
char * Bf
Definition: fl.h:439
uint64 BfL
Definition: fl.h:440
uint64 BfC
Definition: fl.h:440

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class TPt< TMIn >
friend

Definition at line 488 of file fl.h.

Member Data Documentation

char* TMIn::Bf
private
uint64 TMIn::BfC
private

Definition at line 440 of file fl.h.

Referenced by Eof(), FindEol(), GetBf(), GetBfC(), GetCh(), Len(), PeekCh(), Reset(), SetBfC(), SkipCommentLines(), and TMIn().

uint64 TMIn::BfL
private
bool TMIn::IsMemoryMapped
private

Definition at line 441 of file fl.h.

Referenced by TMIn(), and ~TMIn().


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