OPALX (Object Oriented Parallel Accelerator Library for Exascal)
master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
void
FileStream::setEcho
(
bool
flag) {
echoFlag
= flag; }
42
43
bool
FileStream::getEcho
() {
return
echoFlag
; }
44
45
bool
FileStream::fillLine
() {
46
if
(
is
.eof()) {
47
// End of file.
48
return
false
;
49
}
else
if
(
is
.bad()) {
50
// Read error.
51
throw
ParseError
(
"FileStream::fillLine()"
,
"Read error on file \""
+
stream_name
+
"\"."
);
52
}
else
{
53
// Stream OK, read next line.
54
line
=
""
;
55
std::getline(
is
,
line
,
'\n'
);
56
line
+=
"\n"
;
57
curr_line
++;
58
if
(
echoFlag
&& ippl::Comm->rank() == 0) {
59
std::cerr.width(5);
60
std::cerr <<
curr_line
<<
" "
<<
line
;
61
}
62
curr_char
= 0;
63
return
true
;
64
}
65
}
FileStream.h
ParseError.h
AbsFileStream
A stream of input tokens.
Definition
AbsFileStream.h:30
AbsFileStream::line
std::string line
Definition
AbsFileStream.h:59
AbsFileStream::curr_char
int curr_char
Definition
AbsFileStream.h:60
FileStream::getEcho
static bool getEcho()
Return echo flag.
Definition
FileStream.cpp:43
FileStream::is
std::ifstream is
Definition
FileStream.h:59
FileStream::~FileStream
virtual ~FileStream()
Destructor.
Definition
FileStream.cpp:39
FileStream::setEcho
static void setEcho(bool flag)
Set echo flag.
Definition
FileStream.cpp:41
FileStream::FileStream
FileStream()
FileStream::echoFlag
static bool echoFlag
Definition
FileStream.h:62
FileStream::fillLine
virtual bool fillLine()
Read next input line.
Definition
FileStream.cpp:45
ParseError
Parse exception.
Definition
ParseError.h:31
TokenStream::stream_name
std::string stream_name
Definition
TokenStream.h:53
TokenStream::curr_line
int curr_line
Definition
TokenStream.h:56
src
OpalParser
FileStream.cpp
Generated on Mon Jun 1 2026 10:40:52 for OPALX (Object Oriented Parallel Accelerator Library for Exascal) by
1.9.8