CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

binary_ifstream Class Reference

#include <binary_ifstream.h>

List of all members.

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
 operator bool () const
bool operator! () const
binary_ifstreamoperator>> (bool &n)
binary_ifstreamoperator>> (double &n)
binary_ifstreamoperator>> (std::string &n)
binary_ifstreamoperator>> (unsigned long &n)
binary_ifstreamoperator>> (char &n)
binary_ifstreamoperator>> (long &n)
binary_ifstreamoperator>> (unsigned int &n)
binary_ifstreamoperator>> (unsigned short &n)
binary_ifstreamoperator>> (float &n)
binary_ifstreamoperator>> (int &n)
binary_ifstreamoperator>> (unsigned char &n)
binary_ifstreamoperator>> (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::binary_ifstream ( const char *  name) [explicit]

Definition at line 8 of file binary_ifstream.cc.

References init().

                                                  : file_(0)
{
    init (name);
}
binary_ifstream::binary_ifstream ( const std::string &  name) [explicit]

Definition at line 13 of file binary_ifstream.cc.

References init().

                                                       : file_(0)
{
    init (name.c_str());
}
binary_ifstream::~binary_ifstream ( )

Definition at line 28 of file binary_ifstream.cc.

References close().

{
    close();
}

Member Function Documentation

bool binary_ifstream::bad ( ) const

Definition at line 99 of file binary_ifstream.cc.

References fail().

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

{return fail();}
void binary_ifstream::close ( void  )

Definition at line 32 of file binary_ifstream.cc.

References file_.

Referenced by ~binary_ifstream().

{
    if (file_ != 0) fclose( file_);
    file_ = 0;
}
bool binary_ifstream::eof ( ) const

Definition at line 88 of file binary_ifstream.cc.

References file_.

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

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

Definition at line 93 of file binary_ifstream.cc.

References file_.

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

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

stream state checking

Definition at line 83 of file binary_ifstream.cc.

References bad(), and eof().

Referenced by operator bool().

{
    return !bad() && !eof();
}
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().

{
    file_ = fopen( name, "rb");
    if (file_ == 0) {
        std::cout << "file " << name << " cannot be opened for reading"
                  << std::endl;
        throw binary_ifstream_error();
    }
}
binary_ifstream::operator bool ( ) const

Definition at line 105 of file binary_ifstream.cc.

References good().

                                     {
    return good();
}
bool binary_ifstream::operator! ( ) const

Definition at line 101 of file binary_ifstream.cc.

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

{return fail() || bad() || eof();}
binary_ifstream & binary_ifstream::operator>> ( unsigned int &  n)

Definition at line 54 of file binary_ifstream.cc.

References file_.

                                                             {
    fread( &n, sizeof(n), 1, file_); return *this;}
binary_ifstream & binary_ifstream::operator>> ( std::string &  n)

Definition at line 72 of file binary_ifstream.cc.

References gather_cfg::cout, file_, and tmp.

                                                          {
  unsigned int nchar;
  (*this) >> nchar;  
  char* tmp = new char[nchar+1];
  unsigned int nread = fread( tmp, 1, nchar, file_);
  if (nread != nchar) std::cout << "binary_ifstream error: read less then expected " << std::endl;
  n.assign( tmp, nread);
  delete[] tmp;
  return *this;
}
binary_ifstream & binary_ifstream::operator>> ( bool &  n)

Definition at line 67 of file binary_ifstream.cc.

References file_.

                                                     {
    n = static_cast<bool>(fgetc(file_));
    return *this;
}
binary_ifstream & binary_ifstream::operator>> ( int &  n)

Definition at line 52 of file binary_ifstream.cc.

References file_.

                                                    {
    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_.

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

Definition at line 43 of file binary_ifstream.cc.

References file_.

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

Definition at line 64 of file binary_ifstream.cc.

References file_.

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

Definition at line 48 of file binary_ifstream.cc.

References file_.

                                                      {
    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_.

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

Definition at line 38 of file binary_ifstream.cc.

References file_.

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

Definition at line 50 of file binary_ifstream.cc.

References file_.

                                                               {
    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_.

                                                     {
    fread( &n, sizeof(n), 1, file_); return *this;}

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