QMCPACK
IOASCII.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 // http://pathintegrals.info //
15 /////////////////////////////////////////////////////////////
16 
17 #ifndef IO_ASCII_H
18 #define IO_ASCII_H
19 #include "IOBase.h"
20 #include <iostream>
21 #include <stack>
22 #include <string>
23 #include <list>
24 
25 
26 namespace IO
27 {
28 /// This class holds an ASCII token, which is just a std::string and the
29 /// line number in which it appeared in the file.
31 {
32 public:
33  std::string Str;
35 };
36 
37 
38 /// This is the ASCII specialization of IOTreeClass for ASCII text
39 /// files. It's syntax is as follows:
40 /// Section (SectionName)
41 /// {
42 /// double x = 3;
43 /// blitz::Array<int,1> y(3) = [1, 2, 3];
44 /// blitz::Array<int,3> z(2,2,1) = [ 1, 2,
45 /// 3, 4 ];
46 /// Section (Species, "species1.h5");
47 /// }
49 {
50  /// Reads a text file into a buffer eliminating c++ and c-style
51  /// comments.
52  bool ReadWithoutComments(std::string fileName, Array<char, 1>& buffer);
53  /// Reads a section from a list of TokenClass objects. iter should
54  /// refer to the current place in the list that we should start
55  /// reading at. iter should point to a place just after the '{'.
56  /// If wantEndBrace is true, it will look for an ending '}'.
57  /// Otherwise it will read until the list of Tokens runs out.
58  bool ReadSection(IOTreeClass* parent,
59  std::string name,
60  std::list<TokenClass>::iterator& iter,
61  std::list<TokenClass>& tokenList,
62  bool wantEndBrace);
63 
64 public:
65  void WriteSection(std::ofstream& outFile, int indent);
66  IOFileType GetFileType() override;
67  /// Print an indented tree of section variable names.
68  void PrintTree(int level) override;
69  /// Same thing, just calls above with level 0;
70  void PrintTree() override;
71 
72  IOTreeClass* NewSection(std::string name) override;
73  void IncludeSection(IOTreeClass*) override;
74  /// Takes the name of a file to read, the name of my section and a
75  /// pointer to my parent. Reads the file into a tree of
76  /// IOTreeClass's.
77  bool OpenFile(std::string filename, std::string myName, IOTreeClass* parent) override;
78  bool NewFile(std::string fileName, std::string mySectionName, IOTreeClass* parent) override;
79  /// Do any file handling necessary and delete the whole tree of data.
80  void CloseFile() override;
81  void FlushFile() override;
82 
84 };
85 
86 } // namespace IO
87 #endif
bool ReadSection(IOTreeClass *parent, std::string name, std::list< TokenClass >::iterator &iter, std::list< TokenClass > &tokenList, bool wantEndBrace)
Reads a section from a list of TokenClass objects.
void PrintTree() override
Same thing, just calls above with level 0;.
void WriteSection(std::ofstream &outFile, int indent)
bool OpenFile(std::string filename, std::string myName, IOTreeClass *parent) override
Takes the name of a file to read, the name of my section and a pointer to my parent.
bool NewFile(std::string fileName, std::string mySectionName, IOTreeClass *parent) override
This class stores a tree of input file sections.
Definition: IOBase.h:33
IOTreeClass * NewSection(std::string name) override
Write me!
bool IsModified
Definition: IOBase.h:37
bool ReadWithoutComments(std::string fileName, Array< char, 1 > &buffer)
Reads a text file into a buffer eliminating c++ and c-style comments.
IOFileType
Definition: IOVarBase.h:35
This class holds an ASCII token, which is just a std::string and the line number in which it appeared...
Definition: IOASCII.h:30
Definition: IO.h:24
std::string Str
Definition: IOASCII.h:33
IOFileType GetFileType() override
void IncludeSection(IOTreeClass *) override
Inserts a new Include directive in the present section.
void CloseFile() override
Do any file handling necessary and delete the whole tree of data.
int LineNumber
Definition: IOASCII.h:34
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25
This is the ASCII specialization of IOTreeClass for ASCII text files.
Definition: IOASCII.h:48
void FlushFile() override