CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::binary_ifstream ( const char *  name)
explicit

Definition at line 8 of file binary_ifstream.cc.

References init().

8 : file_(nullptr) { init(name); }
void init(const char *name)
binary_ifstream::binary_ifstream ( const std::string &  name)
explicit

Definition at line 10 of file binary_ifstream.cc.

References init().

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

Definition at line 20 of file binary_ifstream.cc.

References close().

20 { close(); }

Member Function Documentation

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
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 }
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_); }
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; }
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
void binary_ifstream::init ( const char *  name)
private

Definition at line 12 of file binary_ifstream.cc.

References gather_cfg::cout, and file_.

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 }
tuple cout
Definition: gather_cfg.py:144
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
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 bad() const
bool eof() const
bool fail() const
binary_ifstream & binary_ifstream::operator>> ( char &  n)

Definition at line 27 of file binary_ifstream.cc.

References file_.

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

Definition at line 32 of file binary_ifstream.cc.

References file_.

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

Definition at line 37 of file binary_ifstream.cc.

References file_.

37  {
38  fread(&n, sizeof(n), 1, file_);
39  return *this;
40 }
binary_ifstream & binary_ifstream::operator>> ( unsigned short &  n)

Definition at line 41 of file binary_ifstream.cc.

References file_.

41  {
42  fread(&n, sizeof(n), 1, file_);
43  return *this;
44 }
binary_ifstream & binary_ifstream::operator>> ( int &  n)

Definition at line 45 of file binary_ifstream.cc.

References file_.

45  {
46  fread(&n, sizeof(n), 1, file_);
47  return *this;
48 }
binary_ifstream & binary_ifstream::operator>> ( unsigned int &  n)

Definition at line 49 of file binary_ifstream.cc.

References file_.

49  {
50  fread(&n, sizeof(n), 1, file_);
51  return *this;
52 }
binary_ifstream & binary_ifstream::operator>> ( long &  n)

Definition at line 54 of file binary_ifstream.cc.

References file_.

54  {
55  fread(&n, sizeof(n), 1, file_);
56  return *this;
57 }
binary_ifstream & binary_ifstream::operator>> ( unsigned long &  n)

Definition at line 58 of file binary_ifstream.cc.

References file_.

58  {
59  fread(&n, sizeof(n), 1, file_);
60  return *this;
61 }
binary_ifstream & binary_ifstream::operator>> ( float &  n)

Definition at line 63 of file binary_ifstream.cc.

References file_.

63  {
64  fread(&n, sizeof(n), 1, file_);
65  return *this;
66 }
binary_ifstream & binary_ifstream::operator>> ( double &  n)

Definition at line 67 of file binary_ifstream.cc.

References file_.

67  {
68  fread(&n, sizeof(n), 1, file_);
69  return *this;
70 }
binary_ifstream & binary_ifstream::operator>> ( bool &  n)

Definition at line 72 of file binary_ifstream.cc.

References file_.

72  {
73  n = static_cast<bool>(fgetc(file_));
74  return *this;
75 }
binary_ifstream & binary_ifstream::operator>> ( std::string &  n)

Definition at line 77 of file binary_ifstream.cc.

References gather_cfg::cout, file_, 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 }
tuple cout
Definition: gather_cfg.py:144
tmp
align.sh
Definition: createJobs.py:716

Member Data Documentation

FILE* binary_ifstream::file_
private

Definition at line 44 of file binary_ifstream.h.

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