Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
MagneticField
Interpolation
src
binary_ofstream.cc
Go to the documentation of this file.
1
#include "
binary_ofstream.h
"
2
3
#include <cstdio>
4
#include <iostream>
5
6
struct
binary_ofstream_error
{};
7
8
binary_ofstream::binary_ofstream
(
const
char
*
name
) : file_(0)
9
{
10
init
(name);
11
}
12
13
binary_ofstream::binary_ofstream
(
const
std::string
&
name
) : file_(0)
14
{
15
init
(name.c_str());
16
}
17
18
void
binary_ofstream::init
(
const
char
*
name
)
19
{
20
file_
= fopen( name,
"wb"
);
21
if
(
file_
== 0) {
22
std::cout
<<
"file "
<< name <<
" cannot be opened for writing"
23
<< std::endl;
24
throw
binary_ofstream_error
();
25
}
26
}
27
28
binary_ofstream::~binary_ofstream
()
29
{
30
close
();
31
}
32
void
binary_ofstream::close
()
33
{
34
if
(
file_
!= 0) fclose(
file_
);
35
file_
= 0;
36
}
37
38
binary_ofstream
&
binary_ofstream::operator<<
(
char
n
) {
39
fputc( n,
file_
);
return
*
this
;
40
}
41
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
char
n
) {
42
fputc( n,
file_
);
return
*
this
;
43
}
44
45
binary_ofstream
&
binary_ofstream::operator<<
(
short
n
) {
46
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
47
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
short
n
) {
48
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
49
binary_ofstream
&
binary_ofstream::operator<<
(
int
n
) {
50
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
51
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
int
n
) {
52
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
53
binary_ofstream
&
binary_ofstream::operator<<
(
long
n
) {
54
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
55
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
long
n
) {
56
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
57
binary_ofstream
&
binary_ofstream::operator<<
(
float
n
) {
58
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
59
binary_ofstream
&
binary_ofstream::operator<<
(
double
n
) {
60
fwrite( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
61
62
binary_ofstream
&
binary_ofstream::operator<<
(
bool
n
) {
63
return
operator<<( static_cast<char>(
n
));
64
}
65
66
binary_ofstream
&
binary_ofstream::operator<<
(
const
std::string
&
s
) {
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
}
binary_ofstream
Definition:
binary_ofstream.h:8
binary_ofstream::close
void close()
Definition:
binary_ofstream.cc:32
binary_ofstream_error
Definition:
binary_ofstream.cc:6
mergeVDriftHistosByStation.name
string name
Definition:
mergeVDriftHistosByStation.py:77
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:255
binary_ofstream::file_
FILE * file_
Definition:
binary_ofstream.h:38
binary_ofstream::init
void init(const char *name)
Definition:
binary_ofstream.cc:18
binary_ofstream::binary_ofstream
binary_ofstream(const char *name)
Definition:
binary_ofstream.cc:8
binary_ofstream::operator<<
binary_ofstream & operator<<(char n)
Definition:
binary_ofstream.cc:38
n
int n
Definition:
DTDataIntegrityTask.cc:30
alignCSCRings.s
list s
Definition:
alignCSCRings.py:91
binary_ofstream.h
gather_cfg.cout
tuple cout
Definition:
gather_cfg.py:121
binary_ofstream::~binary_ofstream
~binary_ofstream()
Definition:
binary_ofstream.cc:28
Generated for CMSSW Reference Manual by
1.8.5