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() [1/2]

binary_ofstream::binary_ofstream ( const char *  name)
explicit

Definition at line 8 of file binary_ofstream.cc.

References init(), and Skims_PA_cff::name.

8 : file_(nullptr) { init(name); }
void init(const char *name)

◆ binary_ofstream() [2/2]

binary_ofstream::binary_ofstream ( const std::string &  name)
explicit

Definition at line 10 of file binary_ofstream.cc.

References init(), and Skims_PA_cff::name.

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

◆ ~binary_ofstream()

binary_ofstream::~binary_ofstream ( )

Definition at line 20 of file binary_ofstream.cc.

References close().

20 { close(); }

Member Function Documentation

◆ close()

void binary_ofstream::close ( void  )

Definition at line 21 of file binary_ofstream.cc.

References file_.

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), and ~binary_ofstream().

21  {
22  if (file_ != nullptr)
23  fclose(file_);
24  file_ = nullptr;
25 }

◆ init()

void binary_ofstream::init ( const char *  name)
private

Definition at line 12 of file binary_ofstream.cc.

References gather_cfg::cout, file_, and Skims_PA_cff::name.

Referenced by binary_ofstream().

12  {
13  file_ = fopen(name, "wb");
14  if (file_ == nullptr) {
15  std::cout << "file " << name << " cannot be opened for writing" << std::endl;
16  throw binary_ofstream_error();
17  }
18 }

◆ operator<<() [1/12]

binary_ofstream & binary_ofstream::operator<< ( char  n)

Definition at line 27 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

27  {
28  fputc(n, file_);
29  return *this;
30 }

◆ operator<<() [2/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned char  n)

Definition at line 31 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

31  {
32  fputc(n, file_);
33  return *this;
34 }

◆ operator<<() [3/12]

binary_ofstream & binary_ofstream::operator<< ( short  n)

Definition at line 36 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

36  {
37  fwrite(&n, sizeof(n), 1, file_);
38  return *this;
39 }

◆ operator<<() [4/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned short  n)

Definition at line 40 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

40  {
41  fwrite(&n, sizeof(n), 1, file_);
42  return *this;
43 }

◆ operator<<() [5/12]

binary_ofstream & binary_ofstream::operator<< ( int  n)

Definition at line 44 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

44  {
45  fwrite(&n, sizeof(n), 1, file_);
46  return *this;
47 }

◆ operator<<() [6/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned int  n)

Definition at line 48 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

48  {
49  fwrite(&n, sizeof(n), 1, file_);
50  return *this;
51 }

◆ operator<<() [7/12]

binary_ofstream & binary_ofstream::operator<< ( long  n)

Definition at line 52 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

52  {
53  fwrite(&n, sizeof(n), 1, file_);
54  return *this;
55 }

◆ operator<<() [8/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned long  n)

Definition at line 56 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

56  {
57  fwrite(&n, sizeof(n), 1, file_);
58  return *this;
59 }

◆ operator<<() [9/12]

binary_ofstream & binary_ofstream::operator<< ( float  n)

Definition at line 60 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

60  {
61  fwrite(&n, sizeof(n), 1, file_);
62  return *this;
63 }

◆ operator<<() [10/12]

binary_ofstream & binary_ofstream::operator<< ( double  n)

Definition at line 64 of file binary_ofstream.cc.

References file_, and dqmiodumpmetadata::n.

64  {
65  fwrite(&n, sizeof(n), 1, file_);
66  return *this;
67 }

◆ operator<<() [11/12]

binary_ofstream & binary_ofstream::operator<< ( bool  n)

Definition at line 69 of file binary_ofstream.cc.

References dqmiodumpmetadata::n.

69 { return operator<<(static_cast<char>(n)); }

◆ operator<<() [12/12]

binary_ofstream & binary_ofstream::operator<< ( const std::string &  n)

Definition at line 71 of file binary_ofstream.cc.

References file_, and alignCSCRings::s.

71  {
72  (*this)
73  << (uint32_t)
74  s.size(); // Use uint32 for backward compatibilty of binary files that were generated on 32-bit machines.
75  fwrite(s.data(), 1, s.size(), file_);
76  return *this;
77 }

Member Data Documentation

◆ file_

FILE* binary_ofstream::file_
private

Definition at line 36 of file binary_ofstream.h.

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