CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
binary_ifstream Class Reference

#include <binary_ifstream.h>

Public Member Functions

bool bad () const
 
 binary_ifstream (const char *name)
 
 binary_ifstream (const std::string &name)
 
void close ()
 
bool eof () const
 
bool fail () const
 
bool good () const
 stream state checking More...
 
 operator bool () const
 
bool operator! () const
 
binary_ifstreamoperator>> (char &n)
 
binary_ifstreamoperator>> (unsigned char &n)
 
binary_ifstreamoperator>> (short &n)
 
binary_ifstreamoperator>> (unsigned short &n)
 
binary_ifstreamoperator>> (int &n)
 
binary_ifstreamoperator>> (unsigned int &n)
 
binary_ifstreamoperator>> (long &n)
 
binary_ifstreamoperator>> (unsigned long &n)
 
binary_ifstreamoperator>> (float &n)
 
binary_ifstreamoperator>> (double &n)
 
binary_ifstreamoperator>> (bool &n)
 
binary_ifstreamoperator>> (std::string &n)
 
 ~binary_ifstream ()
 

Private Member Functions

void init (const char *name)
 

Private Attributes

FILE * file_
 

Detailed Description

Definition at line 8 of file binary_ifstream.h.

Constructor & Destructor Documentation

◆ binary_ifstream() [1/2]

binary_ifstream::binary_ifstream ( const char *  name)
explicit

Definition at line 8 of file binary_ifstream.cc.

References init(), and Skims_PA_cff::name.

8 : file_(nullptr) { init(name); }
void init(const char *name)

◆ binary_ifstream() [2/2]

binary_ifstream::binary_ifstream ( const std::string &  name)
explicit

Definition at line 10 of file binary_ifstream.cc.

References init(), and Skims_PA_cff::name.

10 : file_(nullptr) { init(name.c_str()); }
void init(const char *name)

◆ ~binary_ifstream()

binary_ifstream::~binary_ifstream ( )

Definition at line 20 of file binary_ifstream.cc.

References close().

20 { close(); }

Member Function Documentation

◆ bad()

bool binary_ifstream::bad ( ) const

Definition at line 96 of file binary_ifstream.cc.

References fail().

Referenced by good(), and operator!().

96 { return fail(); }
bool fail() const

◆ close()

void binary_ifstream::close ( void  )

Definition at line 21 of file binary_ifstream.cc.

References file_.

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), MagneticFieldGrid::load(), and ~binary_ifstream().

21  {
22  if (file_ != nullptr)
23  fclose(file_);
24  file_ = nullptr;
25 }

◆ eof()

bool binary_ifstream::eof ( ) const

Definition at line 91 of file binary_ifstream.cc.

References file_.

Referenced by good(), and operator!().

91 { return feof(file_); }

◆ fail()

bool binary_ifstream::fail ( ) const

Definition at line 93 of file binary_ifstream.cc.

References file_.

Referenced by bad(), and operator!().

93 { return file_ == nullptr || ferror(file_) != 0; }

◆ good()

bool binary_ifstream::good ( ) const

stream state checking

Definition at line 89 of file binary_ifstream.cc.

References bad(), and eof().

89 { return !bad() && !eof(); }
bool bad() const
bool eof() const

◆ init()

void binary_ifstream::init ( const char *  name)
private

Definition at line 12 of file binary_ifstream.cc.

References gather_cfg::cout, file_, and Skims_PA_cff::name.

Referenced by binary_ifstream().

12  {
13  file_ = fopen(name, "rb");
14  if (file_ == nullptr) {
15  std::cout << "file " << name << " cannot be opened for reading" << std::endl;
16  throw binary_ifstream_error();
17  }
18 }

◆ operator bool()

binary_ifstream::operator bool ( ) const

Definition at line 102 of file binary_ifstream.cc.

References good.

102 { return good(); }
bool good() const
stream state checking

◆ operator!()

bool binary_ifstream::operator! ( ) const

Definition at line 98 of file binary_ifstream.cc.

References bad(), eof(), and fail().

98 { return fail() || bad() || eof(); }
bool fail() const
bool bad() const
bool eof() const

◆ operator>>() [1/12]

binary_ifstream & binary_ifstream::operator>> ( char &  n)

Definition at line 27 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

27  {
28  n = static_cast<char>(fgetc(file_));
29  return *this;
30 }

◆ operator>>() [2/12]

binary_ifstream & binary_ifstream::operator>> ( unsigned char &  n)

Definition at line 32 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

32  {
33  n = static_cast<unsigned char>(fgetc(file_));
34  return *this;
35 }

◆ operator>>() [3/12]

binary_ifstream & binary_ifstream::operator>> ( short &  n)

Definition at line 37 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

37  {
38  fread(&n, sizeof(n), 1, file_);
39  return *this;
40 }

◆ operator>>() [4/12]

binary_ifstream & binary_ifstream::operator>> ( unsigned short &  n)

Definition at line 41 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

41  {
42  fread(&n, sizeof(n), 1, file_);
43  return *this;
44 }

◆ operator>>() [5/12]

binary_ifstream & binary_ifstream::operator>> ( int &  n)

Definition at line 45 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

45  {
46  fread(&n, sizeof(n), 1, file_);
47  return *this;
48 }

◆ operator>>() [6/12]

binary_ifstream & binary_ifstream::operator>> ( unsigned int &  n)

Definition at line 49 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

49  {
50  fread(&n, sizeof(n), 1, file_);
51  return *this;
52 }

◆ operator>>() [7/12]

binary_ifstream & binary_ifstream::operator>> ( long &  n)

Definition at line 54 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

54  {
55  fread(&n, sizeof(n), 1, file_);
56  return *this;
57 }

◆ operator>>() [8/12]

binary_ifstream & binary_ifstream::operator>> ( unsigned long &  n)

Definition at line 58 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

58  {
59  fread(&n, sizeof(n), 1, file_);
60  return *this;
61 }

◆ operator>>() [9/12]

binary_ifstream & binary_ifstream::operator>> ( float &  n)

Definition at line 63 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

63  {
64  fread(&n, sizeof(n), 1, file_);
65  return *this;
66 }

◆ operator>>() [10/12]

binary_ifstream & binary_ifstream::operator>> ( double &  n)

Definition at line 67 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

67  {
68  fread(&n, sizeof(n), 1, file_);
69  return *this;
70 }

◆ operator>>() [11/12]

binary_ifstream & binary_ifstream::operator>> ( bool &  n)

Definition at line 72 of file binary_ifstream.cc.

References file_, and dqmiodumpmetadata::n.

72  {
73  n = static_cast<bool>(fgetc(file_));
74  return *this;
75 }

◆ operator>>() [12/12]

binary_ifstream & binary_ifstream::operator>> ( std::string &  n)

Definition at line 77 of file binary_ifstream.cc.

References gather_cfg::cout, file_, dqmiodumpmetadata::n, and createJobs::tmp.

77  {
78  unsigned int nchar;
79  (*this) >> nchar;
80  char* tmp = new char[nchar + 1];
81  unsigned int nread = fread(tmp, 1, nchar, file_);
82  if (nread != nchar)
83  std::cout << "binary_ifstream error: read less then expected " << std::endl;
84  n.assign(tmp, nread);
85  delete[] tmp;
86  return *this;
87 }
tmp
align.sh
Definition: createJobs.py:716

Member Data Documentation

◆ file_

FILE* binary_ifstream::file_
private

Definition at line 44 of file binary_ifstream.h.

Referenced by close(), eof(), fail(), init(), and operator>>().