SNAP Library 3.0, User Reference  2016-07-20 17:56:49
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>

Inherits TSIn.

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)
 
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 384 of file fl.h.

Constructor & Destructor Documentation

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

Definition at line 538 of file fl.cpp.

538  :
539  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(_BfL), IsMemoryMapped(false){
540  if (TakeBf){
541  Bf=(char*)_Bf;
542  } else {
543  Bf=new char[static_cast<size_t>(BfL)]; memmove(Bf, _Bf, static_cast<size_t>(BfL));
544  }
545 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
bool IsMemoryMapped
Definition: fl.h:388
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:387
TMIn::TMIn ( TSIn SIn)

Definition at line 547 of file fl.cpp.

547  :
548  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
549  BfL=SIn.Len(); Bf=new char[static_cast<size_t>(BfL)];
550  for (uint64 BfC=0; BfC<BfL; BfC++){Bf[BfC]=SIn.GetCh();}
551 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
char * Bf
Definition: fl.h:386
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:387
bool IsMemoryMapped
Definition: fl.h:388
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:387
virtual char GetCh()=0
virtual int Len() const =0
TMIn::TMIn ( const char *  CStr)

Definition at line 553 of file fl.cpp.

553  :
554  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
555  BfL=uint64(strlen(CStr)); Bf=new char[static_cast<size_t>(BfL+1)]; strcpy(Bf, CStr);
556 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
char * Bf
Definition: fl.h:386
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:387
bool IsMemoryMapped
Definition: fl.h:388
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:387
TMIn::TMIn ( const TStr Str,
bool  FromFile 
)

first parameter is either used as character array or file name

Definition at line 559 of file fl.cpp.

559  :
560  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0){
561  if (FromFile == false) {
562  BfL=Str.Len(); Bf=new char[static_cast<size_t>(BfL)]; strncpy(Bf, Str.CStr(), static_cast<size_t>(BfL));
563  IsMemoryMapped = false;
564  }
565  else {
566 #ifdef GLib_LINUX
567  TStr FNm = Str;
568  TFileId FileId;
569  int fd;
570  uint64 FLen;
571  EAssertR(!FNm.Empty(), "Empty file-name.");
572  FileId=fopen(FNm.CStr(), "rb");
573  fd = fileno(FileId);
574 
575  EAssertR(FileId!=NULL, "Can not open file '"+FNm+"'.");
576 
577  EAssertR(
578  fseek(FileId, 0, SEEK_END)==0,
579  "Error seeking into file '"+TStr(FNm)+"'.");
580  FLen=(uint64)ftell(FileId);
581  EAssertR(
582  fseek(FileId, 0, SEEK_SET)==0,
583  "Error seeking into file '"+TStr(FNm)+"'.");
584 
585  // memory map contents of file
586  char *mapped;
587  mapped = (char *) mmap (0, FLen, PROT_READ, MAP_PRIVATE, fd, 0);
588  IsMemoryMapped = true;
589 
590  if (mapped == MAP_FAILED) {
591  printf("mmap failed: %d %s\n", fd, strerror (errno));
592  Bf = NULL;
593  BfC = BfL = 0;
594  }
595  else {
596  Bf = mapped;
597  BfC = 0;
598  BfL = FLen;
599  }
600  IsMemoryMapped = true;
601 #else
602  TExcept::Throw("TMIn::TMIn(TStr, Bool): GLib_LINUX undefined.\n");
603 #endif
604  }
605 }
int Len() const
Definition: dt.h:487
TSBase(const TSStr &Nm)
Definition: fl.h:50
#define SEEK_END
Definition: fl.cpp:913
#define SEEK_SET
Definition: fl.cpp:914
char * Bf
Definition: fl.h:386
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:387
bool IsMemoryMapped
Definition: fl.h:388
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:387
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * CStr()
Definition: dt.h:476
TMIn::TMIn ( const TChA ChA)

Definition at line 607 of file fl.cpp.

607  :
608  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
609  BfL=ChA.Len(); Bf=new char[static_cast<size_t>(BfL)]; strncpy(Bf, ChA.CStr(), static_cast<size_t>(BfL));
610 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
int Len() const
Definition: dt.h:259
char * Bf
Definition: fl.h:386
char * CStr()
Definition: dt.h:255
uint64 BfL
Definition: fl.h:387
bool IsMemoryMapped
Definition: fl.h:388
TSIn()
Definition: fl.h:65
uint64 BfC
Definition: fl.h:387
TMIn::~TMIn ( )

Definition at line 632 of file fl.cpp.

632  {
633  if (Bf!=NULL){
634  if (IsMemoryMapped) {
635 #ifdef GLib_LINUX
636  munmap(Bf, BfL);
637 #endif
638  }
639  else {
640  delete[] Bf;
641  }
642  }
643 }
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
bool IsMemoryMapped
Definition: fl.h:388

Member Function Documentation

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

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

Definition at line 726 of file fl.cpp.

726  {
727  uint64 Cnt = 0;
728  if (Lb >= BfL) {
729  return 0;
730  }
731  for (uint64 i = Lb; i < Ub; i++) {
732  if (Bf[i] == '\n') {
733  Cnt += 1;
734  }
735  }
736  return Cnt;
737 }
char * Bf
Definition: fl.h:386
unsigned long long uint64
Definition: bd.h:38
uint64 BfL
Definition: fl.h:387
bool TMIn::Eof ( )
inlinevirtual

Implements TSIn.

Definition at line 411 of file fl.h.

411 {return BfC==BfL;}
uint64 BfL
Definition: fl.h:387
uint64 BfC
Definition: fl.h:387
int TMIn::FindEol ( uint64 BfN,
bool &  CrEnd 
)
private

Definition at line 669 of file fl.cpp.

669  {
670  char Ch;
671  if (BfC >= BfL) {
672  // read more data, check for eof
673  if (Eof()) {
674  return -1;
675  }
676  if (CrEnd && Bf[BfC]=='\n') {
677  BfC++;
678  BfN = BfC-1;
679  return 1;
680  }
681  }
682 
683  CrEnd = false;
684  while (BfC < BfL) {
685  Ch = Bf[BfC++];
686  if (Ch=='\n') {
687  BfN = BfC-1;
688  return 1;
689  }
690  if (Ch=='\r') {
691  if (BfC == BfL) {
692  CrEnd = true;
693  BfN = BfC-1;
694  return 0;
695  } else if (Bf[BfC]=='\n') {
696  BfC++;
697  BfN = BfC-2;
698  return 1;
699  }
700  }
701  }
702  BfN = BfC;
703 
704  return 0;
705 }
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
bool Eof()
Definition: fl.h:411
uint64 BfC
Definition: fl.h:387
int TMIn::GetBf ( const void *  LBf,
const TSize LBfL 
)
virtual

Implements TSIn.

Definition at line 655 of file fl.cpp.

655  {
656  EAssertR(TSize(BfC+LBfL)<=TSize(BfL), "Reading beyond the end of stream.");
657  int LBfS=0;
658  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
659  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
660  return LBfS;
661 }
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
size_t TSize
Definition: bd.h:58
uint64 BfC
Definition: fl.h:387
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char* TMIn::GetBfAddr ( )
inline

Definition at line 433 of file fl.h.

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

Definition at line 713 of file fl.cpp.

713  {
714  return BfC;
715 }
uint64 BfC
Definition: fl.h:387
uint64 TMIn::GetBfL ( )

Definition at line 717 of file fl.cpp.

717  {
718  return BfL;
719 }
uint64 BfL
Definition: fl.h:387
char TMIn::GetCh ( )
virtual

Implements TSIn.

Definition at line 645 of file fl.cpp.

645  {
646  EAssertR(BfC<BfL, "Reading beyond the end of stream.");
647  return Bf[BfC++];
648 }
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
uint64 BfC
Definition: fl.h:387
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * TMIn::GetLine ( uint64  Ind)

Definition at line 754 of file fl.cpp.

754  {
755  return &Bf[Index];
756 }
char * Bf
Definition: fl.h:386
uint64 TMIn::GetLineEndPos ( uint64  Ind)

Finds end of line in which Ind is present.

Definition at line 746 of file fl.cpp.

746  {
747  while (Ind < BfL && Bf[Ind] != '\n') {
748  Ind++;
749  }
750  if (Ind == BfL) Ind--;
751  return Ind;
752 }
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
uint64 TMIn::GetLineStartPos ( uint64  Ind)

Finds beginning of line in which Ind is present.

Definition at line 739 of file fl.cpp.

739  {
740  while (Ind > 0 && Bf[Ind-1] != '\n') {
741  Ind--;
742  }
743  return Ind;
744 }
char * Bf
Definition: fl.h:386
bool TMIn::GetNextLnBf ( TChA LnChA)
virtual

Implements TSIn.

Definition at line 707 of file fl.cpp.

707  {
708  // not implemented
709  FailR(TStr::Fmt("TMIn::GetNextLnBf: not implemented").CStr());
710  return false;
711 }
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
int TMIn::Len ( ) const
inlinevirtual

Implements TSIn.

Definition at line 412 of file fl.h.

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

Definition at line 612 of file fl.cpp.

612  {
613  return PSIn(new TMIn(_Bf, _BfL, TakeBf));
614 }
TPt< TSIn > PSIn
Definition: fl.h:119
PSIn TMIn::New ( const char *  CStr)
static

Definition at line 616 of file fl.cpp.

616  {
617  return PSIn(new TMIn(CStr));
618 }
TPt< TSIn > PSIn
Definition: fl.h:119
PSIn TMIn::New ( const TStr Str)
static

Definition at line 620 of file fl.cpp.

620  {
621  return PSIn(new TMIn(Str));
622 }
TPt< TSIn > PSIn
Definition: fl.h:119
PSIn TMIn::New ( const TChA ChA)
static

Definition at line 628 of file fl.cpp.

628  {
629  return PSIn(new TMIn(ChA));
630 }
TPt< TSIn > PSIn
Definition: fl.h:119
PMIn TMIn::New ( const TStr Str,
bool  FromFile 
)
static

Definition at line 624 of file fl.cpp.

624  {
625  return new TMIn(Str, FromFile);
626 }
TMIn& TMIn::operator= ( const TMIn )
private
char TMIn::PeekCh ( )
virtual

Implements TSIn.

Definition at line 650 of file fl.cpp.

650  {
651  EAssertR(BfC<BfL, "Reading beyond the end of stream.");
652  return Bf[BfC];
653 }
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
uint64 BfC
Definition: fl.h:387
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
void TMIn::Reset ( )
inlinevirtual

Reimplemented from TSIn.

Definition at line 416 of file fl.h.

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

Definition at line 721 of file fl.cpp.

721  {
722  BfC = Pos;
723 }
uint64 BfC
Definition: fl.h:387
void TMIn::SkipCommentLines ( )

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

Definition at line 758 of file fl.cpp.

758  {
759  while (BfC < BfL && TCh::IsHashCh(Bf[BfC])) {
760  while (BfC < BfL && Bf[BfC] != '\n') {
761  BfC++;
762  }
763  BfC++;
764  }
765 }
static bool IsHashCh(const char &Ch)
Definition: dt.h:968
char * Bf
Definition: fl.h:386
uint64 BfL
Definition: fl.h:387
uint64 BfC
Definition: fl.h:387

Friends And Related Function Documentation

friend class TPt< TMIn >
friend

Definition at line 435 of file fl.h.

Member Data Documentation

char* TMIn::Bf
private

Definition at line 386 of file fl.h.

uint64 TMIn::BfC
private

Definition at line 387 of file fl.h.

uint64 TMIn::BfL
private

Definition at line 387 of file fl.h.

bool TMIn::IsMemoryMapped
private

Definition at line 388 of file fl.h.


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