CMS 3D CMS Logo

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

Definition at line 10 of file binary_ofstream.cc.

References init().

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

Definition at line 20 of file binary_ofstream.cc.

References close().

20 { close(); }

Member Function Documentation

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 }
void binary_ofstream::init ( const char *  name)
private

Definition at line 12 of file binary_ofstream.cc.

References gather_cfg::cout, and file_.

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 }
tuple cout
Definition: gather_cfg.py:144
binary_ofstream & binary_ofstream::operator<< ( char  n)

Definition at line 27 of file binary_ofstream.cc.

References file_.

27  {
28  fputc(n, file_);
29  return *this;
30 }
binary_ofstream & binary_ofstream::operator<< ( unsigned char  n)

Definition at line 31 of file binary_ofstream.cc.

References file_.

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

Definition at line 36 of file binary_ofstream.cc.

References file_.

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

Definition at line 40 of file binary_ofstream.cc.

References file_.

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

Definition at line 44 of file binary_ofstream.cc.

References file_.

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

Definition at line 48 of file binary_ofstream.cc.

References file_.

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

Definition at line 52 of file binary_ofstream.cc.

References file_.

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

Definition at line 56 of file binary_ofstream.cc.

References file_.

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

Definition at line 60 of file binary_ofstream.cc.

References file_.

60  {
61  fwrite(&n, sizeof(n), 1, file_);
62  return *this;
63 }
binary_ofstream & binary_ofstream::operator<< ( double  n)

Definition at line 64 of file binary_ofstream.cc.

References file_.

64  {
65  fwrite(&n, sizeof(n), 1, file_);
66  return *this;
67 }
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)); }
binary_ofstream & binary_ofstream::operator<< ( const std::string &  n)

Definition at line 71 of file binary_ofstream.cc.

References file_.

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* binary_ofstream::file_
private

Definition at line 36 of file binary_ofstream.h.

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