QMCPACK
IOTreeClass Class Referenceabstract

This class stores a tree of input file sections. More...

+ Inheritance diagram for IOTreeClass:
+ Collaboration diagram for IOTreeClass:

Public Member Functions

void MarkModified ()
 
virtual void PrintTree ()=0
 
virtual void PrintTree (int numIndent)=0
 
virtual IOFileType GetFileType ()=0
 
void InsertSection (IOTreeClass *newSec)
 
bool FindSection (std::string name, IOTreeClass *&sectionPtr, int num=0)
 FindSection locates a subsection with the given name within the section in contains and returns it in the pointer, sectionPtr, which is passed a reference. More...
 
int CountSections (std::string name)
 Returns the number of subsections with the given name within the present section. More...
 
int CountVars ()
 
template<class T >
bool ReadVar (std::string name, T &var)
 
IOVarBaseGetVarPtr (std::string name)
 
IOVarBaseGetVarPtr (int num)
 
virtual IOTreeClassNewSection (std::string name)=0
 Write me! More...
 
virtual bool OpenFile (std::string fileName, std::string mySectionName, IOTreeClass *parent)=0
 
virtual bool NewFile (std::string fileName, std::string mySectionName, IOTreeClass *parent)=0
 
virtual void IncludeSection (IOTreeClass *)=0
 Inserts a new Include directive in the present section. More...
 
virtual void CloseFile ()=0
 
virtual void FlushFile ()=0
 
template<typename T >
bool WriteVar (std::string name, T val)
 These create a new variable with the given name and value: More...
 
template<typename T , int LEN>
bool WriteVar (std::string name, const TinyVector< T, LEN > &val)
 
template<typename T , int RANK>
bool WriteVar (std::string name, const Array< T, RANK > &val)
 
template<typename T , int RANK, int LEN>
bool WriteVar (std::string name, const Array< TinyVector< T, LEN >, RANK > &val)
 
template<class T >
bool AppendVar (std::string name, T val)
 Append a value to a variable of dimension of 1 higher than val. More...
 
void SetUnderscores (bool use)
 
 IOTreeClass ()
 
virtual ~IOTreeClass ()
 
template<>
bool WriteVar (std::string name, const char *val)
 

Public Attributes

std::list< IOVarBase * > VarList
 
std::list< IOTreeClass * > SectionList
 
int MyNumber
 This is used to ensure proper ordering of sections in the HDF version in which there is no guarantee that the sections will come out of the file in the same order you put them in. More...
 
int CurrSecNum
 
IOTreeClassParent
 
std::string FileName
 This is the empty std::string unless I'm the root node of some file. More...
 
std::string Name
 

Protected Attributes

bool IsModified
 
bool UseUnderscores
 

Detailed Description

This class stores a tree of input file sections.

Each member of the tree contains a list of tree nodes below it and a list of variables contained in the present node.

Definition at line 33 of file IOBase.h.

Constructor & Destructor Documentation

◆ IOTreeClass()

IOTreeClass ( )
inline

Definition at line 145 of file IOBase.h.

145  : UseUnderscores(false), FileName("")
146  {
147  // Nothing for now
148  }
std::string FileName
This is the empty std::string unless I&#39;m the root node of some file.
Definition: IOBase.h:55
bool UseUnderscores
Definition: IOBase.h:38

◆ ~IOTreeClass()

virtual ~IOTreeClass ( )
inlinevirtual

Definition at line 149 of file IOBase.h.

149 {}

Member Function Documentation

◆ AppendVar()

bool AppendVar ( std::string  name,
val 
)
inline

Append a value to a variable of dimension of 1 higher than val.

i.e. Add a double to an blitz::Array<double,1> or add blitz::Array<double,1> to an blitz::Array<double,2>, etc.

Definition at line 162 of file IOBase.h.

References IOVarBase::GetExtent(), IOTreeClass::GetVarPtr(), IOTreeClass::MarkModified(), IOVarBase::Resize(), and IOVarBase::Write().

Referenced by IOSectionClass::AppendVar().

163 {
164  IOVarBase* var = GetVarPtr(name);
165  if (var == NULL)
166  return false;
167  MarkModified();
168  int dim0 = var->GetExtent(0);
169  var->Resize(dim0 + 1);
170  return var->Write(val, 0);
171  // return var->Append(val);
172 }
IOVarBase * GetVarPtr(std::string name)
Definition: IOBase.h:81
void MarkModified()
Definition: IOBase.h:152

◆ CloseFile()

virtual void CloseFile ( )
pure virtual

Implemented in IOTreeASCIIClass.

◆ CountSections()

int CountSections ( std::string  name)
inline

Returns the number of subsections with the given name within the present section.

Definition at line 177 of file IOBase.h.

References IOTreeClass::SectionList.

Referenced by IOSectionClass::CountSections().

178 {
179  std::list<IOTreeClass*>::iterator sectionIter;
180  sectionIter = SectionList.begin();
181  int numSections = 0;
182  while (sectionIter != SectionList.end())
183  {
184  if ((name == (*sectionIter)->Name) || (name == ""))
185  {
186  numSections++;
187  }
188  sectionIter++;
189  }
190  return numSections;
191 }
std::list< IOTreeClass * > SectionList
Definition: IOBase.h:42

◆ CountVars()

int CountVars ( )
inline

Definition at line 193 of file IOBase.h.

References IOTreeClass::VarList.

Referenced by IOSectionClass::CountVars().

194 {
195  std::list<IOVarBase*>::iterator varIter;
196  varIter = VarList.begin();
197  int numVars = 0;
198  while (varIter != VarList.end())
199  {
200  numVars++;
201  varIter++;
202  }
203  return numVars;
204 }
std::list< IOVarBase * > VarList
Definition: IOBase.h:41

◆ FindSection()

bool FindSection ( std::string  name,
IOTreeClass *&  sectionPtr,
int  num = 0 
)
inline

FindSection locates a subsection with the given name within the section in contains and returns it in the pointer, sectionPtr, which is passed a reference.

Returns true if the section is found. The final parameter, which default value "true", optionally resets the section iterator to the beginning of the section. Thus, one may control whether or not order is significant.

Definition at line 214 of file IOBase.h.

References IOTreeClass::SectionList.

215 {
216  std::list<IOTreeClass*>::iterator Iter = SectionList.begin();
217  int counter = 0;
218  while (counter <= num && Iter != SectionList.end())
219  {
220  if ((*Iter)->Name == name)
221  {
222  counter++;
223  }
224  if (counter <= num)
225  Iter++;
226  }
227  bool found = Iter != SectionList.end();
228  if (found)
229  {
230  sectionPtr = *Iter;
231  }
232  return (found);
233 }
std::list< IOTreeClass * > SectionList
Definition: IOBase.h:42

◆ FlushFile()

virtual void FlushFile ( )
pure virtual

Implemented in IOTreeASCIIClass.

◆ GetFileType()

virtual IOFileType GetFileType ( )
pure virtual

Implemented in IOTreeASCIIClass.

Referenced by IOTreeClass::WriteVar().

◆ GetVarPtr() [1/2]

IOVarBase* GetVarPtr ( std::string  name)
inline

Definition at line 81 of file IOBase.h.

References IOTreeClass::MarkModified(), and IOTreeClass::VarList.

Referenced by IOTreeClass::AppendVar(), and IOSectionClass::GetVarPtr().

82  {
83  std::list<IOVarBase*>::iterator iter = VarList.begin();
84  while ((iter != VarList.end()) && ((*iter)->GetName() != name))
85  {
86  iter++;
87  }
88  if (iter == VarList.end())
89  return NULL;
90  else
91  {
92  MarkModified(); // If we're getting the pointer, we're probably
93  // gonna modify the variable.
94  return *iter;
95  }
96  }
void MarkModified()
Definition: IOBase.h:152
std::list< IOVarBase * > VarList
Definition: IOBase.h:41

◆ GetVarPtr() [2/2]

IOVarBase* GetVarPtr ( int  num)
inline

Definition at line 97 of file IOBase.h.

References IOTreeClass::MarkModified(), and IOTreeClass::VarList.

98  {
99  std::list<IOVarBase*>::iterator iter = VarList.begin();
100  int i = 0;
101  while ((iter != VarList.end()) && (i != num))
102  {
103  iter++;
104  i++;
105  }
106  if (iter == VarList.end())
107  return NULL;
108  else
109  {
110  MarkModified(); // If we're getting the pointer, we're probably
111  // gonna modify the variable.
112  return *iter;
113  }
114  }
void MarkModified()
Definition: IOBase.h:152
std::list< IOVarBase * > VarList
Definition: IOBase.h:41

◆ IncludeSection()

virtual void IncludeSection ( IOTreeClass )
pure virtual

Inserts a new Include directive in the present section.

Implemented in IOTreeASCIIClass.

◆ InsertSection()

void InsertSection ( IOTreeClass newSec)
inline

Definition at line 236 of file IOBase.h.

References IOTreeClass::MyNumber, and IOTreeClass::SectionList.

237 {
238  std::list<IOTreeClass*>::iterator iter;
239 
240  if (SectionList.empty())
241  SectionList.push_back(newSec);
242  else
243  {
244  iter = SectionList.begin();
245  while ((iter != SectionList.end()) && ((*iter)->MyNumber < newSec->MyNumber))
246  iter++;
247  if (iter != SectionList.end())
248  SectionList.insert(iter, newSec);
249  else
250  SectionList.push_back(newSec);
251  }
252 }
std::list< IOTreeClass * > SectionList
Definition: IOBase.h:42

◆ MarkModified()

void MarkModified ( )
inline

Definition at line 152 of file IOBase.h.

References IOTreeClass::FileName, IOTreeClass::IsModified, IOTreeClass::MarkModified(), and IOTreeClass::Parent.

Referenced by IOTreeClass::AppendVar(), IOTreeClass::GetVarPtr(), and IOTreeClass::MarkModified().

153 {
154  if (FileName != "")
155  IsModified = true;
156  else if (Parent != NULL)
157  Parent->MarkModified();
158 }
bool IsModified
Definition: IOBase.h:37
void MarkModified()
Definition: IOBase.h:152
IOTreeClass * Parent
Definition: IOBase.h:53
std::string FileName
This is the empty std::string unless I&#39;m the root node of some file.
Definition: IOBase.h:55

◆ NewFile()

virtual bool NewFile ( std::string  fileName,
std::string  mySectionName,
IOTreeClass parent 
)
pure virtual

Implemented in IOTreeASCIIClass.

◆ NewSection()

virtual IOTreeClass* NewSection ( std::string  name)
pure virtual

Write me!

Implemented in IOTreeASCIIClass.

Referenced by IOSectionClass::NewSection().

◆ OpenFile()

virtual bool OpenFile ( std::string  fileName,
std::string  mySectionName,
IOTreeClass parent 
)
pure virtual

Implemented in IOTreeASCIIClass.

◆ PrintTree() [1/2]

virtual void PrintTree ( )
pure virtual

Implemented in IOTreeASCIIClass.

Referenced by IOSectionClass::PrintTree().

◆ PrintTree() [2/2]

virtual void PrintTree ( int  numIndent)
pure virtual

Implemented in IOTreeASCIIClass.

◆ ReadVar()

bool ReadVar ( std::string  name,
T &  var 
)
inline

Definition at line 63 of file IOBase.h.

References IOTreeClass::Parent, IOTreeClass::ReadVar(), and IOTreeClass::VarList.

Referenced by IOTreeClass::ReadVar(), and IOSectionClass::ReadVar().

64  {
65  bool readVarSuccess;
66  std::list<IOVarBase*>::iterator varIter = VarList.begin();
67  while ((varIter != VarList.end()) && ((*varIter)->GetName() != name))
68  varIter++;
69 
70  bool found = varIter != VarList.end();
71  if (found)
72  readVarSuccess = (*varIter)->Read(var);
73  else if (Parent != NULL)
74  readVarSuccess = Parent->ReadVar(name, var);
75  else
76  return false;
77 
78  return readVarSuccess;
79  }
std::list< IOVarBase * > VarList
Definition: IOBase.h:41
bool ReadVar(std::string name, T &var)
Definition: IOBase.h:63
IOTreeClass * Parent
Definition: IOBase.h:53

◆ SetUnderscores()

void SetUnderscores ( bool  use)
inline

Definition at line 143 of file IOBase.h.

References IOTreeClass::UseUnderscores.

Referenced by IOSectionClass::SetUnderscores().

143 { UseUnderscores = use; }
bool UseUnderscores
Definition: IOBase.h:38

◆ WriteVar() [1/5]

bool WriteVar ( std::string  name,
const char *  val 
)
inline

Definition at line 32 of file IO.h.

References IOTreeClass::WriteVar().

33 {
34  return WriteVar(name, std::string(val));
35 }
bool WriteVar(std::string name, T val)
These create a new variable with the given name and value:
Definition: IO.h:37

◆ WriteVar() [2/5]

bool WriteVar ( std::string  name,
val 
)

These create a new variable with the given name and value:

Definition at line 37 of file IO.h.

References IO::ASCII_TYPE, and IOTreeClass::GetFileType().

Referenced by IOTreeClass::WriteVar(), and IOSectionClass::WriteVar().

38 {
39  if (GetFileType() == ASCII_TYPE)
40  {
41  throw std::logic_error{"this case is unimplement for rank 0"};
42 // VarList.push_back(new IOVarASCII<T, 0>(name, val));
43  }
44  else
45  {
46  std::cerr << "Unknown file type in WriteVar.\n";
47  abort();
48  }
49  return true;
50 }
virtual IOFileType GetFileType()=0

◆ WriteVar() [3/5]

bool WriteVar ( std::string  name,
const TinyVector< T, LEN > &  val 
)

Definition at line 53 of file IO.h.

References IOTreeClass::WriteVar().

54 {
55  Array<T, 1> aVal(LEN);
56  for (int i = 0; i < LEN; i++)
57  aVal(i) = val[i];
58  WriteVar(name, aVal);
59  return true;
60 }
bool WriteVar(std::string name, T val)
These create a new variable with the given name and value:
Definition: IO.h:37

◆ WriteVar() [4/5]

bool WriteVar ( std::string  name,
const Array< T, RANK > &  val 
)

Definition at line 64 of file IO.h.

References IO::ASCII_TYPE, IOTreeClass::GetFileType(), and IOTreeClass::VarList.

65 {
66  if (GetFileType() == ASCII_TYPE)
67  {
68  VarList.push_back(new IOVarASCII<T, RANK>(name, val));
69  }
70  else
71  {
72  std::cerr << "Unknown file type in WriteVar.\n";
73  abort();
74  }
75  return true;
76 }
std::list< IOVarBase * > VarList
Definition: IOBase.h:41
virtual IOFileType GetFileType()=0

◆ WriteVar() [5/5]

bool WriteVar ( std::string  name,
const Array< TinyVector< T, LEN >, RANK > &  val 
)

Definition at line 79 of file IO.h.

References neverDeleteData, and IOTreeClass::WriteVar().

80 {
82  for (int dim = 0; dim < RANK; dim++)
83  shape[dim] = val.extent(dim);
84  shape[RANK] = LEN;
85 
86  Array<T, RANK + 1> aval((T*)&(val(0)[0]), shape, neverDeleteData);
87  return WriteVar(name, aval);
88 }
bool WriteVar(std::string name, T val)
These create a new variable with the given name and value:
Definition: IO.h:37
std::ptrdiff_t extent(int d) const
Definition: Blitz.h:77
constexpr class neverDeleteData_t neverDeleteData
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25

Member Data Documentation

◆ CurrSecNum

int CurrSecNum

Definition at line 48 of file IOBase.h.

◆ FileName

std::string FileName

This is the empty std::string unless I'm the root node of some file.

Definition at line 55 of file IOBase.h.

Referenced by IOTreeClass::MarkModified().

◆ IsModified

bool IsModified
protected

Definition at line 37 of file IOBase.h.

Referenced by IOTreeASCIIClass::IOTreeASCIIClass(), and IOTreeClass::MarkModified().

◆ MyNumber

int MyNumber

This is used to ensure proper ordering of sections in the HDF version in which there is no guarantee that the sections will come out of the file in the same order you put them in.

Definition at line 48 of file IOBase.h.

Referenced by IOTreeClass::InsertSection().

◆ Name

std::string Name

Definition at line 56 of file IOBase.h.

Referenced by IOSectionClass::GetName().

◆ Parent

IOTreeClass* Parent

Definition at line 53 of file IOBase.h.

Referenced by IOTreeClass::MarkModified(), and IOTreeClass::ReadVar().

◆ SectionList

std::list<IOTreeClass*> SectionList

◆ UseUnderscores

bool UseUnderscores
protected

Definition at line 38 of file IOBase.h.

Referenced by IOTreeClass::SetUnderscores().

◆ VarList

std::list<IOVarBase*> VarList

The documentation for this class was generated from the following files: