OPAL (Object Oriented Parallel Accelerator Library)
2021.1.99
OPAL
src
src
Classic
Parser
FileStream.cpp
Go to the documentation of this file.
1
// ------------------------------------------------------------------------
2
// $RCSfile: FileStream.cpp,v $
3
// ------------------------------------------------------------------------
4
// $Revision: 1.2 $
5
// ------------------------------------------------------------------------
6
// Copyright: see Copyright.readme
7
// ------------------------------------------------------------------------
8
//
9
// Class: FileStream
10
// Implements an input buffer for reading from a file.
11
//
12
// ------------------------------------------------------------------------
13
// Class category: Parser
14
// ------------------------------------------------------------------------
15
//
16
// $Date: 2001/08/24 19:33:11 $
17
// $Author: jsberg $
18
//
19
// ------------------------------------------------------------------------
20
21
#include "
Parser/FileStream.h
"
22
#include "
Utilities/ParseError.h
"
23
#include "
Utility/IpplInfo.h
"
24
#include <iomanip>
25
#include <iostream>
26
27
// Class FileStream
28
// ------------------------------------------------------------------------
29
30
bool
FileStream::echoFlag
=
false
;
31
32
33
FileStream::FileStream
(
const
std::string &
name
):
34
AbsFileStream
(
name
),
35
is(
name
.c_str()) {
36
if
(
is
.fail()) {
37
throw
ParseError
(
"FileStream::FileStream()"
,
38
"Cannot open file \""
+
name
+
"\"."
);
39
}
40
}
41
42
43
FileStream::~FileStream
()
44
{}
45
46
47
void
FileStream::setEcho
(
bool
flag) {
48
echoFlag
= flag;
49
}
50
51
52
bool
FileStream::getEcho
() {
53
return
echoFlag
;
54
}
55
56
57
bool
FileStream::fillLine
() {
58
if
(
is
.eof()) {
59
// End of file.
60
return
false
;
61
}
else
if
(
is
.bad()) {
62
// Read error.
63
throw
ParseError
(
"FileStream::fillLine()"
,
64
"Read error on file \""
+
stream_name
+
"\"."
);
65
}
else
{
66
// Stream OK, read next line.
67
line
=
""
;
68
std::getline(
is
,
line
,
'\n'
);
69
line
+=
"\n"
;
70
curr_line
++;
71
if
(
echoFlag
&&
Ippl::myNode
() == 0) {
72
std::cerr.width(5);
73
std::cerr <<
curr_line
<<
" "
<<
line
;
74
}
75
curr_char
= 0;
76
return
true
;
77
}
78
}
FileStream.h
ParseError.h
IpplInfo.h
name
const std::string name
Definition:
MaxNormRadialPeak.cpp:32
AbsFileStream
A stream of input tokens.
Definition:
AbsFileStream.h:31
AbsFileStream::line
std::string line
Definition:
AbsFileStream.h:63
AbsFileStream::curr_char
int curr_char
Definition:
AbsFileStream.h:64
FileStream::getEcho
static bool getEcho()
Return echo flag.
Definition:
FileStream.cpp:52
FileStream::is
std::ifstream is
Definition:
FileStream.h:63
FileStream::~FileStream
virtual ~FileStream()
Destructor.
Definition:
FileStream.cpp:43
FileStream::setEcho
static void setEcho(bool flag)
Set echo flag.
Definition:
FileStream.cpp:47
FileStream::FileStream
FileStream()
FileStream::echoFlag
static bool echoFlag
Definition:
FileStream.h:66
FileStream::fillLine
virtual bool fillLine()
Read next input line.
Definition:
FileStream.cpp:57
TokenStream::stream_name
std::string stream_name
Definition:
TokenStream.h:59
TokenStream::curr_line
int curr_line
Definition:
TokenStream.h:62
ParseError
Parse exception.
Definition:
ParseError.h:32
IpplInfo::myNode
static int myNode()
Definition:
IpplInfo.cpp:691
Generated on Wed Aug 25 2021 16:41:03 for OPAL (Object Oriented Parallel Accelerator Library) by
1.9.1