Main Page
Namespaces
Classes
Package Documentation
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
)
9
{
10
init
(name);
11
}
12
13
binary_ifstream::binary_ifstream
(
const
std::string
&
name
) :
file_
(
nullptr
)
14
{
15
init
(name.c_str());
16
}
17
18
void
binary_ifstream::init
(
const
char
*
name
)
19
{
20
file_
= fopen( name,
"rb"
);
21
if
(
file_
==
nullptr
) {
22
std::cout
<<
"file "
<< name <<
" cannot be opened for reading"
23
<< std::endl;
24
throw
binary_ifstream_error
();
25
}
26
}
27
28
binary_ifstream::~binary_ifstream
()
29
{
30
close
();
31
}
32
void
binary_ifstream::close
()
33
{
34
if
(
file_
!=
nullptr
) fclose(
file_
);
35
file_
=
nullptr
;
36
}
37
38
binary_ifstream
&
binary_ifstream::operator>>
(
char
&
n
) {
39
n =
static_cast<
char
>
(fgetc(
file_
));
40
return
*
this
;
41
}
42
43
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
char
&
n
) {
44
n =
static_cast<
unsigned
char
>
(fgetc(
file_
));
45
return
*
this
;
46
}
47
48
binary_ifstream
&
binary_ifstream::operator>>
(
short
&
n
) {
49
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
50
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
short
&
n
) {
51
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
52
binary_ifstream
&
binary_ifstream::operator>>
(
int
&
n
) {
53
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
54
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
int
&
n
) {
55
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
56
57
binary_ifstream
&
binary_ifstream::operator>>
(
long
&
n
) {
58
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
59
binary_ifstream
&
binary_ifstream::operator>>
(
unsigned
long
&
n
) {
60
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
61
62
binary_ifstream
&
binary_ifstream::operator>>
(
float
&
n
) {
63
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
64
binary_ifstream
&
binary_ifstream::operator>>
(
double
&
n
) {
65
fread( &n,
sizeof
(n), 1,
file_
);
return
*
this
;}
66
67
binary_ifstream
&
binary_ifstream::operator>>
(
bool
&
n
) {
68
n =
static_cast<
bool
>
(fgetc(
file_
));
69
return
*
this
;
70
}
71
72
binary_ifstream
&
binary_ifstream::operator>>
(
std::string
&
n
) {
73
unsigned
int
nchar;
74
(*this) >> nchar;
75
char
*
tmp
=
new
char
[nchar+1];
76
unsigned
int
nread = fread( tmp, 1, nchar,
file_
);
77
if
(nread != nchar)
std::cout
<<
"binary_ifstream error: read less then expected "
<< std::endl;
78
n.assign( tmp, nread);
79
delete
[]
tmp
;
80
return
*
this
;
81
}
82
83
bool
binary_ifstream::good
()
const
84
{
85
return
!
bad
() && !
eof
();
86
}
87
88
bool
binary_ifstream::eof
()
const
89
{
90
return
feof(
file_
);
91
}
92
93
bool
binary_ifstream::fail
()
const
94
{
95
return
file_
==
nullptr
|| ferror(
file_
) != 0;
96
}
97
98
// don't know the difference between fail() and bad() (yet)
99
bool
binary_ifstream::bad
()
const
{
return
fail
();}
100
101
bool
binary_ifstream::operator!
()
const
{
return
fail
() ||
bad
() ||
eof
();}
102
103
//binary_ifstream::operator bool() const {return !fail() && !bad();}
104
105
binary_ifstream::operator
bool
()
const
{
106
return
good
();
107
}
binary_ifstream::bad
bool bad() const
Definition:
binary_ifstream.cc:99
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:255
binary_ifstream::good
bool good() const
stream state checking
Definition:
binary_ifstream.cc:83
binary_ifstream_error
Definition:
binary_ifstream.cc:6
nullptr
#define nullptr
binary_ifstream::close
void close()
Definition:
binary_ifstream.cc:32
binary_ifstream::eof
bool eof() const
Definition:
binary_ifstream.cc:88
Utilities.operator
operator
Definition:
Utilities.py:23
binary_ifstream::file_
FILE * file_
Definition:
binary_ifstream.h:46
electrons_cff.bool
bool
Definition:
electrons_cff.py:266
binary_ifstream::operator!
bool operator!() const
Definition:
binary_ifstream.cc:101
binary_ifstream::~binary_ifstream
~binary_ifstream()
Definition:
binary_ifstream.cc:28
gen::n
int n
Definition:
Cascade2Hadronizer.cc:79
binary_ifstream
Definition:
binary_ifstream.h:8
tmp
std::vector< std::vector< double > > tmp
Definition:
MVATrainer.cc:100
binary_ifstream::binary_ifstream
binary_ifstream(const char *name)
Definition:
binary_ifstream.cc:8
gather_cfg.cout
cout
Definition:
gather_cfg.py:145
dataset.name
name
Definition:
dataset.py:45
binary_ifstream::operator>>
binary_ifstream & operator>>(char &n)
Definition:
binary_ifstream.cc:38
binary_ifstream::init
void init(const char *name)
Definition:
binary_ifstream.cc:18
binary_ifstream.h
binary_ifstream::fail
bool fail() const
Definition:
binary_ifstream.cc:93
Generated for CMSSW Reference Manual by
1.8.11