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
22#include <iomanip>
23#include <iostream>
24#include "Ippl.h"
26#include "Utility/IpplInfo.h"
27
28// Class FileStream
29// ------------------------------------------------------------------------
30
31bool FileStream::echoFlag = false;
32
33FileStream::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
40
41void FileStream::setEcho(bool flag) { echoFlag = flag; }
42
43bool FileStream::getEcho() { return echoFlag; }
44
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}
A stream of input tokens.
std::string line
static bool getEcho()
Return echo flag.
std::ifstream is
Definition FileStream.h:59
virtual ~FileStream()
Destructor.
static void setEcho(bool flag)
Set echo flag.
static bool echoFlag
Definition FileStream.h:62
virtual bool fillLine()
Read next input line.
Parse exception.
Definition ParseError.h:31
std::string stream_name
Definition TokenStream.h:53