Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
MagneticField
Interpolation
src
binary_ifstream.cc
Go to the documentation of this file.
1
#include "
binary_ifstream.h
"
2
3
#include <cstdio>
4
#include <iostream>
5
6
struct
binary_ifstream_error
{};
7
8
binary_ifstream::binary_ifstream
(
const
char
*
name
) : file_(nullptr) {
init
(name); }
9
10
binary_ifstream::binary_ifstream
(
const
std::string
&
name
) : file_(nullptr) {
init
(name.c_str()); }
11
12
void
binary_ifstream::init
(
const
char
*
name
) {
13
file_
= fopen(name,
"rb"
);
14
if
(
file_
==
nullptr
) {
15
std::cout
<<
"file "
<< name <<
" cannot be opened for reading"
<< std::endl;
16
throw
binary_ifstream_error
();
17
}
18
}
19
20
binary_ifstream::~binary_ifstream
() {
close
(); }
21
void
binary_ifstream::close
() {
22
if
(
file_
!=
nullptr
)
23
fclose(
file_
);
24
file_
=
nullptr
;
25
}
26
27
binary_ifstream
&
binary_ifstream::operator>>
(
char
&
n
) {
28
n =
static_cast<
char
>
(fgetc(
file_
));
29
return
*
this
;
30
}
31
32
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
char
&
n
) {
33
n =
static_cast<
unsigned
char
>
(fgetc(
file_
));
34
return
*
this
;
35
}
36
37
binary_ifstream
&
binary_ifstream::operator>>
(
short
&
n
) {
38
fread(&n,
sizeof
(n), 1,
file_
);
39
return
*
this
;
40
}
41
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
short
&
n
) {
42
fread(&n,
sizeof
(n), 1,
file_
);
43
return
*
this
;
44
}
45
binary_ifstream
&
binary_ifstream::operator>>
(
int
&
n
) {
46
fread(&n,
sizeof
(n), 1,
file_
);
47
return
*
this
;
48
}
49
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
int
&
n
) {
50
fread(&n,
sizeof
(n), 1,
file_
);
51
return
*
this
;
52
}
53
54
binary_ifstream
&
binary_ifstream::operator>>
(
long
&
n
) {
55
fread(&n,
sizeof
(n), 1,
file_
);
56
return
*
this
;
57
}
58
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
long
&
n
) {
59
fread(&n,
sizeof
(n), 1,
file_
);
60
return
*
this
;
61
}
62
63
binary_ifstream
&
binary_ifstream::operator>>
(
float
&
n
) {
64
fread(&n,
sizeof
(n), 1,
file_
);
65
return
*
this
;
66
}
67
binary_ifstream
&
binary_ifstream::operator>>
(
double
&
n
) {
68
fread(&n,
sizeof
(n), 1,
file_
);
69
return
*
this
;
70
}
71
72
binary_ifstream
&
binary_ifstream::operator>>
(
bool
&
n
) {
73
n =
static_cast<
bool
>
(fgetc(
file_
));
74
return
*
this
;
75
}
76
77
binary_ifstream
&
binary_ifstream::operator>>
(
std::string
&
n
) {
78
unsigned
int
nchar;
79
(*this) >> nchar;
80
char
*
tmp
=
new
char
[nchar + 1];
81
unsigned
int
nread = fread(tmp, 1, nchar,
file_
);
82
if
(nread != nchar)
83
std::cout
<<
"binary_ifstream error: read less then expected "
<< std::endl;
84
n.assign(tmp, nread);
85
delete
[]
tmp
;
86
return
*
this
;
87
}
88
89
bool
binary_ifstream::good
()
const
{
return
!
bad
() && !
eof
(); }
90
91
bool
binary_ifstream::eof
()
const
{
return
feof(
file_
); }
92
93
bool
binary_ifstream::fail
()
const
{
return
file_
==
nullptr
|| ferror(
file_
) != 0; }
94
95
// don't know the difference between fail() and bad() (yet)
96
bool
binary_ifstream::bad
()
const
{
return
fail
(); }
97
98
bool
binary_ifstream::operator!
()
const
{
return
fail
() ||
bad
() ||
eof
(); }
99
100
//binary_ifstream::operator bool() const {return !fail() && !bad();}
101
102
binary_ifstream::operator
bool()
const
{
return
good
(); }
binary_ifstream::bad
bool bad() const
Definition:
binary_ifstream.cc:96
binary_ifstream::good
bool good() const
stream state checking
Definition:
binary_ifstream.cc:89
binary_ifstream_error
Definition:
binary_ifstream.cc:6
mergeVDriftHistosByStation.name
string name
Definition:
mergeVDriftHistosByStation.py:78
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
binary_ifstream::close
void close()
Definition:
binary_ifstream.cc:21
binary_ifstream::eof
bool eof() const
Definition:
binary_ifstream.cc:91
Utilities.operator
operator
Definition:
Utilities.py:24
binary_ifstream::file_
FILE * file_
Definition:
binary_ifstream.h:44
good
auto const good
min quality of good
Definition:
CAHitNtupletGeneratorKernelsImpl.h:769
binary_ifstream::operator!
bool operator!() const
Definition:
binary_ifstream.cc:98
binary_ifstream::~binary_ifstream
~binary_ifstream()
Definition:
binary_ifstream.cc:20
binary_ifstream
Definition:
binary_ifstream.h:8
gather_cfg.cout
tuple cout
Definition:
gather_cfg.py:144
binary_ifstream::binary_ifstream
binary_ifstream(const char *name)
Definition:
binary_ifstream.cc:8
binary_ifstream::operator>>
binary_ifstream & operator>>(char &n)
Definition:
binary_ifstream.cc:27
binary_ifstream::init
void init(const char *name)
Definition:
binary_ifstream.cc:12
createJobs.tmp
tmp
align.sh
Definition:
createJobs.py:716
binary_ifstream.h
binary_ifstream::fail
bool fail() const
Definition:
binary_ifstream.cc:93
dqmiodumpmetadata.n
int n
Definition:
dqmiodumpmetadata.py:28
Generated for CMSSW Reference Manual by
1.8.5