test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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_(0)
9 {
10  init (name);
11 }
void init(const char *name)
binary_ifstream::binary_ifstream ( const std::string &  name)
explicit

Definition at line 13 of file binary_ifstream.cc.

References init().

13  : file_(0)
14 {
15  init (name.c_str());
16 }
void init(const char *name)
binary_ifstream::~binary_ifstream ( )

Definition at line 28 of file binary_ifstream.cc.

References close().

29 {
30  close();
31 }

Member Function Documentation

bool binary_ifstream::bad ( ) const

Definition at line 99 of file binary_ifstream.cc.

References fail().

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

99 {return fail();}
bool fail() const
void binary_ifstream::close ( void  )
bool binary_ifstream::eof ( ) const

Definition at line 88 of file binary_ifstream.cc.

References file_.

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

89 {
90  return feof( file_);
91 }
bool binary_ifstream::fail ( ) const

Definition at line 93 of file binary_ifstream.cc.

References file_.

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

94 {
95  return file_ == 0 || ferror( file_) != 0;
96 }
bool binary_ifstream::good ( ) const

stream state checking

Definition at line 83 of file binary_ifstream.cc.

References bad(), and eof().

84 {
85  return !bad() && !eof();
86 }
bool bad() const
bool eof() const
void binary_ifstream::init ( const char *  name)
private

Definition at line 18 of file binary_ifstream.cc.

References gather_cfg::cout, and file_.

Referenced by binary_ifstream().

19 {
20  file_ = fopen( name, "rb");
21  if (file_ == 0) {
22  std::cout << "file " << name << " cannot be opened for reading"
23  << std::endl;
24  throw binary_ifstream_error();
25  }
26 }
tuple cout
Definition: gather_cfg.py:121
binary_ifstream::operator bool ( ) const

Definition at line 105 of file binary_ifstream.cc.

105  {
106  return good();
107 }
bool good() const
stream state checking
bool binary_ifstream::operator! ( ) const

Definition at line 101 of file binary_ifstream.cc.

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

101 {return fail() || bad() || eof();}
bool bad() const
bool eof() const
bool fail() const
binary_ifstream & binary_ifstream::operator>> ( char &  n)

Definition at line 38 of file binary_ifstream.cc.

References file_.

38  {
39  n = static_cast<char>(fgetc(file_));
40  return *this;
41 }
binary_ifstream & binary_ifstream::operator>> ( unsigned char &  n)

Definition at line 43 of file binary_ifstream.cc.

References file_.

43  {
44  n = static_cast<unsigned char>(fgetc(file_));
45  return *this;
46 }
binary_ifstream & binary_ifstream::operator>> ( short &  n)

Definition at line 48 of file binary_ifstream.cc.

References file_.

48  {
49  fread( &n, sizeof(n), 1, file_); return *this;}
binary_ifstream & binary_ifstream::operator>> ( unsigned short &  n)

Definition at line 50 of file binary_ifstream.cc.

References file_.

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

Definition at line 52 of file binary_ifstream.cc.

References file_.

52  {
53  fread( &n, sizeof(n), 1, file_); return *this;}
binary_ifstream & binary_ifstream::operator>> ( unsigned int &  n)

Definition at line 54 of file binary_ifstream.cc.

References file_.

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

Definition at line 57 of file binary_ifstream.cc.

References file_.

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

Definition at line 59 of file binary_ifstream.cc.

References file_.

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

Definition at line 62 of file binary_ifstream.cc.

References file_.

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

Definition at line 64 of file binary_ifstream.cc.

References file_.

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

Definition at line 67 of file binary_ifstream.cc.

References file_.

67  {
68  n = static_cast<bool>(fgetc(file_));
69  return *this;
70 }
binary_ifstream & binary_ifstream::operator>> ( std::string &  n)

Definition at line 72 of file binary_ifstream.cc.

References gather_cfg::cout, file_, and tmp.

72  {
73  unsigned int nchar;
74  (*this) >> nchar;
75  char* tmp = new char[nchar+1];
76  unsigned int nread = fread( tmp, 1, nchar, file_);
77  if (nread != nchar) std::cout << "binary_ifstream error: read less then expected " << std::endl;
78  n.assign( tmp, nread);
79  delete[] tmp;
80  return *this;
81 }
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple cout
Definition: gather_cfg.py:121

Member Data Documentation

FILE* binary_ifstream::file_
private

Definition at line 46 of file binary_ifstream.h.

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