CMS 3D CMS Logo

binary_ofstream.cc
Go to the documentation of this file.
1 #include "binary_ofstream.h"
2 
3 #include <cstdio>
4 #include <iostream>
5 
7 
8 binary_ofstream::binary_ofstream(const char* name) : file_(nullptr) { init(name); }
9 
10 binary_ofstream::binary_ofstream(const std::string& name) : file_(nullptr) { init(name.c_str()); }
11 
12 void binary_ofstream::init(const char* name) {
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 }
19 
22  if (file_ != nullptr)
23  fclose(file_);
24  file_ = nullptr;
25 }
26 
28  fputc(n, file_);
29  return *this;
30 }
32  fputc(n, file_);
33  return *this;
34 }
35 
37  fwrite(&n, sizeof(n), 1, file_);
38  return *this;
39 }
41  fwrite(&n, sizeof(n), 1, file_);
42  return *this;
43 }
45  fwrite(&n, sizeof(n), 1, file_);
46  return *this;
47 }
49  fwrite(&n, sizeof(n), 1, file_);
50  return *this;
51 }
53  fwrite(&n, sizeof(n), 1, file_);
54  return *this;
55 }
57  fwrite(&n, sizeof(n), 1, file_);
58  return *this;
59 }
61  fwrite(&n, sizeof(n), 1, file_);
62  return *this;
63 }
65  fwrite(&n, sizeof(n), 1, file_);
66  return *this;
67 }
68 
69 binary_ofstream& binary_ofstream::operator<<(bool n) { return operator<<(static_cast<char>(n)); }
70 
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 }
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
gather_cfg.cout
cout
Definition: gather_cfg.py:144
binary_ofstream::file_
FILE * file_
Definition: binary_ofstream.h:36
binary_ofstream::binary_ofstream
binary_ofstream(const char *name)
Definition: binary_ofstream.cc:8
binary_ofstream::~binary_ofstream
~binary_ofstream()
Definition: binary_ofstream.cc:20
alignCSCRings.s
s
Definition: alignCSCRings.py:92
binary_ofstream.h
binary_ofstream::close
void close()
Definition: binary_ofstream.cc:21
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
binary_ofstream
Definition: binary_ofstream.h:8
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
binary_ofstream::init
void init(const char *name)
Definition: binary_ofstream.cc:12
binary_ofstream_error
Definition: binary_ofstream.cc:6
binary_ofstream::operator<<
binary_ofstream & operator<<(char n)
Definition: binary_ofstream.cc:27