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
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
41
42void FileStream::setEcho(bool flag) {
43 echoFlag = flag;
44}
45
47 return echoFlag;
48}
49
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}
AbsFileStream(const std::string &name)
Constructor.
std::string line
static bool getEcho()
Return echo flag.
std::ifstream is
Definition FileStream.h:63
virtual ~FileStream()
Destructor.
static void setEcho(bool flag)
Set echo flag.
static bool echoFlag
Definition FileStream.h:66
virtual bool fillLine()
Read next input line.
std::string stream_name
Definition TokenStream.h:59
Parse exception.
Definition ParseError.h:32