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>> (bool &n)
 
binary_ifstreamoperator>> (char &n)
 
binary_ifstreamoperator>> (double &n)
 
binary_ifstreamoperator>> (float &n)
 
binary_ifstreamoperator>> (int &n)
 
binary_ifstreamoperator>> (long &n)
 
binary_ifstreamoperator>> (short &n)
 
binary_ifstreamoperator>> (std::string &n)
 
binary_ifstreamoperator>> (unsigned char &n)
 
binary_ifstreamoperator>> (unsigned int &n)
 
binary_ifstreamoperator>> (unsigned long &n)
 
binary_ifstreamoperator>> (unsigned short &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.

8 : file_(nullptr) { init(name); }

References init(), and Skims_PA_cff::name.

◆ binary_ifstream() [2/2]

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

Definition at line 10 of file binary_ifstream.cc.

10 : file_(nullptr) { init(name.c_str()); }

References init(), and Skims_PA_cff::name.

◆ ~binary_ifstream()

binary_ifstream::~binary_ifstream ( )

Definition at line 20 of file binary_ifstream.cc.

20 { close(); }

References close().

Member Function Documentation

◆ bad()

bool binary_ifstream::bad ( ) const

Definition at line 96 of file binary_ifstream.cc.

96 { return fail(); }

References fail().

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

◆ close()

void binary_ifstream::close ( void  )

Definition at line 21 of file binary_ifstream.cc.

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

References file_.

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

◆ eof()

bool binary_ifstream::eof ( ) const

Definition at line 91 of file binary_ifstream.cc.

91 { return feof(file_); }

References file_.

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

◆ fail()

bool binary_ifstream::fail ( ) const

Definition at line 93 of file binary_ifstream.cc.

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

References file_.

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

◆ good()

bool binary_ifstream::good ( ) const

stream state checking

Definition at line 89 of file binary_ifstream.cc.

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

References bad(), and eof().

◆ init()

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

Definition at line 12 of file binary_ifstream.cc.

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 }

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

Referenced by binary_ifstream().

◆ operator bool()

binary_ifstream::operator bool ( ) const

Definition at line 102 of file binary_ifstream.cc.

102 { return good(); }

◆ operator!()

bool binary_ifstream::operator! ( ) const

Definition at line 98 of file binary_ifstream.cc.

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

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

◆ operator>>() [1/12]

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

Definition at line 72 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [2/12]

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

Definition at line 27 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [3/12]

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

Definition at line 67 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [4/12]

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

Definition at line 63 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [5/12]

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

Definition at line 45 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [6/12]

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

Definition at line 54 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [7/12]

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

Definition at line 37 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [8/12]

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

Definition at line 77 of file binary_ifstream.cc.

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 }

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

◆ operator>>() [9/12]

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

Definition at line 32 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [10/12]

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

Definition at line 49 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [11/12]

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

Definition at line 58 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator>>() [12/12]

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

Definition at line 41 of file binary_ifstream.cc.

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

References file_, and dqmiodumpmetadata::n.

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>>().

binary_ifstream::good
bool good() const
stream state checking
Definition: binary_ifstream.cc:89
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
gather_cfg.cout
cout
Definition: gather_cfg.py:144
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
binary_ifstream::init
void init(const char *name)
Definition: binary_ifstream.cc:12
binary_ifstream::close
void close()
Definition: binary_ifstream.cc:21
binary_ifstream::eof
bool eof() const
Definition: binary_ifstream.cc:91
binary_ifstream::fail
bool fail() const
Definition: binary_ifstream.cc:93
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
binary_ifstream::file_
FILE * file_
Definition: binary_ifstream.h:44
binary_ifstream_error
Definition: binary_ifstream.cc:6
binary_ifstream::bad
bool bad() const
Definition: binary_ifstream.cc:96