QMCPACK
QMCAppBase.cpp
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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #include "Configuration.h"
16 #include "QMCAppBase.h"
17 
18 namespace qmcplusplus
19 {
20 QMCAppBase::QMCAppBase() = default;
21 
23 {
24  while (!xml_doc_stack_.empty())
25  {
26  popDocument();
27  }
28 }
29 
30 bool QMCAppBase::pushDocument(const std::string& infile)
31 {
32  Libxml2Document* adoc = new Libxml2Document();
33  bool success = adoc->parse(infile);
34  if (success)
35  {
36  xml_doc_stack_.push(adoc);
37  }
38  else
39  {
40  app_error() << "File " << infile << " is invalid" << std::endl;
41  delete adoc;
42  }
43  return success;
44 }
45 
47 {
48  if (!xml_doc_stack_.empty())
49  //Check if the stack is empty
50  {
51  Libxml2Document* adoc = xml_doc_stack_.top();
52  delete adoc;
53  xml_doc_stack_.pop();
54  }
55 }
56 
57 /** parse an input file
58  * @param infile name of an input file
59  * @return true, if the document is a valid xml file.
60  *
61  * The data members m_doc and m_root point to the "current" document and
62  * root element.
63  */
64 bool QMCAppBase::parse(const std::string& infile)
65 {
66  app_summary() << " Input XML = " << infile << std::endl;
67  return pushDocument(infile);
68 }
69 
71 {
72  if (!xml_doc_stack_.empty())
73  {
74  std::string newxml(my_project_.currentMainRoot());
75  newxml.append(".cont.xml");
76  app_log() << "\n========================================================="
77  << "\n A new xml input file : " << newxml << std::endl;
78  xml_doc_stack_.top()->dump(newxml);
79  }
80 }
81 
82 const std::string& QMCAppBase::getTitle() const { return my_project_.getTitle(); }
83 } // namespace qmcplusplus
const std::string & getTitle() const noexcept
returns the title of the project <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> tr...
class that handles xmlDoc
Definition: Libxml2Doc.h:76
bool parse(const std::string &infile)
parse an input file
Definition: QMCAppBase.cpp:64
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_summary()
Definition: OutputManager.h:63
std::ostream & app_error()
Definition: OutputManager.h:67
void saveXml()
save the xml document
Definition: QMCAppBase.cpp:70
ProjectData my_project_
project description
Definition: QMCAppBase.h:67
bool pushDocument(const std::string &infile)
open a new document
Definition: QMCAppBase.cpp:30
const std::string & currentMainRoot() const noexcept
returns the projectmain of the project, the series id is incremented at every QMC section <project id...
bool parse(const std::string &fname)
Definition: Libxml2Doc.cpp:180
const std::string & getTitle() const
Definition: QMCAppBase.cpp:82
QMCAppBase()
constructor
void popDocument()
close the current document
Definition: QMCAppBase.cpp:46
virtual ~QMCAppBase()
destructor
Definition: QMCAppBase.cpp:22
std::stack< Libxml2Document * > xml_doc_stack_
stack of xml document
Definition: QMCAppBase.h:64