CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

binary_ofstream Class Reference

#include <binary_ofstream.h>

List of all members.

Public Member Functions

 binary_ofstream (const char *name)
 binary_ofstream (const std::string &name)
void close ()
binary_ofstreamoperator<< (bool n)
binary_ofstreamoperator<< (double n)
binary_ofstreamoperator<< (const std::string &n)
binary_ofstreamoperator<< (unsigned long n)
binary_ofstreamoperator<< (long n)
binary_ofstreamoperator<< (unsigned int n)
binary_ofstreamoperator<< (int n)
binary_ofstreamoperator<< (unsigned short n)
binary_ofstreamoperator<< (float n)
binary_ofstreamoperator<< (unsigned char n)
binary_ofstreamoperator<< (char n)
binary_ofstreamoperator<< (short n)
 ~binary_ofstream ()

Private Member Functions

void init (const char *name)

Private Attributes

FILE * file_

Detailed Description

Definition at line 8 of file binary_ofstream.h.


Constructor & Destructor Documentation

binary_ofstream::binary_ofstream ( const char *  name) [explicit]

Definition at line 8 of file binary_ofstream.cc.

References init().

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

Definition at line 13 of file binary_ofstream.cc.

References init().

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

Definition at line 28 of file binary_ofstream.cc.

References close().

{
    close();
}

Member Function Documentation

void binary_ofstream::close ( void  )

Definition at line 32 of file binary_ofstream.cc.

References file_.

Referenced by ~binary_ofstream().

{
    if (file_ != 0) fclose( file_);
    file_ = 0;
}
void binary_ofstream::init ( const char *  name) [private]

Definition at line 18 of file binary_ofstream.cc.

References gather_cfg::cout, and file_.

Referenced by binary_ofstream().

{
    file_ = fopen( name, "wb");
    if (file_ == 0) {
        std::cout << "file " << name << " cannot be opened for writing"
                  << std::endl;
        throw binary_ofstream_error();
    }
}
binary_ofstream & binary_ofstream::operator<< ( unsigned int  n)

Definition at line 51 of file binary_ofstream.cc.

References file_.

                                                            {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( const std::string &  n)

Definition at line 66 of file binary_ofstream.cc.

References file_.

                                                                {
  (*this) << s.size();
  fwrite( s.data(), 1, s.size(), file_);
  return *this;
}
binary_ofstream & binary_ofstream::operator<< ( bool  n)

Definition at line 62 of file binary_ofstream.cc.

References n.

                                                    {
  return operator<<( static_cast<char>(n));
}
binary_ofstream & binary_ofstream::operator<< ( double  n)

Definition at line 59 of file binary_ofstream.cc.

References file_.

                                                      {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( float  n)

Definition at line 57 of file binary_ofstream.cc.

References file_.

                                                     {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( unsigned long  n)

Definition at line 55 of file binary_ofstream.cc.

References file_.

                                                             {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( char  n)

Definition at line 38 of file binary_ofstream.cc.

References file_.

                                                    {
    fputc( n, file_); return *this;
}
binary_ofstream & binary_ofstream::operator<< ( short  n)

Definition at line 45 of file binary_ofstream.cc.

References file_.

                                                     {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( int  n)

Definition at line 49 of file binary_ofstream.cc.

References file_.

                                                   {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( unsigned short  n)

Definition at line 47 of file binary_ofstream.cc.

References file_.

                                                              {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( long  n)

Definition at line 53 of file binary_ofstream.cc.

References file_.

                                                    {
    fwrite( &n, sizeof(n), 1, file_); return *this;}
binary_ofstream & binary_ofstream::operator<< ( unsigned char  n)

Definition at line 41 of file binary_ofstream.cc.

References file_.

                                                             {
    fputc( n, file_); return *this;
}

Member Data Documentation

FILE* binary_ofstream::file_ [private]

Definition at line 38 of file binary_ofstream.h.

Referenced by close(), init(), and operator<<().