CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
binary_ofstream Class Reference

#include <binary_ofstream.h>

Public Member Functions

 binary_ofstream (const char *name)
 
 binary_ofstream (const std::string &name)
 
void close ()
 
binary_ofstreamoperator<< (char n)
 
binary_ofstreamoperator<< (unsigned char n)
 
binary_ofstreamoperator<< (short n)
 
binary_ofstreamoperator<< (unsigned short n)
 
binary_ofstreamoperator<< (int n)
 
binary_ofstreamoperator<< (unsigned int n)
 
binary_ofstreamoperator<< (long n)
 
binary_ofstreamoperator<< (unsigned long n)
 
binary_ofstreamoperator<< (float n)
 
binary_ofstreamoperator<< (double n)
 
binary_ofstreamoperator<< (bool n)
 
binary_ofstreamoperator<< (const std::string &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().

8  : file_(nullptr)
9 {
10  init (name);
11 }
void init(const char *name)
binary_ofstream::binary_ofstream ( const std::string &  name)
explicit

Definition at line 13 of file binary_ofstream.cc.

References init().

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

Definition at line 28 of file binary_ofstream.cc.

References close().

29 {
30  close();
31 }

Member Function Documentation

void binary_ofstream::close ( void  )
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().

19 {
20  file_ = fopen( name, "wb");
21  if (file_ == nullptr) {
22  std::cout << "file " << name << " cannot be opened for writing"
23  << std::endl;
24  throw binary_ofstream_error();
25  }
26 }
binary_ofstream & binary_ofstream::operator<< ( char  n)

Definition at line 38 of file binary_ofstream.cc.

References file_.

38  {
39  fputc( n, file_); return *this;
40 }
binary_ofstream & binary_ofstream::operator<< ( unsigned char  n)

Definition at line 41 of file binary_ofstream.cc.

References file_.

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

Definition at line 45 of file binary_ofstream.cc.

References file_.

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

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

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

Definition at line 51 of file binary_ofstream.cc.

References file_.

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

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

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

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

Definition at line 59 of file binary_ofstream.cc.

References file_.

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

Definition at line 62 of file binary_ofstream.cc.

References gen::n.

62  {
63  return operator<<( static_cast<char>(n));
64 }
binary_ofstream & binary_ofstream::operator<< ( const std::string &  n)

Definition at line 66 of file binary_ofstream.cc.

References file_.

66  {
67  (*this) << (uint32_t) s.size(); // Use uint32 for backward compatibilty of binary files that were generated on 32-bit machines.
68  fwrite( s.data(), 1, s.size(), file_);
69  return *this;
70 }

Member Data Documentation

FILE* binary_ofstream::file_
private

Definition at line 38 of file binary_ofstream.h.

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