SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TShMIn Class Reference

#include <fl.h>

Inheritance diagram for TShMIn:
Collaboration diagram for TShMIn:

Public Member Functions

 TShMIn (const TStr &Str)
 
 TShMIn (void *_Bf, const TSize &_BfL)
 
 ~TShMIn ()
 
bool Eof ()
 
int Len () const
 
char GetCh ()
 
char * getCursor ()
 
char PeekCh ()
 
void LoadCs ()
 
int GetBf (const void *LBf, const TSize &LBfL)
 
bool GetNextLnBf (TChA &LnChA)
 
void LoadAndAdvance (void *Dest, TSize ElemSize)
 Copy memory into the destination and advance the cursor. More...
 
char * AdvanceCursor (TSize N)
 Return the current pointer and advance the cursor. More...
 
void CloseMapping ()
 munmap the mapping. Note that munmap is not called by the destructor More...
 
- Public Member Functions inherited from TSIn
 TSIn ()
 
 TSIn (const TStr &Str)
 
virtual ~TSIn ()
 
virtual void Reset ()
 
bool IsFastMode () const
 
void SetFastMode (const bool &_FastMode)
 
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
 

Private Attributes

char * OriginalBuffer
 
TSize TotalLength
 
TSize SizeLeft
 
char * Cursor
 
bool IsMemoryMapped
 

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

TShMIn::TShMIn ( const TStr Str)

Definition at line 538 of file fl.cpp.

References TStr::CStr(), Cursor, EAssertR, TStr::Empty(), IsMemoryMapped, OriginalBuffer, SEEK_END, SEEK_SET, SizeLeft, TExcept::Throw(), and TotalLength.

538  : TSBase("Input-Shared_Memory"),
539  TSIn("Input-Shared_Memory"), TotalLength(0),
540  SizeLeft(0) {
541 
542 #ifdef GLib_LINUX
543  TStr FNm = Str;
544  TFileId FileId;
545  int fd;
546  uint64 FLen;
547  EAssertR(!FNm.Empty(), "Empty file-name.");
548  FileId=fopen(FNm.CStr(), "rb");
549  fd = fileno(FileId);
550  EAssertR(FileId!=NULL, "Can not open file '"+FNm+"'.");
551  EAssertR(
552  fseek(FileId, 0, SEEK_END)==0,
553  "Error seeking into file '"+TStr(FNm)+"'.");
554  FLen=(uint64)ftell(FileId);
555  EAssertR(
556  fseek(FileId, 0, SEEK_SET)==0,
557  "Error seeking into file '"+TStr(FNm)+"'.");
558  char *Mapped;
559  Mapped = (char *) mmap (0, FLen, PROT_READ, MAP_PRIVATE, fd, 0);
560  EAssertR(Mapped!=MAP_FAILED, "mmap failed in TShMIn.");
561  OriginalBuffer = Mapped;
563  SizeLeft = FLen;
564  TotalLength = FLen;
565  IsMemoryMapped = true;
566 #else
567  TExcept::Throw("TMIn::TMIn(TStr, Bool): GLib_LINUX undefined.\n");
568 #endif
569  }
TSBase(const TSStr &Nm)
Definition: fl.h:50
bool IsMemoryMapped
Definition: fl.h:390
#define SEEK_END
Definition: fl.cpp:969
#define SEEK_SET
Definition: fl.cpp:970
char * Cursor
Definition: fl.h:389
TSize SizeLeft
Definition: fl.h:388
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
unsigned long long uint64
Definition: bd.h:38
TSIn()
Definition: fl.h:65
Definition: dt.h:412
bool Empty() const
Definition: dt.h:491
FILE * TFileId
Definition: bd.h:17
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * CStr()
Definition: dt.h:479
TSize TotalLength
Definition: fl.h:387
char * OriginalBuffer
Definition: fl.h:386

Here is the call graph for this function:

TShMIn::TShMIn ( void *  _Bf,
const TSize _BfL 
)

Definition at line 571 of file fl.cpp.

References Cursor, and OriginalBuffer.

571  : TSBase("Input-Shared_Memory"),
572  TSIn("Input-Shared_Memory"), TotalLength(_BfL), SizeLeft(_BfL), IsMemoryMapped(false) {
573  OriginalBuffer = (char*)_Bf;
574  Cursor = (char*)_Bf;
575  }
TSBase(const TSStr &Nm)
Definition: fl.h:50
bool IsMemoryMapped
Definition: fl.h:390
char * Cursor
Definition: fl.h:389
TSize SizeLeft
Definition: fl.h:388
TSIn()
Definition: fl.h:65
TSize TotalLength
Definition: fl.h:387
char * OriginalBuffer
Definition: fl.h:386
TShMIn::~TShMIn ( )
inline

Definition at line 394 of file fl.h.

394 {}

Member Function Documentation

char* TShMIn::AdvanceCursor ( TSize  N)
inline

Return the current pointer and advance the cursor.

Definition at line 425 of file fl.h.

References Cursor.

Referenced by LoadAndAdvance(), TBigStrPool::LoadPoolShM(), and TVec< TVal, TSizeTy >::LoadShM().

425  {
426  char* TempCursor = Cursor;
427  Cursor += N;
428  SizeLeft -= N;
429  return TempCursor;
430  }
char * Cursor
Definition: fl.h:389
TSize SizeLeft
Definition: fl.h:388

Here is the caller graph for this function:

void TShMIn::CloseMapping ( )

munmap the mapping. Note that munmap is not called by the destructor

Definition at line 577 of file fl.cpp.

References Cursor, IsMemoryMapped, OriginalBuffer, SizeLeft, and TotalLength.

577  {
578  if (OriginalBuffer!=NULL){
579  if (IsMemoryMapped) {
580 #ifdef GLib_LINUX
581  munmap(OriginalBuffer, TotalLength);
582  IsMemoryMapped = false;
583  OriginalBuffer = NULL;
584  Cursor = NULL;
585  TotalLength= 0;
586  SizeLeft = 0;
587 #endif
588  }
589  }
590 }
bool IsMemoryMapped
Definition: fl.h:390
char * Cursor
Definition: fl.h:389
TSize SizeLeft
Definition: fl.h:388
TSize TotalLength
Definition: fl.h:387
char * OriginalBuffer
Definition: fl.h:386
bool TShMIn::Eof ( )
inlinevirtual

Implements TSIn.

Definition at line 395 of file fl.h.

395 { return SizeLeft<=0; }
TSize SizeLeft
Definition: fl.h:388
int TShMIn::GetBf ( const void *  LBf,
const TSize LBfL 
)
inlinevirtual

Implements TSIn.

Definition at line 412 of file fl.h.

References LoadAndAdvance().

Referenced by LoadCs().

412  {
413  LoadAndAdvance((char*)LBf, LBfL);
414  return 0;
415  }
void LoadAndAdvance(void *Dest, TSize ElemSize)
Copy memory into the destination and advance the cursor.
Definition: fl.h:420

Here is the call graph for this function:

Here is the caller graph for this function:

char TShMIn::GetCh ( )
inlinevirtual

Implements TSIn.

Definition at line 397 of file fl.h.

References LoadAndAdvance().

397  {
398  char c;
399  LoadAndAdvance(&c, sizeof(c));
400  return c;
401  }
void LoadAndAdvance(void *Dest, TSize ElemSize)
Copy memory into the destination and advance the cursor.
Definition: fl.h:420

Here is the call graph for this function:

char* TShMIn::getCursor ( )
inline

Definition at line 402 of file fl.h.

References Cursor.

402  {
403  return Cursor;
404  }
char * Cursor
Definition: fl.h:389
bool TShMIn::GetNextLnBf ( TChA LnChA)
inlinevirtual

Implements TSIn.

Definition at line 416 of file fl.h.

416  {
417  return false;
418  }
int TShMIn::Len ( ) const
inlinevirtual

Implements TSIn.

Definition at line 396 of file fl.h.

References TotalLength.

396 { return TotalLength; }
TSize TotalLength
Definition: fl.h:387
void TShMIn::LoadAndAdvance ( void *  Dest,
TSize  ElemSize 
)
inline

Copy memory into the destination and advance the cursor.

Definition at line 420 of file fl.h.

References AdvanceCursor().

Referenced by GetBf(), and GetCh().

420  {
421  memcpy(Dest, Cursor, ElemSize);
422  AdvanceCursor(ElemSize);
423  }
char * AdvanceCursor(TSize N)
Return the current pointer and advance the cursor.
Definition: fl.h:425
char * Cursor
Definition: fl.h:389

Here is the call graph for this function:

Here is the caller graph for this function:

void TShMIn::LoadCs ( )
inlinevirtual

Reimplemented from TSIn.

Definition at line 408 of file fl.h.

References GetBf().

Referenced by TBigStrPool::LoadPoolShM(), THash< TPair, THash >::LoadShM(), and TStrHash< TInt, TBigStrPool >::LoadShM().

408  {
409  TCs TestCs;
410  GetBf(&TestCs, sizeof(TestCs));
411  }
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.h:412
Definition: fl.h:11

Here is the call graph for this function:

Here is the caller graph for this function:

char TShMIn::PeekCh ( )
inlinevirtual

Implements TSIn.

Definition at line 405 of file fl.h.

405  {
406  return ((char*)Cursor)[0];
407  }
char * Cursor
Definition: fl.h:389

Member Data Documentation

char* TShMIn::Cursor
private

Definition at line 389 of file fl.h.

Referenced by AdvanceCursor(), CloseMapping(), getCursor(), and TShMIn().

bool TShMIn::IsMemoryMapped
private

Definition at line 390 of file fl.h.

Referenced by CloseMapping(), and TShMIn().

char* TShMIn::OriginalBuffer
private

Definition at line 386 of file fl.h.

Referenced by CloseMapping(), and TShMIn().

TSize TShMIn::SizeLeft
private

Definition at line 388 of file fl.h.

Referenced by CloseMapping(), and TShMIn().

TSize TShMIn::TotalLength
private

Definition at line 387 of file fl.h.

Referenced by CloseMapping(), Len(), and TShMIn().


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