OPALX (Object Oriented Parallel Accelerator Library for Exascal)
MINIorX
OPALX
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 "
OpalParser/FileStream.h
"
22
#include <iomanip>
23
#include <iostream>
24
#include "Ippl.h"
25
#include "
Utilities/ParseError.h
"
26
#include "Utility/IpplInfo.h"
27
28
// Class FileStream
29
// ------------------------------------------------------------------------
30
31
bool
FileStream::echoFlag
=
false
;
32
33
FileStream::FileStream
(
const
std::string& name) :
AbsFileStream
(name),
is
(name.c_str()) {
34
if
(
is
.fail()) {
35
throw ParseError(
"FileStream::FileStream()"
,
"Cannot open file \""
+ name +
"\"."
);
36
}
37
}
38
39
FileStream::~FileStream
() {
40
}
41
42
void
FileStream::setEcho
(
bool
flag) {
43
echoFlag
= flag;
44
}
45
46
bool
FileStream::getEcho
() {
47
return
echoFlag
;
48
}
49
50
bool
FileStream::fillLine
() {
51
if
(
is
.eof()) {
52
// End of file.
53
return
false
;
54
}
else
if
(
is
.bad()) {
55
// Read error.
56
throw
ParseError
(
"FileStream::fillLine()"
,
"Read error on file \""
+
stream_name
+
"\"."
);
57
}
else
{
58
// Stream OK, read next line.
59
line
=
""
;
60
std::getline(
is
,
line
,
'\n'
);
61
line
+=
"\n"
;
62
curr_line
++;
63
if
(
echoFlag
&& ippl::Comm->rank() == 0) {
64
std::cerr.width(5);
65
std::cerr <<
curr_line
<<
" "
<<
line
;
66
}
67
curr_char
= 0;
68
return
true
;
69
}
70
}
ParseError.h
FileStream.h
AbsFileStream::AbsFileStream
AbsFileStream(const std::string &name)
Constructor.
Definition
AbsFileStream.cpp: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:46
FileStream::is
std::ifstream is
Definition
FileStream.h:63
FileStream::~FileStream
virtual ~FileStream()
Destructor.
Definition
FileStream.cpp:39
FileStream::setEcho
static void setEcho(bool flag)
Set echo flag.
Definition
FileStream.cpp:42
FileStream::FileStream
FileStream()
FileStream::echoFlag
static bool echoFlag
Definition
FileStream.h:66
FileStream::fillLine
virtual bool fillLine()
Read next input line.
Definition
FileStream.cpp:50
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